File python-clevercss-tymofij.patch of Package python-clevercss

diff -uNr -x .git dziegler-clevercss-2272da5785fd9a5a723ea12a5d7081bec20b7c9b/BUGFIXES t/clevercss/BUGFIXES
--- dziegler-clevercss-2272da5785fd9a5a723ea12a5d7081bec20b7c9b/BUGFIXES	2009-09-01 15:44:49.000000000 +0200
+++ t/clevercss/BUGFIXES	2010-03-24 11:19:50.002353188 +0100
@@ -1,6 +1,10 @@
 List of bug fixes since CleverCSS-0.1
 ===================================
 
+9/18/09 - v.0.1.5 - submitted by Tim Babych - The Parser was not aware of negative numbers. Thus any minus sign was an operator, leading to unneeded calculations. Say, "margin: -2px -2px" was converted into "margin: -4px"
+ 
+9/18/09 - v.0.1.5 - submitted by Tim Babych - LineIterator was not filtering out "\n"s that were left after trimming /* comments */, causing an exception in Parser
+
 9/01/09 - v.0.1.4 - submitted by David Niergarth and 'Lasse' - Missing None check in Engine.evaluate which causes context to always be reset to {}.
 
 4/20/09 - v.0.1.3 - submitted by Antti Kaihola - Using the rgb_to_hls() and hls_to_rgb() functions in CleverCSS to convert colors back and forth reveals a mistake in the HLS to RGB algorithm. Fractional parts are stripped when rounding should be done instead.
diff -uNr -x .git dziegler-clevercss-2272da5785fd9a5a723ea12a5d7081bec20b7c9b/clevercss.py t/clevercss/clevercss.py
--- dziegler-clevercss-2272da5785fd9a5a723ea12a5d7081bec20b7c9b/clevercss.py	2009-09-01 15:44:49.000000000 +0200
+++ t/clevercss/clevercss.py	2010-03-24 11:19:50.022348959 +0100
@@ -225,7 +225,7 @@
 import operator
 
 
-VERSION = '0.1'
+VERSION = '0.1.5'
 
 __all__ = ['convert']
 
@@ -410,7 +410,7 @@
 _reverse_colors = dict((v, k) for k, v in _colors.iteritems())
 
 # partial regular expressions for the expr parser
-_r_number = '\d+(?:\.\d+)?'
+_r_number = '(?:\s\-)?\d+(?:\.\d+)?'
 _r_string = r"(?:'(?:[^'\\]*(?:\\.[^'\\]*)*)'|" \
             r'\"(?:[^"\\]*(?:\\.[^"\\]*)*)")'
 _r_call = r'([a-zA-Z_][a-zA-Z0-9_]*)\('
@@ -559,12 +559,15 @@
 
     def next(self):
         """
-        Get the next line without multiline comments and emit the
-        endmarker if we reached the end of the sourcecode and endmarkers
+        Get the next non-whitespace line without multiline comments and emit
+        the endmarker if we reached the end of the sourcecode and endmarkers
         were requested.
         """
         try:
-            return self._next()
+            while True:
+                lineno, stripped_line = self._next()
+                if stripped_line:
+                    return lineno, stripped_line
         except StopIteration:
             if self.emit_endmarker:
                 self.emit_endmarker = False
@@ -585,7 +588,7 @@
     def evaluate(self, context=None):
         """Evaluate code."""
         expr = None
-        if not isinstance(context, dict): 
+        if not isinstance(context, dict):
             context = {}
         for key, value in context.iteritems():
             expr = self._parser.parse_expr(1, value)
@@ -1372,9 +1375,10 @@
                     raise ParserError(lineno, 'invalid string escape')
                 return value, 'string'
 
