diff options
author | Mark Dickinson <dickinsm@gmail.com> | 2009-01-20 20:43:58 +0000 |
---|---|---|
committer | Mark Dickinson <dickinsm@gmail.com> | 2009-01-20 20:43:58 +0000 |
commit | 8dd05147d6224f4982ef6b14d904bb600ef33ea3 (patch) | |
tree | f65fc6569e9fdb3ef82719d268531676f2b2743d /Lib/pickletools.py | |
parent | Blocked revisions 68764,68766 via svnmerge (diff) | |
download | cpython-8dd05147d6224f4982ef6b14d904bb600ef33ea3.tar.gz cpython-8dd05147d6224f4982ef6b14d904bb600ef33ea3.tar.bz2 cpython-8dd05147d6224f4982ef6b14d904bb600ef33ea3.zip |
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.
Diffstat (limited to 'Lib/pickletools.py')
-rw-r--r-- | Lib/pickletools.py | 78 |
1 files changed, 40 insertions, 38 deletions
diff --git a/Lib/pickletools.py b/Lib/pickletools.py index 1dd45da807c..6614df718a2 100644 --- a/Lib/pickletools.py +++ b/Lib/pickletools.py @@ -527,6 +527,8 @@ def read_decimalnl_long(f): """ s = read_stringnl(f, decode=False, stripquotes=False) + if s[-1:] == b'L': + s = s[:-1] return int(s) @@ -2052,39 +2054,39 @@ _dis_test = r""" 1: l LIST (MARK at 0) 2: p PUT 0 5: L LONG 1 - 8: a APPEND - 9: L LONG 2 - 12: a APPEND - 13: ( MARK - 14: L LONG 3 - 17: L LONG 4 - 20: t TUPLE (MARK at 13) - 21: p PUT 1 - 24: a APPEND - 25: ( MARK - 26: d DICT (MARK at 25) - 27: p PUT 2 - 30: c GLOBAL 'builtins bytes' - 46: p PUT 3 - 49: ( MARK - 50: ( MARK - 51: l LIST (MARK at 50) - 52: p PUT 4 - 55: L LONG 97 - 59: a APPEND - 60: L LONG 98 + 9: a APPEND + 10: L LONG 2 + 14: a APPEND + 15: ( MARK + 16: L LONG 3 + 20: L LONG 4 + 24: t TUPLE (MARK at 15) + 25: p PUT 1 + 28: a APPEND + 29: ( MARK + 30: d DICT (MARK at 29) + 31: p PUT 2 + 34: c GLOBAL 'builtins bytes' + 50: p PUT 3 + 53: ( MARK + 54: ( MARK + 55: l LIST (MARK at 54) + 56: p PUT 4 + 59: L LONG 97 64: a APPEND - 65: L LONG 99 - 69: a APPEND - 70: t TUPLE (MARK at 49) - 71: p PUT 5 - 74: R REDUCE - 75: p PUT 6 - 78: V UNICODE 'def' - 83: p PUT 7 - 86: s SETITEM - 87: a APPEND - 88: . STOP + 65: L LONG 98 + 70: a APPEND + 71: L LONG 99 + 76: a APPEND + 77: t TUPLE (MARK at 53) + 78: p PUT 5 + 81: R REDUCE + 82: p PUT 6 + 85: V UNICODE 'def' + 90: p PUT 7 + 93: s SETITEM + 94: a APPEND + 95: . STOP highest protocol among opcodes = 0 Try again with a "binary" pickle. @@ -2157,12 +2159,12 @@ highest protocol among opcodes = 0 92: V UNICODE 'value' 99: p PUT 7 102: L LONG 42 - 106: s SETITEM - 107: b BUILD - 108: a APPEND - 109: g GET 5 - 112: a APPEND - 113: . STOP + 107: s SETITEM + 108: b BUILD + 109: a APPEND + 110: g GET 5 + 113: a APPEND + 114: . STOP highest protocol among opcodes = 0 >>> dis(pickle.dumps(x, 1)) |