changeset 6:275ffbf0a94a

py3
author Jeff Hammel <k0scist@gmail.com>
date Tue, 03 Nov 2020 15:38:04 -0800
parents 40eefa5b5223
children e27d57e7722e
files markup/form.py
diffstat 1 files changed, 14 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/markup/form.py	Tue Nov 03 13:10:34 2020 -0800
+++ b/markup/form.py	Tue Nov 03 15:38:04 2020 -0800
@@ -8,6 +8,9 @@
     except ModuleNotFoundError:
         from io import StringIO
 
+# python3 only
+string = (str,)
+
 
 class Form(object):
     """a simple class for HTML forms"""
@@ -28,7 +31,7 @@
     def __call__(self, errors=None):
         """render the form"""
         retval = StringIO()
-        print >> retval
+        retval.write('\n')
 
         def name_field(element):
             if not element['name']:
@@ -40,27 +43,29 @@
             return markup.span(markup.strong('%s:' % element['name']), **title)
 
         # print the form as a table
-        table = [ [ name_field(element), element['html'] ]
-                  for element in self.elements ]
+        table = [[name_field(element), element['html']]
+                 for element in self.elements]
         if errors:
             for row, element in zip(table, self.elements):
                 error = errors.get(element['name'], '')
                 if error:
-                    if not isinstance(error, basestring):
+                    if not isinstance(error, string):
                         if len(error) == 1:
                             error = error[0]
                         else:
                             error = markup.listify(error)
                     error = markup.div(error, **{ 'class': 'error' })
                 row.append(error)
-            
-        print >> retval, markup.tablify(table)
-        print >> retval, self.post_html
+
+        retval.write('{}\n'.format(markup.tablify(table)))
+        retval.write('{}\n'.format(self.post_html)
 
         # each form has a submit button
         # XXX this should probably be more customizable
-        print >> retval, markup.input(None, type='submit', name='submit',
-                                      value=self.submit),
+        retval.write('{}\n'.format(markup.input(None,
+                                                type='submit',
+                                                name='submit',
+                                                value=self.submit)))
 
         args = { 'method': self.method,
                  'enctype': 'multipart/form-data'}