Author: pjenvey
Date: 2007-05-25 17:53:52 -0600 (Fri, 25 May 2007)
New Revision: 2703

Modified:
   FormEncode/trunk/formencode/htmlfill.py
   FormEncode/trunk/tests/test_htmlfill.py
Log:
o fix charref unescaping, added a test
o removed debug statements

Modified: FormEncode/trunk/formencode/htmlfill.py
===================================================================
--- FormEncode/trunk/formencode/htmlfill.py     2007-05-25 02:00:09 UTC (rev 
2702)
+++ FormEncode/trunk/formencode/htmlfill.py     2007-05-25 23:53:52 UTC (rev 
2703)
@@ -264,8 +264,8 @@
     def add_key(self, key):
         self.used_keys[key] = 1
 
-    _entityref_re = re.compile('&([a-zA-Z][-.a-zA-Z0-9]*);')
-    _charref_re = re.compile('&#(?:[0-9]+|[xX][0-9a-fA-F]+);')
+    _entityref_re = re.compile('&([a-zA-Z][-.a-zA-Z\d]*);')
+    _charref_re = re.compile('&#(\d+|[xX][a-fA-F\d]+);')
 
     def unescape(self, s):
         s = self._entityref_re.sub(self._sub_entityref, s)
@@ -282,8 +282,8 @@
 
     def _sub_charref(self, match):
         num = match.group(1)
-        if num.lower().startswith('0x'):
-            num = int(num, 16)
+        if num.lower().startswith('x'):
+            num = int(num[1:], 16)
         else:
             num = int(num)
         return unichr(num)
@@ -368,7 +368,6 @@
         self.used_errors[name] = 1
 
     def handle_input(self, attrs, startend):
-        print 'attrs', attrs
         t = (self.get_attr(attrs, 'type') or 'text').lower()
         name = self.get_attr(attrs, 'name')
         self.write_marker(name)
@@ -428,7 +427,6 @@
             self.skip_next = True
             self.add_key(name)
         elif t == 'submit' or t == 'reset' or t == 'button':
-            print 'set_attr', repr(value or self.get_attr(attrs, 'value', ''))
             self.set_attr(attrs, 'value', value or
                           self.get_attr(attrs, 'value', ''))
             self.write_tag('input', attrs, startend)

Modified: FormEncode/trunk/tests/test_htmlfill.py
===================================================================
--- FormEncode/trunk/tests/test_htmlfill.py     2007-05-25 02:00:09 UTC (rev 
2702)
+++ FormEncode/trunk/tests/test_htmlfill.py     2007-05-25 23:53:52 UTC (rev 
2703)
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
 import sys
 import os
 import re
@@ -82,3 +83,7 @@
             == '<input type="submit" value="next&gt;%s">' % rarr)
     assert (htmlfill.render('<input type="submit" value="1&amp;2">', {}, {})
             == '<input type="submit" value="1&amp;2">')
+    assert (htmlfill.render('<input type="submit" value="Japan - 
&#x65E5;&#x672C; Nihon" />',
+                            {}, {}) ==
+            u'<input type="submit" value="Japan - 日本 Nihon" />')
+    


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
FormEncode-CVS mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/formencode-cvs

Reply via email to