gvsig-scripting / org.gvsig.scripting / trunk / org.gvsig.scripting / org.gvsig.scripting.app / org.gvsig.scripting.app.mainplugin / src / main / resources-plugin / scripting / lib / cssutils / css / cssrulelist.py @ 475
History | View | Annotate | Download (1.99 KB)
1 |
"""CSSRuleList implements DOM Level 2 CSS CSSRuleList.
|
---|---|
2 |
Partly also http://dev.w3.org/csswg/cssom/#the-cssrulelist."""
|
3 |
__all__ = ['CSSRuleList']
|
4 |
__docformat__ = 'restructuredtext'
|
5 |
__version__ = '$Id$'
|
6 |
|
7 |
class CSSRuleList(list): |
8 |
"""The CSSRuleList object represents an (ordered) list of statements.
|
9 |
|
10 |
The items in the CSSRuleList are accessible via an integral index,
|
11 |
starting from 0.
|
12 |
|
13 |
Subclasses a standard Python list so theoretically all standard list
|
14 |
methods are available. Setting methods like ``__init__``, ``append``,
|
15 |
``extend`` or ``__setslice__`` are added later on instances of this
|
16 |
class if so desired.
|
17 |
E.g. CSSStyleSheet adds ``append`` which is not available in a simple
|
18 |
instance of this class!
|
19 |
"""
|
20 |
def __init__(self, *ignored): |
21 |
"Nothing is set as this must also be defined later."
|
22 |
pass
|
23 |
|
24 |
def __notimplemented(self, *ignored): |
25 |
"Implemented in class using a CSSRuleList only."
|
26 |
raise NotImplementedError( |
27 |
'Must be implemented by class using an instance of this class.')
|
28 |
|
29 |
append = extend = __setitem__ = __setslice__ = __notimplemented |
30 |
|
31 |
def item(self, index): |
32 |
"""(DOM) Retrieve a CSS rule by ordinal `index`. The order in this
|
33 |
collection represents the order of the rules in the CSS style
|
34 |
sheet. If index is greater than or equal to the number of rules in
|
35 |
the list, this returns None.
|
36 |
|
37 |
Returns CSSRule, the style rule at the index position in the
|
38 |
CSSRuleList, or None if that is not a valid index.
|
39 |
"""
|
40 |
try:
|
41 |
return self[index] |
42 |
except IndexError: |
43 |
return None |
44 |
|
45 |
length = property(lambda self: len(self), |
46 |
doc=u"(DOM) The number of CSSRules in the list.")
|
47 |
|
48 |
def rulesOfType(self, type): |
49 |
"""Yield the rules which have the given `type` only, one of the
|
50 |
constants defined in :class:`cssutils.css.CSSRule`."""
|
51 |
for r in self: |
52 |
if r.type == type: |
53 |
yield r
|