Commits

Manfred Moitzi  committed fccd173

all strings unicode; BUGFIX: rgb() with whitespaces;

  • Participants
  • Parent commits 16b0c20

Comments (0)

Files changed (15)

 NEWS
 ====
 
+Version 0.2.4 - 30 December 2011
+
+  * beta version
+  * Python 2.7: all strings will be converted by the unicode() function, for
+    strings containing none-ascii-characters use prefix ``u""`` or better
+    use ``from __future__ import unicode_literals``, because this is
+    Python 3 compatible.
+  * tested with CPython 2.7, CPython 3.2, and PyPy 1.7
+  * BUGFIX: color parsing accepts white spaces in ``rgb()`` like ``rgb(0, 0, 0)``
+
 Version 0.2.3 - 13 November 2010
 
   * beta version

File TODO.TXT

-
-TODO
-====
-
-Version 0.2.4
--------------
-
-  * status: beta
-  * add more tests and examples
-  * add graphics to the documentation
-
-Version 0.3.0
--------------
-
-  * status: stable
-
-Version 0.4.0
--------------
-
-  * MText: Multi-Line-Text (textArea for SVG 1.1)
-  * Table module
-
-Version 0.5.0
--------------
-
-  * chart module (like google chart tools)
-
-    * line charts
-    * bar charts (2D/3D)
-    * pie charts (2D/3D)
-
-Version 0.6.0
--------------
-
-  * plotting functions (inspired by matplotlib but without dependencies to
-    other libs)
-
-Version 0.7.0
--------------
-
-  * data protocol to embed binary data
-  * audio, video, foreignObject
-
-Version 0.8.0
--------------
-
-  * import parts of SVG files (paths)
-
-Version 1.0.0
--------------
-
-  * finished

File doc/index.rst

 
 Welcome! This is the documentation for svgwrite |version|, last updated |today|.
 
-.. raw:: html
-
-   <a href="http://flattr.com/thing/129230/svgwrite" target="_blank">
-   <img src="http://api.flattr.com/button/flattr-badge-large.png"
-   alt="Flattr this" title="Flattr this" border="0" /></a>
-
 Contents
 --------
 
     "Development Status :: 4 - Beta",
     "License :: OSI Approved :: GNU General Public License (GPL)",
     "Operating System :: OS Independent",
-    "Programming Language :: Python :: 2.5",
-    "Programming Language :: Python :: 2.6",
     "Programming Language :: Python :: 2.7",
     "Programming Language :: Python :: 3",
-    "Programming Language :: Python :: 3.1",
+    "Programming Language :: Python :: 3.2",
+    "Programming Language :: Python :: Implementation :: CPython",
+    "Programming Language :: Python :: Implementation :: PyPy",
     "Intended Audience :: Developers",
 	"Topic :: Multimedia :: Graphics",
     "Topic :: Software Development :: Libraries :: Python Modules",

File svgwrite/__init__.py

 alpha masks, filter effects and template objects.
 
 SVG drawings can be interactive and dynamic. Animations can be defined and
