lxml :: html :: Classes :: Class Classes |
[hide private]
[frames] | no frames]

# Class Classes

source code

           object --+
                    |
        _abcoll.Sized --+
                        |
           object --+   |
                    |   |
     _abcoll.Iterable --+
                        |
           object --+   |
                    |   |
    _abcoll.Container --+
                        |
              _abcoll.Set --+
                            |
           _abcoll.MutableSet --+
                                |
                               Classes

Provides access to an element's class attribute as a set-like collection. Usage:

    >>> el = fromstring('<p class="hidden large">Text</p>')
    >>> classes = el.classes  # or: classes = Classes(el.attrib)
    >>> classes |= ['block', 'paragraph']
    >>> el.get('class')
    'hidden large block paragraph'
    >>> classes.toggle('hidden')
    False
    >>> el.get('class')
    'large block paragraph'
    >>> classes -= ('some', 'classes', 'block')
    >>> el.get('class')
    'large paragraph'

Nested Classes | [hide private]
Inherited from `_abcoll.Sized`: `__metaclass__`

Instance Methods | [hide private]
__contains__(self, name) | source code
__init__(self, attributes) x.__init__(...) initializes x; see help(type(x)) for signature | source code
__iter__(self) | source code
__len__(self) | source code
add(self, value) Add a class. | source code
discard(self, value) Remove a class if it is currently present. | source code
remove(self, value) Remove a class; it must currently be present. | source code
toggle(self, value) Add a class name if it isn't there yet, or remove it if it exists. | source code
update(self, values) Add all names from 'values'. | source code
Inherited from `_abcoll.MutableSet`: `__iand__`, `__ior__`, `__isub__`, `__ixor__`, `clear`, `pop` Inherited from `_abcoll.Set`: `__and__`, `__eq__`, `__ge__`, `__gt__`, `__le__`, `__lt__`, `__ne__`, `__or__`, `__rand__`, `__ror__`, `__rsub__`, `__rxor__`, `__sub__`, `__xor__`, `isdisjoint` Inherited from `_abcoll.Set` (private): `_hash` Inherited from `object`: `__delattr__`, `__format__`, `__getattribute__`, `__new__`, `__reduce__`, `__reduce_ex__`, `__repr__`, `__setattr__`, `__sizeof__`, `__str__`

Class Methods | [hide private]
Inherited from `_abcoll.Set` (private): `_from_iterable` Inherited from `_abcoll.Sized`: `__subclasshook__`

Class Variables | [hide private]
| __abstractmethods__ = ``frozenset([``])``
| _abc_negative_cache = `<_weakrefset.WeakSet object>`
| _abc_negative_cache_version = `22`
| _abc_registry = `<_weakrefset.WeakSet object>`
Inherited from `_abcoll.Set`: `__hash__` Inherited from `_abcoll.Sized` (private): `_abc_cache`

Properties | [hide private]
Inherited from `object`: `__class__`

Method Details | [hide private]

### __contains__(self, name) (In operator) | source code
Overrides: _abcoll.Container.__contains__

### __init__(self, attributes) (Constructor) | source code
x.__init__(...) initializes x; see help(type(x)) for signature Overrides: object.__init__ (inherited documentation)

### __iter__(self) | source code
Overrides: _abcoll.Iterable.__iter__

### __len__(self) (Length operator) | source code
Overrides: _abcoll.Sized.__len__

### add(self, value) | source code
Add a class. This has no effect if the class is already present. Overrides: _abcoll.MutableSet.add

### discard(self, value) | source code
Remove a class if it is currently present. If the class is not present, do nothing. Overrides: _abcoll.MutableSet.discard

### remove(self, value) | source code
Remove a class; it must currently be present. If the class is not present, raise a KeyError. Overrides: _abcoll.MutableSet.remove

### toggle(self, value) | source code
Add a class name if it isn't there yet, or remove it if it exists. Returns true if the class was added (and is now enabled) and false if it was removed (and is now disabled).