-            rules = ((_operator_re, process('op')),
-                     (_call_re, process('call', 1)),
+            rules = (
                      (_value_re, lambda m: (m.groups(), 'value')),
+                     (_operator_re, process('op')),
+                     (_call_re, process('call', 1)),
                      (_color_re, process('color')),
                      (_number_re, process('number')),
                      (_url_re, process('url', 1)),
@@ -1525,6 +1529,10 @@
         stream.expect(')', 'op')
         return Call(node, method, args, lineno=stream.lineno)
 
+def eigen_test():
+    return convert('\n'.join(l[8:].rstrip() for l in
+                      re.compile(r'Example::\n(.*?)__END__(?ms)')
+                        .search(__doc__).group(1).splitlines()))
 
 def convert(source, context=None):
     """Convert a CleverCSS file into a normal stylesheet."""
@@ -1561,9 +1569,7 @@
 
     # evaluate the example from the docstring.
     elif '--eigen-test' in sys.argv:
-        print convert('\n'.join(l[8:].rstrip() for l in
-                      re.compile(r'Example::\n(.*?)__END__(?ms)')
-                        .search(__doc__).group(1).splitlines()))
+        print eigen_test()
 
     # color list
     elif '--list-colors' in sys.argv:
diff -uNr -x .git dziegler-clevercss-2272da5785fd9a5a723ea12a5d7081bec20b7c9b/.gitignore t/clevercss/.gitignore
--- dziegler-clevercss-2272da5785fd9a5a723ea12a5d7081bec20b7c9b/.gitignore	1970-01-01 01:00:00.000000000 +0100
+++ t/clevercss/.gitignore	2010-03-24 11:19:50.002353188 +0100
@@ -0,0 +1,5 @@
+*.pyc
+*.swp
+CleverCSS.egg-info
+build
+dist
diff -uNr -x .git dziegler-clevercss-2272da5785fd9a5a723ea12a5d7081bec20b7c9b/tests/__init__.py t/clevercss/tests/__init__.py
--- dziegler-clevercss-2272da5785fd9a5a723ea12a5d7081bec20b7c9b/tests/__init__.py	2009-09-01 15:44:49.000000000 +0200
+++ t/clevercss/tests/__init__.py	2010-03-24 11:19:50.022348959 +0100
@@ -1,4 +1,5 @@
 from unittest import TestCase, main
+from textwrap import dedent
 
 from clevercss import rgb_to_hls
 
@@ -54,7 +55,7 @@
         rgb2hls = rgb_to_hls(*hls2rgb)
         self.assertEqual(rgb2hls, hls)
 
-from clevercss import convert
+from clevercss import convert, eigen_test
 
 class ConvertTestCase(TestCase):
     def test_01_convert(self):
@@ -68,6 +69,97 @@
             background-color: $background_color
         ''', {'background_color': 'red.darken(10)'}),
         u'body {\n  background-color: #cc0000;\n}')
+        
+    def test_math(self):
+        self.assertEqual(convert(dedent("""
+        div:
+            margin: -2px -2px
+            padding: 2px + 2px
+            top: 1px+1
+            left: 5+5px
+            right: 4px-5px
+            bottom: 0 - 5px
+        """)), dedent("""
+        div {
+          margin: -2px -2px;
+          padding: 4px;
+          top: 2px;
+          left: 10px;
+          right: -1px;
+          bottom: -5px;
+        }""").strip())
+
+    def test_eigen(self):
+        self.assertEqual(eigen_test(),dedent("""
+        body {
+          font-family: serif, sans-serif, Verdana, 'Times New Roman';
+          color: #111111;
+          padding-top: 4px;
+          padding-right: 5px;
+          padding-left: 5px;
+          padding-bottom: 4px;
+          background-color: #eeeeee;
+        }
+
+        div.foo {
+          width: 220px;
+          foo: foo/bar/baz/42;
+        }
+
+        a {
+          color: #ff0000;
+        }
+
+        a:hover {
+          color: #4d0000;
+        }
+
+        a:active {
+          color: #ff1a1a;
+        }
+
+        div.navigation {
+          height: 1.2em;
+          padding: 0.2em;
+          foo: '1 2 3';
+        }
+
+        div.navigation ul {
+          margin: 0;
+          padding: 0;
+          list-style: none;
+        }
+
+        div.navigation ul li {
+          float: left;
+          height: 1.2em;
+        }
+
+        div.navigation ul li a {
+          display: block;
+          height: 1em;
+          padding: 0.1em;
+        }
+        """).strip())        
+
+
+from clevercss import LineIterator
+
+class LineIterTestCase(TestCase):
+    def test_comments(self):
+        line_iter = LineIterator(dedent(
+        """
+        /* block */
+        /* multiblock 
+        */
+                
+        aa, /* comment */bb: 
+            x:1 // comment
+            
+        """))
+        self.assertEqual("\n".join([s[1] for s in line_iter]),
+            "aa, bb:\n    x:1")
+    
 
 if __name__ == '__main__':
     main()
openSUSE Build Service is sponsored by