Commits

Manfred Moitzi committed 5ebd9fc

restored Python 3 compatibility

  • Participants
  • Parent commits 600e9de

Comments (0)

Files changed (5)

 NEWS
 ====
 
+Version 0.2.5 - ...
+  * added script tag - thx to jmahmood
+  * docs also available at: http://readthedocs.org/docs/svgwrite
+
 Version 0.2.4 - 30 December 2011
 
   * beta version
 =============
 
 http://packages.python.org/svgwrite
+http://readthedocs.org/docs/svgwrite/
 
 send feedback to mozman@gmx.at
 

svgwrite/container.py

 
 """
 
+from lxml import etree
+from svgwrite.utils import to_unicode
+
 from svgwrite.base import BaseElement
 from svgwrite.mixins import ViewBox, Transform, XLink
 from svgwrite.mixins import Presentation, Clipping
     """
 
     elementname = 'script'
-    def __init__(self, href, type='text/ecmascript', **extra):
+    def __init__(self, href, **extra):
+        # tried to implement script text content, but failed on awkward
+        # lxml CDATA serialisation problems.
         """
         :param string href: hyperlink to the target resource
-        :param string type: This is the type of script being used.
         :param extra: additional attributes as keyword-arguments
         """
+        # removed type parameter, default is "application/ecmascript"
         super(Script, self).__init__(**extra)
         self['xlink:href'] = href
-        self['type'] = type

svgwrite/drawing.py

         # write stylesheets
         stylesheet_template = '<?xml-stylesheet href="%s" type="text/css" ' \
                      'title="%s" alternate="%s" media="%s"?>\n'
-        map( lambda s: fileobj.write( stylesheet_template % s ), self._stylesheets)
+        # removed map(), does not work with Python 3
+        for stylesheet in self._stylesheets:
+            fileobj.write(stylesheet_template % stylesheet)
         fileobj.write(self.tostring())
 
     def save(self):

tests/test_script.py

 from svgwrite.container import Script
 
 class TestScript(unittest.TestCase):
-    def test_constructor(self):
-        script = Script('test.js', "text/ecmascript")
-        self.assertEqual(script.tostring(), '<script type="text/ecmascript" xlink:href="test.js" />')
+    def test_link(self):
+        script = Script('test.js')
+        self.assertEqual(script.tostring(), '<script xlink:href="test.js" />')
+
+    def test_type(self):
+        script = Script('test.py', type='application/python')
+        self.assertEqual(script.tostring(), '<script type="application/python" xlink:href="test.py" />')
+
 
 if __name__=='__main__':
     unittest.main()