Package cssutils :: Package css :: Module cssstylesheet :: Class CSSStyleSheet
[hide private]
[frames] | no frames]

Class CSSStyleSheet

source code

                   object --+        
                            |        
                    util.Base --+    
                                |    
stylesheets.stylesheet.StyleSheet --+
                                    |
                                   CSSStyleSheet

The CSSStyleSheet interface represents a CSS style sheet.

Properties

CSSOM

cssRules
of type CSSRuleList, (DOM readonly)
encoding
reflects the encoding of an @charset rule or 'utf-8' (default) if set to None
ownerRule
of type CSSRule, readonly (NOT IMPLEMENTED YET)

Inherits properties from stylesheet.StyleSheet

cssutils

cssText: string
a textual representation of the stylesheet
namespaces
reflects set @namespace rules of this rule. A dict of {prefix: namespaceURI} mapping.

Format

stylesheet
: [ CHARSET_SYM S* STRING S* ';' ]?
[S|CDO|CDC]* [ import [S|CDO|CDC]* ]* [ namespace [S|CDO|CDC]* ]* # according to @namespace WD [ [ ruleset | media | page ] [S|CDO|CDC]* ]*
Nested Classes [hide private]

Inherited from util.Base (private): _prods

Instance Methods [hide private]
 
__init__(self, href=None, media=None, title=u'', disabled=None, ownerNode=None, parentStyleSheet=None, readonly=False)
init parameters are the same as for stylesheets.StyleSheet
source code
 
__iter__(self)
generator which iterates over cssRules.
source code
 
_cleanNamespaces(self)
removes all namespace rules with same namespaceURI but last one set
source code
 
_getUsedURIs(self)
returns set of URIs used in the sheet
source code
 
_getCssText(self) source code
 
_setCssText(self, cssText)
(cssutils) Parses cssText and overwrites the whole stylesheet.
source code
 
_setEncoding(self, encoding)
sets encoding of charset rule if present or inserts new charsetrule with given encoding.
source code
 
_getEncoding(self)
return encoding if @charset rule if given or default of 'utf-8'
source code
 
add(self, rule)
Adds rule to stylesheet at appropriate position.
source code
 
deleteRule(self, index)
Used to delete a rule from the style sheet.
source code
 
insertRule(self, rule, index=None, inOrder=False, _clean=True)
Used to insert a new rule into the style sheet.
source code
 
_getsetOwnerRuleDummy(self)
NOT IMPLEMENTED YET
source code
 
replaceUrls(self, replacer)
EXPERIMENTAL
source code
 
setSerializer(self, cssserializer)
Sets the global Serializer used for output of all stylesheet output.
source code
 
setSerializerPref(self, pref, value)
Sets Preference of CSSSerializer used for output of this stylesheet.
source code
 
__repr__(self)
repr(x)
source code
 
__str__(self)
str(x)
source code

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__

Static Methods [hide private]

Inherited from util.Base (private): _normalize

Class Variables [hide private]
  type = 'text/css'

Inherited from util.Base (private): _SHORTHANDPROPERTIES, _log

Properties [hide private]
  cssText
  encoding
return encoding if @charset rule if given or default of 'utf-8'
  namespaces
Namespaces used in this CSSStyleSheet.
  ownerRule
(DOM attribute) NOT IMPLEMENTED YET

Inherited from stylesheets.stylesheet.StyleSheet: parentStyleSheet

Inherited from object: __class__

Method Details [hide private]

__init__(self, href=None, media=None, title=u'', disabled=None, ownerNode=None, parentStyleSheet=None, readonly=False)
(Constructor)

source code 
init parameters are the same as for stylesheets.StyleSheet
Overrides: object.__init__

_setCssText(self, cssText)

source code 
(cssutils) Parses cssText and overwrites the whole stylesheet.
Parameters:
  • cssText - a parseable string or a tuple of (cssText, dict-of-namespaces)
Raises:
  • NAMESPACE_ERR - If a namespace prefix is found which is not declared.
  • NO_MODIFICATION_ALLOWED_ERR - (self) Raised if the rule is readonly.
  • SYNTAX_ERR - Raised if the specified CSS string value has a syntax error and is unparsable.

