Commits

Daniel Fetchinson committed 7bc6cd8

2 errors and 3 failures with python 3.2

Comments (0)

Files changed (1)

formencode/htmlgen.py

 
 """
 
-from cgi import escape
+try:
+    # python3
+    from html import escape
+except ImportError:
+    # python 2.x
+    from cgi import escape
 try:
     import xml.etree.ElementTree as ET
 except ImportError: # Python < 2.5
     def quote(self, arg):
         if arg is None:
             return ''
-        return escape(unicode(arg).encode(default_encoding), 1)
+        import sys
+        if sys.version_info >= (3, 0):
+            return escape(str(arg), 1)
+        else:
+            return escape(unicode(arg).encode(default_encoding), 1)
 
     def str(self, arg, encoding=None):
         if isinstance(arg, str):