# HG changeset patch # User Jeff Hammel # Date 1604446862 28800 # Node ID e27d57e7722e1e372ff640fac8632d55b215af1c # Parent 275ffbf0a94a1127508c2f7ab2e6d6ddcd76f0bb py3 diff -r 275ffbf0a94a -r e27d57e7722e markup/markup.py --- 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]