]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Fix references to str() type for python3
authorBen Darnell <ben@bendarnell.com>
Thu, 24 Feb 2011 00:59:49 +0000 (16:59 -0800)
committerBen Darnell <ben@bendarnell.com>
Thu, 24 Feb 2011 00:59:49 +0000 (16:59 -0800)
tornado/escape.py

index 3a810da6f0e405959254e1061710d917e519f14a..752c90951aafb815f2ed130276f30275932fdaff 100644 (file)
@@ -21,6 +21,10 @@ import re
 import xml.sax.saxutils
 import urllib
 
+# Python3 compatibility:  On python2.5, introduce the bytes alias from 2.6
+try: bytes
+except: bytes = str
+
 # json module is in the standard library as of python 2.6; fall back to
 # simplejson if present for older versions.
 try:
@@ -93,7 +97,7 @@ def utf8(value):
         return None
     if isinstance(value, unicode):
         return value.encode("utf-8")
-    assert isinstance(value, str)
+    assert isinstance(value, bytes)
     return value
 
 
@@ -185,7 +189,7 @@ def linkify(text, shorten=False, extra_params="",
 
 
 def _unicode(value):
-    if isinstance(value, str):
+    if isinstance(value, bytes):
         return value.decode("utf-8")
     assert isinstance(value, unicode)
     return value