Commits

Anonymous committed 487ae55

various changes due to changes in CSS2.1rev1

Comments (0)

Files changed (7)

 
     + **BUGFIX**: Fixed issue #22 parsing or indeed reserializing of values like ``content: "\\"``
 
+    - **FEATURE**: Updated some parts to http://www.w3.org/TR/2009/CR-CSS2-20090423/changes.html#new (most changes decribed here were already done in cssutils)
+        + updated tokenizer macro ``escape``
+        + replace ``aural`` media with ``speech``
+        + property ``content`` has allowed value ``none``
+        + property ``background-position`` allows mixed values like ``left 10%`` now
+
+
     - **IMPROVEMENT**: Fixed issue #23. The examples/style.py example renderer was reusing ``Property`` objects for each HTML element so they effectively overwrote each other.
 
     + DOCUMENTATION: Using Sphinx 0.6.1 does seem to mess up the start page of these docs a bit. Need to look into that...
 
 Based upon and partly implementing the following specifications :
 
-`CSS 2.1 <http://www.w3.org/TR/CSS21/>`__
+`CSS 2.1rev1 <http://www.w3.org/TR/2009/CR-CSS2-20090423/>`__
     General CSS rules and properties are defined here
-`CSS 2.1 Errata  <http://www.w3.org/Style/css2-updates/CR-CSS21-20070719-errata.html>`__
     A few errata, mainly the definition of CHARSET_SYM tokens
 `CSS3 Module: Syntax <http://www.w3.org/TR/css3-syntax/>`__
     Used in parts since cssutils 0.9.4. cssutils tries to use the features from CSS 2.1 and CSS 3 with preference to CSS3 but as this is not final yet some parts are from CSS 2.1

src/cssutils/cssproductions.py

 MACROS = {
     'nonascii': r'[^\0-\177]',
     'unicode': r'\\[0-9a-f]{1,6}(?:{nl}|{s})?',
-    # 'escape': r'{unicode}|\\[ -~\200-\4177777]',
-    'escape': r'{unicode}|\\[ -~\200-\777]',
+    #'escape': r'{unicode}|\\[ -~\200-\777]',
+    'escape': r'{unicode}|\\[^\n\r\f0-9a-f]',
     'nmstart': r'[_a-zA-Z]|{nonascii}|{escape}',
     'nmchar': r'[-_a-zA-Z0-9]|{nonascii}|{escape}',
     'string1': r'"([^\n\r\f\\"]|\\{nl}|{escape})*"',

src/cssutils/profiles.py

 
     'background-color': r'{color}|transparent|inherit',
     'background-image': r'{uri}|none|inherit',
-    #'background-position': r'({percentage}|{length})(\s*({percentage}|{length}))?|((top|center|bottom)\s*(left|center|right))|((left|center|right)\s*(top|center|bottom))|inherit',
-    'background-position': r'({percentage}|{length})(\s*({percentage}|{length}))?|((top|center|bottom)\s*(left|center|right)?)|((left|center|right)\s*(top|center|bottom)?)|inherit',
+    #'background-position': r'({percentage}|{length})(\s*({percentage}|{length}))?|((top|center|bottom)\s*(left|center|right)?)|((left|center|right)\s*(top|center|bottom)?)|inherit',
+    'background-position': r'({percentage}|{length}|left|center|right)(\s*({percentage}|{length}|top|center|bottom))?|((top|center|bottom)\s*(left|center|right)?)|((left|center|right)\s*(top|center|bottom)?)|inherit',
     'background-repeat': r'repeat|repeat-x|repeat-y|no-repeat|inherit',
     'background-attachment': r'scroll|fixed|inherit',
 
     'clear': r'none|left|right|both|inherit',
     'clip': r'{shape}|auto|inherit',
     'color': r'{color}|inherit',
-    'content': r'normal|{content}(\s+{content})*|inherit',
+    'content': r'none|normal|{content}(\s+{content})*|inherit',
     'counter-increment': r'({identifier}(\s+{integer})?)(\s+({identifier}(\s+{integer})))*|none|inherit',
     'counter-reset': r'({identifier}(\s+{integer})?)(\s+({identifier}(\s+{integer})))*|none|inherit',
     'cue-after': r'{uri}|none|inherit',
 # CSS Color Module Level 3
 macros[Profiles.CSS3_COLOR] = {
     # orange and transparent in CSS 2.1
-    'namedcolor': r'(currentcolor|transparent|orange|black|green|silver|lime|gray|olive|white|yellow|maroon|navy|red|blue|purple|teal|fuchsia|aqua)',
+    'namedcolor': r'(currentcolor|transparent|aqua|black|blue|fuchsia|gray|green|lime|maroon|navy|olive|orange|purple|red|silver|teal|white|yellow)',
                     # orange?
     'rgbacolor': r'rgba\({w}{int}{w},{w}{int}{w},{w}{int}{w},{w}{int}{w}\)|rgba\({w}{num}%{w},{w}{num}%{w},{w}{num}%{w},{w}{num}{w}\)',
     'hslcolor': r'hsl\({w}{int}{w},{w}{num}%{w},{w}{num}%{w}\)|hsla\({w}{int}{w},{w}{num}%{w},{w}{num}%{w},{w}{num}{w}\)',

src/cssutils/stylesheets/mediaquery.py

         media_query: [[only | not]? <media_type> [ and <expression> ]*]
           | <expression> [ and <expression> ]*
         expression: ( <media_feature> [: <value>]? )
-        media_type: all | aural | braille | handheld | print |
-          projection | screen | tty | tv | embossed
+        media_type: all | braille | handheld | print |
+          projection | speech | screen | tty | tv | embossed
         media_feature: width | min-width | max-width
           | height | min-height | max-height
           | device-width | min-device-width | max-device-width
           | scan | grid
           
     """
-    MEDIA_TYPES = [u'all', u'aural', u'braille', u'embossed', u'handheld',
-        u'print', u'projection', u'screen', u'tty', u'tv']
+    MEDIA_TYPES = [u'all', u'braille', u'embossed', u'handheld',
+        u'print', u'projection', u'screen', u'speech', u'tty', u'tv']
 
     # From the HTML spec (see MediaQuery):
     # "[...] character that isn't a US ASCII letter [a-zA-Z] (Unicode

src/tests/test_mediaquery.py

         "MediaQuery.mediaText"
         tests = {
             u'all': None,
+            u'braille': None,
+            u'embossed': None,
+            u'handheld': None,
+            u'print': None,
+            u'projection': None,
+            u'screen': None,
+            u'speech': None,
+            u'tty': None,
+            u'tv': None,
+            u'ALL': None,
             u'a\\ll': None,
             u'not tv': None,
             u'n\\ot t\\v': None,
             u'two values': xml.dom.SyntaxErr,
             u'or even three': xml.dom.SyntaxErr,
             u'print and(color)': xml.dom.SyntaxErr, # a function
+            u'aural': xml.dom.InvalidCharacterErr, # a dimension
             u'3d': xml.dom.InvalidCharacterErr, # a dimension
             }
         self.do_raise_r(tests, att='_setMediaText')        

src/tests/test_profiles.py

                              cssutils.profile.validateWithProfile('color', color))
         
         tests = {
-            # name, value: valid, matching, profile
+            # name, values: valid, matching, profile
             
             # PROPERTY background-position
-            ('background-position', 'inherit'): (True, True, CSS2),
-            ('background-position', '0'): (True, True, CSS2),
-            ('background-position', '1%'): (True, True, CSS2),
-            ('background-position', '1px'): (True, True, CSS2),
-            ('background-position', '0 0'): (True, True, CSS2),
-            ('background-position', '1% 1%'): (True, True, CSS2),
-            ('background-position', '1px 1px'): (True, True, CSS2),
-            ('background-position', '1px 1%'): (True, True, CSS2),
-            ('background-position', 'top'): (True, True, CSS2),
-            ('background-position', 'bottom'): (True, True, CSS2),
-            ('background-position', 'left'): (True, True, CSS2),
-            ('background-position', 'right'): (True, True, CSS2),
-            ('background-position', 'center'): (True, True, CSS2),
-            ('background-position', 'top left'): (True, True, CSS2),
-            ('background-position', 'top center'): (True, True, CSS2),
-            ('background-position', 'top right'): (True, True, CSS2),
-            ('background-position', 'bottom left'): (True, True, CSS2),
-            ('background-position', 'bottom center'): (True, True, CSS2),
-            ('background-position', 'bottom right'): (True, True, CSS2),
-            ('background-position', 'center left'): (True, True, CSS2),
-            ('background-position', 'center center'): (True, True, CSS2),
-            ('background-position', 'center right'): (True, True, CSS2),
-            ('background-position', '0 center'): (False, False, CSS2),
-            ('background-position', 'center 0'): (False, False, CSS2),
+            ('background-position', ('inherit',
+                                     '0',
+                                     '1%',
+                                     '1px',
+                                     '0 0',
+                                     '1% 1%',
+                                     '1px 1px',
+                                     '1px 1%',
+                                     'top', 'bottom',
+                                     'left', 'right',
+                                     'center center',
+                                     'center',
+                                     'top left', 'top center', 'top right',
+                                     'bottom left', 'bottom center', 'bottom right',
+                                     'center left', 'center center', 'center right',
+                                     '0 center', 'center 0',
+                                     '0 top', '10% bottom',
+                                     'left 0', 'right 10%',
+                                     '1% center', 'center 1%'
+                                     )): (True, True, CSS2),
+            ('background-position', ('0 left',
+                                     'top 0'
+                                     )): (False, False, CSS2),
+             
 
             # PROPERTY color
             ('color', 'inherit'): (True, True, CSS2),
             ('color', 'hsla(1,1,1%, 1)'): (False, False, CSS2_CM3), # %
             ('color', 'hsla(1,1%,1, 1)'): (False, False, CSS2_CM3), # %
             ('color', 'hsla(1,1%,1%, 1%)'): (False, False, CSS2_CM3), # %
+
+            # PROPERTY content
+            ('content', ('none', 
+                         'normal')): (True, True, CSS2),
             
             # PROPERTY opacity
-            ('opacity', 'inherit'): (True, True, CM3),
-            ('opacity', '0'): (True, True, CM3),
-            ('opacity', '0.0'): (True, True, CM3),
-            ('opacity', '0.42342'): (True, True, CM3),
-            ('opacity', '1'): (True, True, CM3),
-            ('opacity', '1.0'): (True, True, CM3),
-            # should be clipped but valid
-            ('opacity', '-0'): (True, True, CM3),
-            ('opacity', '-0.1'): (True, True, CM3),
-            ('opacity', '-10'): (True, True, CM3),
-            ('opacity', '2'): (True, True, CM3),
+            ('opacity', ('inherit',
+                         '0', '0.0', '0.42342', '1', '1.0',
+                         # should be clipped but valid
+                         '-0', '-0.1', '-10', '2'
+                         )): (True, True, CM3),
             # invalid
-            ('opacity', 'a'): (False, False, CM3),
-            ('opacity', '#000'): (False, False, CM3),
-            ('opacity', '+1'): (False, False, CM3),
+            ('opacity', ('a', '#000', '+1')): (False, False, CM3),
+
+        
         }
-        for test, (v, m, p) in tests.items():            
-            self.assertEqual(v, cssutils.profile.validate(*test))
-            self.assertEqual((v, m, p), 
-                             cssutils.profile.validateWithProfile(*test))
+        for (name, values), (v, m, p) in tests.items():            
+            if issubclass(type(values), basestring):
+                values = [values]
+            for value in values:
+                self.assertEqual(v, cssutils.profile.validate(name, value))
+                self.assertEqual((v, m, p), 
+                                 cssutils.profile.validateWithProfile(name, value))
 
         # not css2 but 3
         self.assertEqual((True, True, CM3),