changeset 7:e27d57e7722e

py3
author Jeff Hammel <k0scist@gmail.com>
date Tue, 03 Nov 2020 15:41:02 -0800
parents 275ffbf0a94a
children ad2d8969ce25
files markup/markup.py
diffstat 1 files changed, 15 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/markup/markup.py	Tue Nov 03 15:38:04 2020 -0800
+++ b/markup/markup.py	Tue Nov 03 15:41:02 2020 -0800
@@ -1,4 +1,13 @@
-from cStringIO import StringIO
+try:
+    from cStringIO import StringIO
+except ImportError:
+    try:
+        # python2
+        from StringIO import StringIO
+    except ImportError:
+        # python3
+        from io import StringIO
+
 
 def HTMLmarkup(tag, text=None, **attributes):
     """
@@ -8,7 +17,7 @@
 
     # ideally, this woulod be cached for cascading calls
     s = StringIO()
-    
+
     s.write('<%s' % tag)
     for attribute, value in attributes.items():
         if value is None:
@@ -109,15 +118,14 @@
 
     # convert dicts to lists of 2-tuples
     if hasattr(items, 'items'):
-        items = items.items() 
+        items = items.items()
 
     items = [ dt(term) + dd(definition) for term, definition in items ]
     return dl(('\n%s%s\n' % ( header, '\n'.join(items))), **attributes)
 
-def tablify(rows, header=False, item_attributes=None, 
-            **attributes):
+def tablify(rows, header=False, item_attributes=None, **attributes):
     """return an HTML table from a iterable of iterable rows"""
-    
+
     if item_attributes is None:
         item_attributes = {}
 
@@ -141,8 +149,7 @@
         _head += title(pagetitle)
     rel = 'stylesheet'
     for i in stylesheets:
-        attributes = dict(rel=rel,
-                          type='text/css')        
+        attributes = dict(rel=rel, type='text/css')
         if hasattr(i, '__iter__'):
             # assume a 2-tuple
             attributes['href'] = i[0]