[Lxml-checkins] r51601 - lxml/trunk/src/lxml/html
ianb at codespeak.net
ianb at codespeak.net
Mon Feb 18 18:44:12 CET 2008
Author: ianb
Date: Mon Feb 18 18:44:09 2008
New Revision: 51601
Modified:
lxml/trunk/src/lxml/html/__init__.py
Log:
Make getter/setter methods private
Modified: lxml/trunk/src/lxml/html/__init__.py
==============================================================================
--- lxml/trunk/src/lxml/html/__init__.py (original)
+++ lxml/trunk/src/lxml/html/__init__.py Mon Feb 18 18:44:09 2008
@@ -67,7 +67,7 @@
return self.xpath('//head')[0]
head = property(head, doc=head.__doc__)
- def label__get(self):
+ def _label__get(self):
"""
Get or set any <label> element associated with this element.
"""
@@ -79,7 +79,7 @@
return None
else:
return result[0]
- def label__set(self, label):
+ def _label__set(self, label):
id = self.get('id')
if not id:
raise TypeError(
@@ -90,11 +90,11 @@
"You can only assign label to a label element (not %r)"
% label)
label.set('for', id)
- def label__del(self):
+ def _label__del(self):
label = self.label
if label is not None:
del label.attrib['for']
- label = property(label__get, label__set, label__del, doc=label__get.__doc__)
+ label = property(_label__get, _label__set, _label__del, doc=_label__get.__doc__)
def drop_tree(self):
"""
@@ -608,14 +608,14 @@
return InputGetter(self)
inputs = property(inputs, doc=inputs.__doc__)
- def fields__get(self):
+ def _fields__get(self):
"""
Dictionary-like object that represents all the fields in this
form. You can set values in this dictionary to effect the
form.
"""
return FieldsDict(self.inputs)
- def fields__set(self, value):
+ def _fields__set(self, value):
prev_keys = self.fields.keys()
for key, value in value.iteritems():
if key in prev_keys:
@@ -628,7 +628,7 @@
continue
self.fields[key] = None
- fields = property(fields__get, fields__set, doc=fields__get.__doc__)
+ fields = property(_fields__get, _fields__set, doc=_fields__get.__doc__)
def _name(self):
if self.get('name'):
@@ -668,7 +668,7 @@
results.append((name, el.value))
return results
- def action__get(self):
+ def _action__get(self):
"""
Get/set the form's ``action`` attribute.
"""
@@ -678,22 +678,22 @@
return urlparse.urljoin(base_url, action)
else:
return action
- def action__set(self, value):
+ def _action__set(self, value):
self.set('action', value)
- def action__del(self):
+ def _action__del(self):
if 'action' in self.attrib:
del self.attrib['action']
- action = property(action__get, action__set, action__del, doc=action__get.__doc__)
+ action = property(_action__get, _action__set, _action__del, doc=_action__get.__doc__)
- def method__get(self):
+ def _method__get(self):
"""
Get/set the form's method. Always returns a capitalized
string, and defaults to ``'GET'``
"""
return self.get('method', 'GET').upper()
- def method__set(self, value):
+ def _method__set(self, value):
self.set('method', value.upper())
- method = property(method__get, method__set, doc=method__get.__doc__)
+ method = property(_method__get, _method__set, doc=_method__get.__doc__)
HtmlElementClassLookup._default_element_classes['form'] = FormElement
@@ -837,17 +837,17 @@
"""
- def name__get(self):
+ def _name__get(self):
"""
Get/set the name of the element
"""
return self.get('name')
- def name__set(self, value):
+ def _name__set(self, value):
self.set('name', value)
- def name__del(self):
+ def _name__del(self):
if 'name' in self.attrib:
del self.attrib['name']
- name = property(name__get, name__set, name__del, doc=name__get.__doc__)
+ name = property(_name__get, _name__set, _name__del, doc=_name__get.__doc__)
def __repr__(self):
type = getattr(self, 'type', None)
@@ -864,16 +864,16 @@
get/set the value with ``.value``
"""
- def value__get(self):
+ def _value__get(self):
"""
Get/set the value (which is the contents of this element)
"""
return self.text or ''
- def value__set(self, value):
+ def _value__set(self, value):
self.text = value
- def value__del(self):
+ def _value__del(self):
self.text = ''
- value = property(value__get, value__set, value__del, doc=value__get.__doc__)
+ value = property(_value__get, _value__set, _value__del, doc=_value__get.__doc__)
HtmlElementClassLookup._default_element_classes['textarea'] = TextareaElement
@@ -890,7 +890,7 @@
multi-select.
"""
- def value__get(self):
+ def _value__get(self):
"""
Get/set the value of this select (the selected option).
@@ -906,7 +906,7 @@
return value
return None
- def value__set(self, value):
+ def _value__set(self, value):
if self.multiple:
if isinstance(value, basestring):
raise TypeError(
@@ -929,14 +929,14 @@
if value is not None:
checked_option.set('selected', '')
- def value__del(self):
+ def _value__del(self):
# FIXME: should del be allowed at all?
if self.multiple:
self.value.clear()
else:
self.value = None
- value = property(value__get, value__set, value__del, doc=value__get.__doc__)
+ value = property(_value__get, _value__set, _value__del, doc=_value__get.__doc__)
def value_options(self):
"""
@@ -946,17 +946,17 @@
return [el.get('value') for el in self.getiterator('option')]
value_options = property(value_options, doc=value_options.__doc__)
- def multiple__get(self):
+ def _multiple__get(self):
"""
Boolean attribute: is there a ``multiple`` attribute on this element.
"""
return 'multiple' in self.attrib
- def multiple__set(self, value):
+ def _multiple__set(self, value):
if value:
self.set('multiple', '')
elif 'multiple' in self.attrib:
del self.attrib['multiple']
- multiple = property(multiple__get, multiple__set, doc=multiple__get.__doc__)
+ multiple = property(_multiple__get, _multiple__set, doc=_multiple__get.__doc__)
HtmlElementClassLookup._default_element_classes['select'] = SelectElement
@@ -1020,7 +1020,7 @@
``.value_options`` to get the possible values.
"""
- def value__get(self):
+ def _value__get(self):
"""
Get/set the value, which checks the radio with that value (and
unchecks any other value).
@@ -1030,7 +1030,7 @@
return el.get('value')
return None
- def value__set(self, value):
+ def _value__set(self, value):
if value is not None:
for el in self:
if el.get('value') == value:
@@ -1045,10 +1045,10 @@
if value is not None:
checked_option.set('checked', '')
- def value__del(self):
+ def _value__del(self):
self.value = None
- value = property(value__get, value__set, value__del, doc=value__get.__doc__)
+ value = property(_value__get, _value__set, _value__del, doc=_value__get.__doc__)
def value_options(self):
"""
@@ -1073,22 +1073,22 @@
to get the possible values.
"""
- def value__get(self):
+ def _value__get(self):
"""
Return a set-like object that can be modified to check or
uncheck individual checkboxes according to their value.
"""
return CheckboxValues(self)
- def value__set(self, value):
+ def _value__set(self, value):
self.value.clear()
if not hasattr(value, '__iter__'):
raise ValueError(
"A CheckboxGroup (name=%r) must be set to a sequence (not %r)"
% (self[0].name, value))
self.value.update(value)
- def value__del(self):
+ def _value__del(self):
self.value.clear()
- value = property(value__get, value__set, value__del, doc=value__get.__doc__)
+ value = property(_value__get, _value__set, _value__del, doc=_value__get.__doc__)
def __repr__(self):
return '%s(%s)' % (
@@ -1153,7 +1153,7 @@
"""
## FIXME: I'm a little uncomfortable with the use of .checked
- def value__get(self):
+ def _value__get(self):
"""
Get/set the value of this element, using the ``value`` attribute.
@@ -1167,7 +1167,7 @@
else:
return None
return self.get('value')
- def value__set(self, value):
+ def _value__set(self, value):
if self.checkable:
if not value:
self.checked = False
@@ -1177,31 +1177,31 @@
self.set('value', value)
else:
self.set('value', value)
- def value__del(self):
+ def _value__del(self):
if self.checkable:
self.checked = False
else:
if 'value' in self.attrib:
del self.attrib['value']
- value = property(value__get, value__set, value__del, doc=value__get.__doc__)
+ value = property(_value__get, _value__set, _value__del, doc=_value__get.__doc__)
- def type__get(self):
+ def _type__get(self):
"""
Return the type of this element (using the type attribute).
"""
return self.get('type', 'text').lower()
- def type__set(self, value):
+ def _type__set(self, value):
self.set('type', value)
- type = property(type__get, type__set, doc=type__get.__doc__)
+ type = property(_type__get, _type__set, doc=_type__get.__doc__)
- def checkable__get(self):
+ def checkable(self):
"""
Boolean: can this element be checked?
"""
return self.type in ['checkbox', 'radio']
- checkable = property(checkable__get, doc=checkable__get.__doc__)
+ checkable = property(checkable, doc=checkable.__doc__)
- def checked__get(self):
+ def _checked__get(self):
"""
Boolean attribute to get/set the presence of the ``checked``
attribute.
@@ -1211,7 +1211,7 @@
if not self.checkable:
raise AttributeError('Not a checkable input type')
return 'checked' in self.attrib
- def checked__set(self, value):
+ def _checked__set(self, value):
if not self.checkable:
raise AttributeError('Not a checkable input type')
if value:
@@ -1219,7 +1219,7 @@
else:
if 'checked' in self.attrib:
del self.attrib['checked']
- checked = property(checked__get, checked__set, doc=checked__get.__doc__)
+ checked = property(_checked__get, _checked__set, doc=_checked__get.__doc__)
HtmlElementClassLookup._default_element_classes['input'] = InputElement
@@ -1231,7 +1231,7 @@
attribute. You can access this element with ``label.for_element``.
"""
- def for_element__get(self):
+ def _for_element__get(self):
"""
Get/set the element this label points to. Return None if it
can't be found.
@@ -1240,17 +1240,17 @@
if not id:
return None
return self.body.get_element_by_id(id)
- def for_element__set(self, other):
+ def _for_element__set(self, other):
id = other.get('id')
if not id:
raise TypeError(
"Element %r has no id attribute" % other)
self.set('for', id)
- def for_element__del(self):
+ def _for_element__del(self):
if 'id' in self.attrib:
del self.attrib['id']
- for_element = property(for_element__get, for_element__set, for_element__del,
- doc=for_element__get.__doc__)
+ for_element = property(_for_element__get, _for_element__set, _for_element__del,
+ doc=_for_element__get.__doc__)
HtmlElementClassLookup._default_element_classes['label'] = LabelElement
More information about the lxml-checkins
mailing list