class RuleSet(object): """A ruleset. .. attribute:: at_keyword Always ``None``. Helps to tell rulesets apart from at-rules. .. attribute:: selector The selector as a :class:`~.token_data.TokenList`. In CSS 3, this is actually called a selector group. ``rule.selector.as_css()`` gives the selector as a string. This string can be used with *cssselect*, see :ref:`selectors3`. .. attribute:: declarations The list of :class:`Declaration`, in source order. """ at_keyword = None __slots__ = 'selector', 'declarations', 'line', 'column' def __init__(self, selector, declarations, line, column): self.selector = TokenList(selector) self.declarations = declarations self.line = line self.column = column def __repr__(self): return ('<{0.__class__.__name__} at {0.line}:{0.column} {1}>' .format(self, self.selector.as_css()))
class Declaration(object): """A property declaration. .. attribute:: name The property name as a normalized (lower-case) string. .. attribute:: value The property value as a :class:`~.token_data.TokenList`. The value is not parsed. UAs using tinycss may only support some properties or some values and tinycss does not know which. They need to parse values themselves and ignore declarations with unknown or unsupported properties or values, and fall back on any previous declaration. :mod:`tinycss.color3` parses color values, but other values will need specific parsing/validation code. .. attribute:: priority Either the string ``'important'`` or ``None``. """ __slots__ = 'name', 'value', 'priority', 'line', 'column' def __init__(self, name, value, priority, line, column): self.name = name self.value = TokenList(value) self.priority = priority self.line = line self.column = column def __repr__(self): priority = ' !' + self.priority if self.priority else '' return ('<{0.__class__.__name__} {0.line}:{0.column}' ' {0.name}: {1}{2}>'.format( self, self.value.as_css(), priority))
def __init__(self, name, value, priority, line, column): self.name = name self.value = TokenList(value) self.priority = priority self.line = line self.column = column
def __init__(self, selector, declarations, line, column): self.selector = TokenList(selector) self.declarations = declarations self.line = line self.column = column
def __init__(self, at_keyword, head, body, line, column): self.at_keyword = at_keyword self.head = TokenList(head) self.body = TokenList(body) if body is not None else body self.line = line self.column = column