changeset 3:76f5294df3a5

py3
author Jeff Hammel <k0scist@gmail.com>
date Tue, 03 Nov 2020 13:06:46 -0800
parents dc8cc3d30d6d
children f060cb19d58d
files markup/form.py
diffstat 1 files changed, 10 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/markup/form.py	Tue Nov 03 13:04:00 2020 -0800
+++ b/markup/form.py	Tue Nov 03 13:06:46 2020 -0800
@@ -86,7 +86,7 @@
             for validator in validators:
                 try:
                     validation = validator(*args)
-                except Exception, e: # horrible!
+                except Exception as e:
                     error = str(e)
                 else:
                     if isinstance(validation, basestring):
@@ -96,7 +96,7 @@
                 if error:
                     for name in names:
                         add_error(name, error)
-                    
+
         return errors
 
     ### functions to add form elements
@@ -137,7 +137,7 @@
 
             # XXX hacky;  ideally, one would use a list with no bullets
             retval.append('%s%s<br/>' % (markup.input(None, **kw), item))
-            
+
         return '\n'.join(retval)
 
     def radiobuttons(self, name, items, checked=None, joiner='<br/>'):
@@ -158,10 +158,10 @@
                 title = dict(title=title)
             else:
                 title = {}
-                
+
             retval.append(markup.span('%s%s' % (item, markup.input(**kw)),
                           **title))
-            
+
         return joiner.join(retval)
 
     def add_password_confirmation(self, password='Password',
@@ -177,7 +177,6 @@
         match = lambda x, y: (x == y) or "Fields don't match"
         self.validators[(password, confirmation)] = [ match ]
 
-    
     def add_element(self, func, name, *args, **kwargs):
 
         if isinstance(func, basestring):
@@ -193,7 +192,7 @@
 
         # don't diplay hidden elements
         if func_name == 'hidden':
-            self.elements.append(dict(name='', 
+            self.elements.append(dict(name='',
                                       html=func(name, *args, **kwargs)))
             return
 
@@ -204,7 +203,7 @@
         # XXX breaks validation?
         input_name = kwargs.pop('input_name', name)
 
-        self.elements.append(dict(name=name, 
+        self.elements.append(dict(name=name,
                                   html=func(input_name, *args, **kwargs),
                                   help=help))
 
@@ -217,16 +216,13 @@
         * kwargs: dictionary of kwargs: [ { kwargs1 }, { kwargs2 }, ... ]
         """
         html = StringIO()
-        
+
         for func, index in zip(funcs, range(len(funcs))):
             # no validation (yet)
             if isinstance(func, basestring):
                 func = getattr(self, func)
-            print >> html, func('%s-%d' % (name, index), *args[index],
-                                **kwargs[index])
+            html.write('{}\n'.format(func('%s-%d' % (name, index), *args[index],
+                                          **kwargs[index])))
         self.elements.append(dict(name=name,
                                   html=html.getvalue(),
                                   help=help))
-
-
-