@@ -41,7 +41,9 @@ class Stylesheet(object):
4141
4242 .. attribute:: rules
4343
44- A mixed list of :class:`RuleSet` and various at-rules, in source order.
44+ A mixed list, in source order, of :class:`RuleSet` and various
45+ at-rules such as :class:`ImportRule`, :class:`MediaRule`
46+ and :class:`PageRule`.
4547 Use their :obj:`at_keyword` attribute to distinguish them.
4648
4749 .. attribute:: errors
@@ -74,7 +76,7 @@ def pretty(self): # pragma: no cover
7476class ParseError (ValueError ):
7577"""Details about a CSS syntax error. Usually indicates that something
7678 (a rule or a declaration) was ignored and will not appear as a parsed
77- objects .
79+ object .
7880
7981 .. attribute:: line
8082
@@ -161,13 +163,12 @@ class RuleSet(object):
161163
162164 .. attribute:: selector
163165
164- A (possibly empty) :class:`ContainerToken` object.
166+ The selecor as a :class:`~tinycss.token_data. ContainerToken` object.
165167 In CSS 3 terminology, this is actually a selector group.
166168
167169 .. attribute:: declarations
168170
169- The list of :class:`Declaration` as returned by
170- :func:`parse_declaration_list`, in source order.
171+ The list of :class:`Declaration`, in source order.
171172
172173 """
173174def __init__ (self , selector , declarations , line , column ):
@@ -201,19 +202,33 @@ class Declaration(object):
201202
202203 .. attribute:: value
203204
204- The property value: a list of tokens as returned by
205- :func:`parse_value`.
205+ The property value as a :class:`~tinycss.token_data.ContainerToken`.
206+
207+ The value is not parsed. UAs using tinycss may only support
208+ some properties or some values and tinycss does not know which.
209+ They need to parse values themselves and ignore declarations with
210+ unknown or unsupported properties or values, and fall back
211+ on any previous declaration.
212+
213+ :mod:`tinycss.colors3` parses color values, but other values
214+ will need specific parsing/validation code.
215+
216+ .. attribute:: priority
217+
218+ Either the string ``'important'`` or ``None``.
206219
207220 """
208- def __init__ (self , name , value , line , column ):
221+ def __init__ (self , name , value , priority , line , column ):
209222self .name = name
210223self .value = value
224+ self .priority = priority
211225self .line = line
212226self .column = column
213227
214228def __repr__ (self ): # pragma: no cover
229+ priority = ' !' + self .priority if self .priority else ''
215230return ('<{0.__class__.__name__}{0.line}:{0.column}'
216- '{0.name}:{0.value.as_css}>' .format (self ))
231+ '{0.name}:{0.value.as_css}{1} >' .format (self , priority ))
217232
218233def pretty (self ): # pragma: no cover
219234"""Return an indented string representation for debugging"""
@@ -224,26 +239,6 @@ def pretty(self): # pragma: no cover
224239return '\n ' .join (lines )
225240
226241
227- class PropertyDeclaration (Declaration ):
228- """A CSS 2.1 property declaration.
229-
230- Same as :class:`Declaration` with an additional attribute:
231-
232- .. attribute:: priority
233-
234- Either the string ``'important'`` or ``None``.
235-
236- """
237- def __init__ (self , name , value , priority , line , column ):
238- super (PropertyDeclaration , self ).__init__ (name , value , line , column )
239- self .priority = priority
240-
241- def __repr__ (self ): # pragma: no cover
242- priority = ' !' + self .priority if self .priority else ''
243- return ('<{0.__class__.__name__}{0.line}:{0.column}'
244- '{0.name}:{0.value.as_css}{1}>' .format (self , priority ))
245-
246-
247242class PageRule (object ):
248243"""A parsed CSS 2.1 @page rule.
249244
@@ -265,11 +260,11 @@ class PageRule(object):
265260
266261 .. attribute:: declarations
267262
268- A list of :class:`PropertyDeclaration`
263+ A list of :class:`Declaration`, in source order.
269264
270265 .. attribute:: at_rules
271266
272- The list of parsed at-rules inside the @page block.
267+ The list of parsed at-rules inside the @page block, in source order .
273268 Always empty for CSS 2.1.
274269
275270 """
@@ -303,7 +298,8 @@ class MediaRule(object):
303298
304299 .. attribute:: rules
305300
306- The list rulesets and at-rules inside the @media block.
301+ The list :class:`RuleSet` and various at-rules inside the @media
302+ block, in source order.
307303
308304 """
309305at_keyword = '@media'
@@ -390,11 +386,11 @@ class CSS21Parser(object):
390386# User API:
391387
392388def parse_stylesheet_file (self , css_file , protocol_encoding = None ,
393- linking_encoding = None , document_encoding = None ):
389+ linking_encoding = None , document_encoding = None ):
394390"""Parse a stylesheet from a file or filename.
395391
396- The character encoding is determined as in
397- :meth:`parse_stylesheet_bytes`.
392+ Character encoding-related parameters and behavior are the same
393+ as in :meth:`parse_stylesheet_bytes`.
398394
399395 :param css_file:
400396 Either a file (any object with a :meth:`~file.read` method)
@@ -417,6 +413,8 @@ def parse_stylesheet_bytes(self, css_bytes, protocol_encoding=None,
417413
418414 The character encoding is determined from the passed metadata and the
419415 ``@charset`` rule in the stylesheet (if any).
416+ If no encoding information is available or decoding fails,
417+ decoding defaults to UTF-8 and then fall back on ISO-8859-1.
420418
421419 :param css_bytes:
422420 A CSS stylesheet as a byte string.
@@ -428,8 +426,6 @@ def parse_stylesheet_bytes(self, css_bytes, protocol_encoding=None,
428426 (if any)
429427 :param document_encoding:
430428 Encoding of the referring style sheet or document (if any)
431- :raises:
432- :class:`UnicodeDecodeError` if decoding failed
433429 :return:
434430 A :class:`Stylesheet`.
435431
@@ -467,8 +463,8 @@ def parse_style_attr(self, css_source):
467463 :param css_source:
468464 The attribute value, as an unicode string.
469465 :return:
470- A tuple of the list of valid :class:`Declaration` and a list
471- of :class:`ParseError`.
466+ A tuple of the list of valid :class:`Declaration` and
467+ a list of :class:`ParseError`.
472468 """
473469return self .parse_declaration_list (tokenize_grouped (css_source ))
474470
@@ -711,7 +707,7 @@ def parse_page_block(self, body, errors):
711707 :returns:
712708 A tuple of:
713709
714- * A list of :class:`PropertyDeclaration `
710+ * A list of :class:`Declaration `
715711 * A list of parsed at-rules (empty for CSS 2.1)
716712 * A list of :class:`ParseError`
717713
@@ -864,7 +860,7 @@ def parse_declaration(self, tokens):
864860value , priority = self .parse_value_priority (value )
865861value = ContainerToken (
866862'VALUES' , '' , '' , value , value [0 ].line , value [0 ].column )
867- return PropertyDeclaration (
863+ return Declaration (
868864property_name , value , priority , name_token .line , name_token .column )
869865
870866def parse_value_priority (self , original_value ):
0 commit comments