# HG changeset patch # User Jeff Hammel # Date 1604446684 28800 # Node ID 275ffbf0a94a1127508c2f7ab2e6d6ddcd76f0bb # Parent 40eefa5b52236f6d63a3930955573feea8764830 py3 diff -r 40eefa5b5223 -r 275ffbf0a94a markup/form.py --- 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'}