-triggered either declaratively (i.e., by embedding SVG animation elements in
+triggered either declarative (i.e., by embedding SVG animation elements in
 SVG content) or via scripting.
 
 .. seealso:: http://www.w3.org/TR/SVG11/intro.html#AboutSVG
 * *SVG 1.1 Full Profile*, use Drawing(profile= ``'full'``)
 
 """
-
+
+version = (0, 2, 4)
+VERSION = '%d.%d.%d' % version
+
 AUTHOR_NAME = 'Manfred Moitzi'
 AUTHOR_EMAIL = 'mozman@gmx.at'
-CYEAR = '2010'
-
+CYEAR = '2011'
+
 from svgwrite.drawing import Drawing
 from svgwrite.utils import rgb
 
     """ Add units to values.
     """
     def __init__(self, unit='cm'):
-        """ Constructor
+        """ Unit constructor
 
-        :Parameters:
-        - `unit`: specify the unit string
+        :param str unit: specify the unit string
         """
         self._unit=unit
 
         return "%s%s" % (other, self._unit)
 
     def __call__(self, *args):
-        """ add unit-strings to all arguments.
-        :Parameters:
-        - `*args` : list of values
-        e.g.: cm(1,2,3) => '1cm,2cm,3cm'
+        """ Add unit-strings to all arguments.
+
+        :param args: list of values
+            e.g.: cm(1,2,3) => '1cm,2cm,3cm'
         """
         return ','.join(["%s%s" % (arg, self._unit) for arg in args])
 
 grad = Unit('grad')
 rad = Unit('rad')
 Hz = Unit('Hz')
-kHz = Unit('kHz')
+kHz = Unit('kHz')

File svgwrite/animate.py

     elementname = 'set'
 
     def __init__(self, href=None, **extra):
-        """
+        """ Set constructor.
+
         :param href: target svg element, if **href** is not `None`; else
-          the target SVG Element is the parent SVG Element.
+            the target SVG Element is the parent SVG Element.
         """
         super(Set, self).__init__(**extra)
         if href is not None:

File svgwrite/base.py

-#!/usr/bin/env python
+#!/usr/bin/env python
 #coding:utf-8
 # Author:  mozman
 # Purpose: svg base element

File svgwrite/data/typechecker.py

 COLOR_RGB_PERCENTAGE_PATTERN = re.compile(r"^rgb\( *\d+% *, *\d+% *, *\d+% *\)$")
 NMTOKEN_PATTERN = re.compile(r"^[a-zA-Z_:][\w\-\.:]*$")
 
+
 class Full11TypeChecker(object):
     def get_version(self):
         return ('1.1', 'full')
         #           <color> [<icccolor>] |
         #           <funciri> [ "none" | "currentColor" | <color> [<icccolor>] |
         #           "inherit"
-        value = str(value).strip()
+        def split_values(value):
+            try:
+                funcIRI, value = value.split(")", 1)
+                values = [funcIRI+")"]
+                values.extend(split_values(value))
+                return values
+            except ValueError:
+                return value.split()
 
-        for value in [v.strip() for v in value.split()]:
+        values = split_values(str(value).strip())
+        for value in [v.strip() for v in values]:
             if value in ('none', 'currentColor', 'inherit'):
                 continue
             elif self.is_color(value):

File svgwrite/drawing.py

 .. seealso:: :ref:`Common SVG Attributs <Common-SVG-Attributs>`
 
 """
+from __future__ import unicode_literals
+import io
 
 from svgwrite.container import SVG, Defs
 from svgwrite.elementfactory import ElementFactory
-from svgwrite.utils import PYTHON3
 
 class Drawing(SVG, ElementFactory):
     """ This is the SVG drawing represented by the top level **svg** element.
 
     def save(self):
         """ Write the XML string to **filename**. """
-        if PYTHON3:
-            fileobj = open(self.filename, mode='w', encoding='utf-8')
-        else:
-            fileobj = open(self.filename, mode='w')
+        fileobj = io.open(self.filename, mode='w', encoding='utf-8')
         self.write(fileobj)
         fileobj.close()
 

File svgwrite/utils.py

 PYTHON3 = sys.version_info[0] > 2
 
 # Python 3 adaption
-def is_string(value):
-    if PYTHON3:
-        return isinstance(value, str)
-    else:
-        return isinstance(value, basestring)
-
-def to_unicode(value):
-    if PYTHON3:
-        return str(value)
-    else:
-        return str(value).decode('utf-8')
+if PYTHON3:
+    to_unicode = str
+    basestring = str
+else:
+    to_unicode = unicode
 # Python 3 adaption
 
-import re
+def is_string(value):
+    return isinstance(value, basestring)
 
 from svgwrite.data import pattern
 

File tests/test_drawing.py

 # Created: 11.09.2010
 # Copyright (C) 2010, Manfred Moitzi
 # License: GPLv3
+from __future__ import unicode_literals
 
-import sys
 import os
-
 import unittest
-from svgwrite.utils import PYTHON3, to_unicode
-
-if PYTHON3:
-    from io import StringIO
-else:
-    from StringIO import StringIO
+from io import StringIO
 
 from svgwrite.drawing import Drawing
 from svgwrite.container import Group
         dwg.write(f)
         result = f.getvalue()
         f.close()
-        self.assertEqual(result, to_unicode(
+        self.assertEqual(result,
             '<?xml version="1.0" encoding="utf-8" ?>\n' \
             '<svg baseProfile="full" height="100%" version="1.1" width="100%" '\
             'xmlns="http://www.w3.org/2000/svg" xmlns:ev="http://www.w3.org/2001/xml-events" '\
             'xmlns:xlink="http://www.w3.org/1999/xlink">'
-            '<title>öäü</title><defs /></svg>'))
+            '<title>öäü</title><defs /></svg>')
 
 class TestDrawingTinyProfile(unittest.TestCase):
     def test_empty_drawing(self):
 
 
 if __name__=='__main__':
-    unittest.main()
+    unittest.main()

File tests/test_full11_typechecker.py

     def test_is_not_color_name(self):
         self.assertFalse(self.checker.is_color("blau"))
 
+    def test_is_paint_with_funcIRI(self):
+        self.assertTrue(self.checker.is_paint("rgb(10, 20, 30)"))
+
+    def test_is_paint_with_funcIRI_2(self):
+        self.assertTrue(self.checker.is_paint("rgb(10, 20, 30) none"))
+
+    def test_is_paint_with_funcIRI_3(self):
+        self.assertTrue(self.checker.is_paint("url(localhost) rgb(10, 20, 30)"))
+
     def test_is_paint(self):
         self.assertTrue(self.checker.is_paint("inherit"))
         self.assertTrue(self.checker.is_paint("none"))
         self.assertTrue(self.checker.is_shape("rect( auto , auto , auto , auto )"))
 
 if __name__=='__main__' :
-    unittest.main()
+    unittest.main()

File tests/test_text.py

 # Created: 25.09.2010
 # Copyright (C) 2010, Manfred Moitzi
 # License: GPLv3
+from __future__ import unicode_literals
 
 import sys
 import unittest
         self.assertEqual(txt.tostring(), '<textPath xlink:href="#test">text<tspan>subtext</tspan></textPath>')
 
 if __name__=='__main__':
-    unittest.main()
+    unittest.main()

File tests/test_validator2.py

 # Copyright (C) 2010, Manfred Moitzi
 # License: GPLv3
 
-import sys
 import unittest
 
 from svgwrite.validator2 import get_validator
             self.assertRaises(TypeError, validator.check_svg_type, value, 'angle')
 
 if __name__=='__main__':
-    unittest.main()
+    unittest.main()
 downloadcache= ../__cache__
 deps=nose
 commands=nosetests
+[testenv:pypy]
+basepython=c:\pypy-1.7\pypy.exe
+