Package cssutils :: Package css :: Module selector :: Class Selector
[hide private]
[frames] | no frames]

Class Selector

source code

object --+        
         |        
 util.Base --+    
             |    
    util.Base2 --+
                 |
                Selector

(cssutils) a single selector in a SelectorList of a CSSStyleRule

Properties

element
Effective element target of this selector
parentList: of type SelectorList, readonly
The SelectorList that contains this selector or None if this Selector is not attached to a SelectorList.
selectorText
textual representation of this Selector
seq
sequence of Selector parts including comments
specificity (READONLY)

tuple of (a, b, c, d) where:

a
presence of style in document, always 0 if not used on a document
b
number of ID selectors
c
number of .class selectors
d
number of Element (type) selectors
wellformed
if this selector is wellformed regarding the Selector spec

Format

# implemented in SelectorList
selectors_group
  : selector [ COMMA S* selector ]*
  ;

selector
  : simple_selector_sequence [ combinator simple_selector_sequence ]*
  ;

combinator
  /* combinators can be surrounded by white space */
  : PLUS S* | GREATER S* | TILDE S* | S+
  ;

simple_selector_sequence
  : [ type_selector | universal ]
    [ HASH | class | attrib | pseudo | negation ]*
  | [ HASH | class | attrib | pseudo | negation ]+
  ;

type_selector
  : [ namespace_prefix ]? element_name
  ;

namespace_prefix
  : [ IDENT | '*' ]? '|'
  ;

element_name
  : IDENT
  ;

universal
  : [ namespace_prefix ]? '*'
  ;

class
  : '.' IDENT
  ;

attrib
  : '[' S* [ namespace_prefix ]? IDENT S*
        [ [ PREFIXMATCH |
            SUFFIXMATCH |
            SUBSTRINGMATCH |
            '=' |
            INCLUDES |
            DASHMATCH ] S* [ IDENT | STRING ] S*
        ]? ']'
  ;

pseudo
  /* '::' starts a pseudo-element, ':' a pseudo-class */
  /* Exceptions: :first-line, :first-letter, :before and :after. */
  /* Note that pseudo-elements are restricted to one per selector and */
  /* occur only in the last simple_selector_sequence. */
  : ':' ':'? [ IDENT | functional_pseudo ]
  ;

functional_pseudo
  : FUNCTION S* expression ')'
  ;

expression
  /* In CSS3, the expressions are identifiers, strings, */
  /* or of the form "an+b" */
  : [ [ PLUS | '-' | DIMENSION | NUMBER | STRING | IDENT ] S* ]+
  ;

negation
  : NOT S* negation_arg S* ')'
  ;

negation_arg
  : type_selector | universal | HASH | class | attrib | pseudo
  ;
Nested Classes [hide private]

Inherited from util.Base (private): _prods

Instance Methods [hide private]
 
__init__(self, selectorText=None, parentList=None, readonly=False)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
source code
 
__getNamespaces(self)
uses own namespaces if not attached to a sheet, else the sheet's ones
source code
 
_getSelectorText(self)
returns serialized format
source code
 
_setSelectorText(self, selectorText) source code
 
__repr__(self)
repr(x)
source code
 
__str__(self)
str(x)
source code
 
_getUsedUris(self)
returns list of actually used URIs in this Selector
source code
 
_getUsedNamespaces(self)
returns actually used namespaces only
source code

Inherited from util.Base2 (private): _setSeq, _tempSeq

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]

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

Properties [hide private]
  _namespaces
if this Selector is attached to a CSSStyleSheet the namespaces of that sheet are mirrored here.
  element
Effective element target of this selector.
  parentList
(DOM) The SelectorList that contains this Selector or None if this Selector is not attached to a SelectorList.
  selectorText
(DOM) The parsable textual representation of the selector.
  specificity
Specificity of this selector (READONLY).

Inherited from util.Base2: seq

Inherited from object: __class__

Method Details [hide private]

__init__(self, selectorText=None, parentList=None, readonly=False)
(Constructor)

source code 

x.__init__(...) initializes x; see x.__class__.__doc__ for signature

Parameters:
  • selectorText - initial value of this selector
  • parentList - a SelectorList
  • readonly - default to False
Overrides: object.__init__

_setSelectorText(self, selectorText)

source code 
Parameters:
  • selectorText - parsable string or a tuple of (selectorText, dict-of-namespaces). Given namespaces are ignored if this object is attached to a CSSStyleSheet!
Raises:
  • NAMESPACE_ERR - (self) Raised if the specified selector uses an unknown namespace prefix.
  • SYNTAX_ERR - (self) Raised if the specified CSS string value has a syntax error and is unparsable.
  • NO_MODIFICATION_ALLOWED_ERR - (self) Raised if this rule is readonly.

__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]

_namespaces

if this Selector is attached to a CSSStyleSheet the namespaces of that sheet are mirrored here. While the Selector (or parent SelectorList or parentRule(s) of that are not attached a own dict of {prefix: namespaceURI} is used.
Get Method:
__getNamespaces(self) - uses own namespaces if not attached to a sheet, else the sheet's ones

element

Effective element target of this selector.
Get Method:
unreachable(self)

parentList

(DOM) The SelectorList that contains this Selector or None if this Selector is not attached to a SelectorList.
Get Method:
unreachable(self)

selectorText

(DOM) The parsable textual representation of the selector.
Get Method:
_getSelectorText(self) - returns serialized format
Set Method:
_setSelectorText(self, selectorText)

specificity

Specificity of this selector (READONLY).
Get Method:
unreachable(self)