Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the

'L' opcode always appends an 'L' on output, just as 2.x does.  When
unpickling, remove the trailing 'L' (if present) before passing the
result to PyLong_FromString.
This commit is contained in:
Mark Dickinson 2009-01-20 20:43:58 +00:00
parent 6dc4396708
commit 8dd05147d6
5 changed files with 155 additions and 128 deletions

View file

@ -470,7 +470,7 @@ class _Pickler:
else:
self.write(LONG4 + pack("<i", n) + encoded)
return
self.write(LONG + repr(obj).encode("ascii") + b'\n')
self.write(LONG + repr(obj).encode("ascii") + b'L\n')
dispatch[int] = save_long
def save_float(self, obj, pack=struct.pack):
@ -890,6 +890,8 @@ class _Unpickler:
def load_long(self):
val = self.readline()[:-1].decode("ascii")
if val and val[-1] == 'L':
val = val[:-1]
self.append(int(val, 0))
dispatch[LONG[0]] = load_long