_setEncoding(self, encoding)

source code 
sets encoding of charset rule if present or inserts new charsetrule with given encoding. If encoding if None removes charsetrule if present.

add(self, rule)

source code 
Adds rule to stylesheet at appropriate position. Same as sheet.insertRule(rule, inOrder=True).

deleteRule(self, index)

source code 
Used to delete a rule from the style sheet.
Parameters:
  • index - of the rule to remove in the StyleSheet's rule list. For an index < 0 no INDEX_SIZE_ERR is raised but rules for normal Python lists are used. E.g. deleteRule(-1) removes the last rule in cssRules.
Raises:
  • INDEX_SIZE_ERR - (self) Raised if the specified index does not correspond to a rule in the style sheet's rule list.
  • NAMESPACE_ERR - (self) Raised if removing this rule would result in an invalid StyleSheet
  • NO_MODIFICATION_ALLOWED_ERR - (self) Raised if this style sheet is readonly.

insertRule(self, rule, index=None, inOrder=False, _clean=True)

source code 
Used to insert a new rule into the style sheet. The new rule now becomes part of the cascade.
Parameters:
  • rule - a parsable DOMString, in cssutils also a CSSRule or a CSSRuleList
  • index - of the rule before the new rule will be inserted. If the specified index is equal to the length of the StyleSheet's rule collection, the rule will be added to the end of the style sheet. If index is not given or None rule will be appended to rule list.
  • inOrder - if True the rule will be put to a proper location while ignoring index but without raising HIERARCHY_REQUEST_ERR. The resulting index is returned nevertheless
Returns:
the index within the stylesheet's rule collection
Raises:
  • HIERARCHY_REQUEST_ERR - (self) Raised if the rule cannot be inserted at the specified index e.g. if an @import rule is inserted after a standard rule set or other at-rule.
  • INDEX_SIZE_ERR - (self) Raised if the specified index is not a valid insertion point.
  • NO_MODIFICATION_ALLOWED_ERR - (self) Raised if this style sheet is readonly.
  • SYNTAX_ERR - (rule) Raised if the specified rule has a syntax error and is unparsable.

_getsetOwnerRuleDummy(self)

source code 

NOT IMPLEMENTED YET

CSSOM

The ownerRule attribute, on getting, must return the CSSImportRule that caused this style sheet to be imported (if any). Otherwise, if no CSSImportRule caused it to be imported the attribute must return null.

replaceUrls(self, replacer)

source code 

EXPERIMENTAL

Utility method to replace all url(urlstring) values in CSSImportRules and CSSStyleDeclaration objects (properties).

replacer must be a function which is called with a single argument urlstring which is the current value of url() excluding url( and ). It still may have surrounding single or double quotes though.

setSerializerPref(self, pref, value)

source code 
Sets Preference of CSSSerializer used for output of this stylesheet. See cssutils.serialize.Preferences for possible preferences to be set.

__repr__(self)
(Representation operator)

source code 

repr(x)

Overrides: object.__repr__
(inherited documentation)

__str__(self)
(Informal representation operator)

source code 

str(x)

Overrides: object.__str__
(inherited documentation)

Property Details [hide private]

cssText

Get Method:
_getCssText(self)
Set Method:
_setCssText(self, cssText) - (cssutils) Parses cssText and overwrites the whole stylesheet.
Delete Method:
'(cssutils) a textual representation of the stylesheet'

encoding

return encoding if @charset rule if given or default of 'utf-8'
Get Method:
_getEncoding(self) - return encoding if @charset rule if given or default of 'utf-8'
Set Method:
_setEncoding(self, encoding) - sets encoding of charset rule if present or inserts new charsetrule with given encoding.
Delete Method:
'(cssutils) reflects the encoding of an @charset rule or \'UTF-8\' (de\
fault) if set to ``None``'

namespaces

Namespaces used in this CSSStyleSheet.
Get Method:
unreachable(self)

ownerRule

(DOM attribute) NOT IMPLEMENTED YET
Get Method:
_getsetOwnerRuleDummy(self) - NOT IMPLEMENTED YET
Set Method:
_getsetOwnerRuleDummy(self) - NOT IMPLEMENTED YET