diff options
author | Guido van Rossum <guido@python.org> | 2001-01-22 14:53:29 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2001-01-22 14:53:29 (GMT) |
commit | 31584cb43d1cb8b393b110ef0b994fd431d7dbb6 (patch) | |
tree | 8ba5249d1f2fc4ca89d68f80ec2703ee077f23db /Lib/pickle.py | |
parent | f317a18a4ac6bcdd9b31295af04d27b549c4126a (diff) | |
download | cpython-31584cb43d1cb8b393b110ef0b994fd431d7dbb6.zip cpython-31584cb43d1cb8b393b110ef0b994fd431d7dbb6.tar.gz cpython-31584cb43d1cb8b393b110ef0b994fd431d7dbb6.tar.bz2 |
Finn Bock (SF patch #103349):
Allow pickle.py to be using with Jython unicode strings
Diffstat (limited to 'Lib/pickle.py')
-rw-r--r-- | Lib/pickle.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/Lib/pickle.py b/Lib/pickle.py index 45fd0f1..1ec5b49 100644 --- a/Lib/pickle.py +++ b/Lib/pickle.py @@ -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 |