mirror of
https://github.com/python/cpython.git
synced 2025-07-13 14:25:18 +00:00
Make these modules work when Python is compiled without Unicode support.
This commit is contained in:
parent
11310bf867
commit
dbb718fa87
3 changed files with 18 additions and 5 deletions
|
@ -54,6 +54,12 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
PyStringMap = None
|
PyStringMap = None
|
||||||
|
|
||||||
|
try:
|
||||||
|
UnicodeType
|
||||||
|
except NameError:
|
||||||
|
UnicodeType = None
|
||||||
|
|
||||||
|
|
||||||
MARK = '('
|
MARK = '('
|
||||||
STOP = '.'
|
STOP = '.'
|
||||||
POP = '0'
|
POP = '0'
|
||||||
|
@ -304,8 +310,8 @@ class Pickler:
|
||||||
s = mdumps(l)[1:]
|
s = mdumps(l)[1:]
|
||||||
self.write(BINUNICODE + s + encoding)
|
self.write(BINUNICODE + s + encoding)
|
||||||
else:
|
else:
|
||||||
object = object.replace(u"\\", u"\\u005c")
|
object = object.replace("\\", "\\u005c")
|
||||||
object = object.replace(u"\n", u"\\u000a")
|
object = object.replace("\n", "\\u000a")
|
||||||
self.write(UNICODE + object.encode('raw-unicode-escape') + '\n')
|
self.write(UNICODE + object.encode('raw-unicode-escape') + '\n')
|
||||||
|
|
||||||
memo_len = len(memo)
|
memo_len = len(memo)
|
||||||
|
@ -334,8 +340,8 @@ class Pickler:
|
||||||
self.write(BINSTRING + s + object)
|
self.write(BINSTRING + s + object)
|
||||||
else:
|
else:
|
||||||
if unicode:
|
if unicode:
|
||||||
object = object.replace(u"\\", u"\\u005c")
|
object = object.replace("\\", "\\u005c")
|
||||||
object = object.replace(u"\n", u"\\u000a")
|
object = object.replace("\n", "\\u000a")
|
||||||
object = object.encode('raw-unicode-escape')
|
object = object.encode('raw-unicode-escape')
|
||||||
self.write(UNICODE + object + '\n')
|
self.write(UNICODE + object + '\n')
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -394,11 +394,15 @@ def f():
|
||||||
if z != 2: raise TestFailed, 'exec \'z=1+1\''
|
if z != 2: raise TestFailed, 'exec \'z=1+1\''
|
||||||
z = None
|
z = None
|
||||||
del z
|
del z
|
||||||
|
import types
|
||||||
|
if hasattr(types, "UnicodeType"):
|
||||||
|
exec r"""if 1:
|
||||||
exec u'z=1+1\n'
|
exec u'z=1+1\n'
|
||||||
if z != 2: raise TestFailed, 'exec u\'z=1+1\'\\n'
|
if z != 2: raise TestFailed, 'exec u\'z=1+1\'\\n'
|
||||||
del z
|
del z
|
||||||
exec u'z=1+1'
|
exec u'z=1+1'
|
||||||
if z != 2: raise TestFailed, 'exec u\'z=1+1\''
|
if z != 2: raise TestFailed, 'exec u\'z=1+1\''
|
||||||
|
"""
|
||||||
f()
|
f()
|
||||||
g = {}
|
g = {}
|
||||||
exec 'z = 1' in g
|
exec 'z = 1' in g
|
||||||
|
|
|
@ -66,7 +66,10 @@ _FH_FILENAME_LENGTH = 10
|
||||||
_FH_EXTRA_FIELD_LENGTH = 11
|
_FH_EXTRA_FIELD_LENGTH = 11
|
||||||
|
|
||||||
# Used to compare file passed to ZipFile
|
# 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):
|
def is_zipfile(filename):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue