]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Make these modules work when Python is compiled without Unicode support.
authorGuido van Rossum <guido@python.org>
Fri, 21 Sep 2001 19:22:34 +0000 (19:22 +0000)
committerGuido van Rossum <guido@python.org>
Fri, 21 Sep 2001 19:22:34 +0000 (19:22 +0000)
Lib/pickle.py
Lib/test/test_grammar.py
Lib/zipfile.py

index d5773e24c77b7e512273bec70a6c3d82c1b9f93c..9b59de8dab1c27a1324367befce0851d576a4c5e 100644 (file)
@@ -54,6 +54,12 @@ try:
 except ImportError:
     PyStringMap = None
 
+try:
+    UnicodeType
+except NameError:
+    UnicodeType = None
+
+
 MARK            = '('
 STOP            = '.'
 POP             = '0'
@@ -304,8 +310,8 @@ class Pickler:
             s = mdumps(l)[1:]
             self.write(BINUNICODE + s + encoding)
         else:
-            object = object.replace(u"\\", u"\\u005c")
-            object = object.replace(u"\n", u"\\u000a")
+            object = object.replace("\\", "\\u005c")
+            object = object.replace("\n", "\\u000a")
             self.write(UNICODE + object.encode('raw-unicode-escape') + '\n')
 
         memo_len = len(memo)
@@ -334,8 +340,8 @@ class Pickler:
                         self.write(BINSTRING + s + object)
             else:
                 if unicode:
-                    object = object.replace(u"\\", u"\\u005c")
-                    object = object.replace(u"\n", u"\\u000a")
+                    object = object.replace("\\", "\\u005c")
+                    object = object.replace("\n", "\\u000a")
                     object = object.encode('raw-unicode-escape')
                     self.write(UNICODE + object + '\n')
                 else:
index 254e00654017e65051809703af941de07b5c26d4..e5ba73e6d6a0b6e13a5827ca54414e6c7c3e2b76 100644 (file)
@@ -394,11 +394,15 @@ def f():
     if z != 2: raise TestFailed, 'exec \'z=1+1\''
     z = None
     del z
+    import types
+    if hasattr(types, "UnicodeType"):
+        exec r"""if 1:
     exec u'z=1+1\n'
     if z != 2: raise TestFailed, 'exec u\'z=1+1\'\\n'
     del z
     exec u'z=1+1'
     if z != 2: raise TestFailed, 'exec u\'z=1+1\''
+"""
 f()
 g = {}
 exec 'z = 1' in g
index 816d887ee5ce5d1b60525afa7e781de798571af2..a06731e4c930546827393ad78c2eab2463ef7fda 100644 (file)
@@ -66,7 +66,10 @@ _FH_FILENAME_LENGTH = 10
 _FH_EXTRA_FIELD_LENGTH = 11
 
 # Used to compare file passed to ZipFile
-_STRING_TYPES = (type('s'), type(u's'))
+import types
+_STRING_TYPES = (types.StringType,)
+if hasattr(types, "UnicodeType"):
+    _STRING_TYPES = _STRING_TYPES + (types.UnicodeType,)
 
 
 def is_zipfile(filename):