summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2001-09-21 19:22:34 (GMT)
committerGuido van Rossum <guido@python.org>2001-09-21 19:22:34 (GMT)
commitdbb718fa8775731666bb9cbc73662fadee41ea8f (patch)
tree9081dce67bff0bca69fe2eed9e6e832126edd77e
parent11310bf867ae1c26d2ad9dc696bf2331709b9843 (diff)
downloadcpython-dbb718fa8775731666bb9cbc73662fadee41ea8f.zip
cpython-dbb718fa8775731666bb9cbc73662fadee41ea8f.tar.gz
cpython-dbb718fa8775731666bb9cbc73662fadee41ea8f.tar.bz2
Make these modules work when Python is compiled without Unicode support.
-rw-r--r--Lib/pickle.py14
-rw-r--r--Lib/test/test_grammar.py4
-rw-r--r--Lib/zipfile.py5
3 files changed, 18 insertions, 5 deletions
diff --git a/Lib/pickle.py b/Lib/pickle.py
index d5773e2..9b59de8 100644
--- a/Lib/pickle.py
+++ b/Lib/pickle.py
@@ -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:
diff --git a/Lib/test/test_grammar.py b/Lib/test/test_grammar.py
index 254e006..e5ba73e 100644
--- a/Lib/test/test_grammar.py
+++ b/Lib/test/test_grammar.py
@@ -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
diff --git a/Lib/zipfile.py b/Lib/zipfile.py
index 816d887..a06731e 100644
--- a/Lib/zipfile.py
+++ b/Lib/zipfile.py
@@ -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):