mirror of
https://github.com/python/cpython.git
synced 2025-10-17 20:28:43 +00:00
Finn Bock (SF patch #103349):
Allow pickle.py to be using with Jython unicode strings
This commit is contained in:
parent
f317a18a4a
commit
31584cb43d
1 changed files with 33 additions and 0 deletions
|
@ -300,6 +300,39 @@ class Pickler:
|
|||
memo[d] = (memo_len, object)
|
||||
dispatch[UnicodeType] = save_unicode
|
||||
|
||||
if StringType == UnicodeType:
|
||||
# This is true for Jython
|
||||
def save_string(self, object):
|
||||
d = id(object)
|
||||
memo = self.memo
|
||||
unicode = object.isunicode()
|
||||
|
||||
if (self.bin):
|
||||
if unicode:
|
||||
object = object.encode("utf-8")
|
||||
l = len(object)
|
||||
s = mdumps(l)[1:]
|
||||
if (l < 256 and not unicode):
|
||||
self.write(SHORT_BINSTRING + s[0] + object)
|
||||
else:
|
||||
if unicode:
|
||||
self.write(BINUNICODE + s + object)
|
||||
else:
|
||||
self.write(BINSTRING + s + object)
|
||||
else:
|
||||
if unicode:
|
||||
object = object.replace(u"\\", u"\\u005c")
|
||||
object = object.replace(u"\n", u"\\u000a")
|
||||
object = object.encode('raw-unicode-escape')
|
||||
self.write(UNICODE + object + '\n')
|
||||
else:
|
||||
self.write(STRING + `object` + '\n')
|
||||
|
||||
memo_len = len(memo)
|
||||
self.write(self.put(memo_len))
|
||||
memo[d] = (memo_len, object)
|
||||
dispatch[StringType] = save_string
|
||||
|
||||
def save_tuple(self, object):
|
||||
|
||||
write = self.write
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue