Commits

Christoph Zwerschke committed e39881f

htmlfill_schemabuilder.parse_schema() was broken.

Comments (0)

Files changed (2)

formencode/htmlfill_schemabuilder.py

 ``Schema`` object.
 """
 
-import validators, schema, compound
+import validators, schema, compound, htmlfill
 
 __all__ = ['parse_schema', 'SchemaBuilder']
 
     Given an HTML form, parse out the schema defined in it and return
     that schema.
     """
-    listener = htmlfill_schemabuilder.SchemaBuilder()
+    listener = SchemaBuilder()
     p = htmlfill.FillingParser(
         defaults={}, listener=listener)
-    p.feed(self.form)
+    p.feed(form)
     p.close()
     return listener.schema()
 
 
     def schema(self):
         return self._schema
-        
+
     def listen_input(self, parser, tag, attrs):
         get_attr = parser.get_attr
         name = get_attr(attrs, 'name')
         if not name:
             # @@: should warn if you try to validate unnamed fields
             return
-        v = compound.All(validators.Identity())
+        v = compound.All(validators.Identity())
         add_to_end = None
         # for checkboxes, we must set if_missing = False
-        if tag.lower() == "input":
+        if tag.lower() == "input":
             type_attr = get_attr(attrs, "type").lower().strip()
             if type_attr == "submit":
                 v.validators.append(validators.Bool())
             elif type_attr == "checkbox":
-                v.validators.append(validators.Wrapper(to_python = force_list))
-            elif type_attr == "file":
+                v.validators.append(validators.Wrapper(to_python = force_list))
+            elif type_attr == "file":
                 add_to_end = validators.FieldStorageUploadConverter()
         message = get_attr(attrs, 'form:message')
         required = to_bool(get_attr(attrs, 'form:required', 'false'))
                 validators.NotEmpty(
                 messages=get_messages(validators.NotEmpty, message)))
         else:
-            v.validators[0].if_missing = False
-        if add_to_end:
+            v.validators[0].if_missing = False
+        if add_to_end:
             v.validators.append(add_to_end)
         v_type = get_attr(attrs, 'form:validate', None)
         if v_type:

tests/test_htmlfill.py

         print expected
         assert 0
     checker(p, listener.schema())
+    checker(p, htmlfill_schemabuilder.parse_schema(template))
 
 def test_no_trailing_newline():
     assert (htmlfill.render('<html><body></body></html>', {}, {})
     assert (htmlfill.render('<input type="submit" value="Japan - &#x65E5;&#x672C; Nihon" />',
                             {}, {}) ==
             u'<input type="submit" value="Japan - 日本 Nihon" />')
-    
+
 def test_xhtml():
     result = htmlfill.render('<form:error name="code"/>', errors={'code': 'an error'})
-    
+
 def test_trailing_error():
     assert (htmlfill.render('<input type="text" name="email">', errors={'email': 'error'},
                             prefix_error=False)
 
 def test_unicode():
     assert (htmlfill.render(u'<input type="checkbox" name="tags" value="2" />',
-                           dict(tags=[])) == 
+                           dict(tags=[])) ==
             '<input type="checkbox" name="tags" value="2" />')
 
 def test_not_force_defaults_text():
     rendered_html = htmlfill.render(html, defaults=dict(),
                                     force_defaults=False)
     assert html == rendered_html, rendered_html
-    
+
 def test_not_force_defaults_select_selected():
     html = """
 <select name="select-1" class="my_select">
     rendered_html = htmlfill.render(html, defaults={"select-1": "option-1"},
                                     force_defaults=False)
     assert expected_html == rendered_html, rendered_html
-    
+
 def test_not_force_defaults_select_not_selected():
     html = """
 <select name="select-1" class="my_select">