dis(): Not all opcodes are printable anymore, so print the repr

of the opcode character instead (but stripping the quotes).

Added a proto 2 test section for the canonical recursive-tuple case.
Note that since pickle's save_tuple() takes different paths depending on
tuple length now, beefier tests are really needed (but not in pickletools);
the "short tuple" case tried here was actually broken yesterday, and it's
subtle stuff so needs to be tested.
This commit is contained in:
Tim Peters 2003-01-28 15:27:57 +00:00
parent 1be3175992
commit d0f7c86a20

View file

@ -1874,7 +1874,7 @@ def dis(pickle, out=None, indentlevel=4):
if pos is not None:
print >> out, "%5d:" % pos,
line = "%s %s%s" % (opcode.code,
line = "%-4s %s%s" % (repr(opcode.code)[1:-1],
indentchunk * len(markstack),
opcode.name)
@ -2068,6 +2068,30 @@ pickle would require the disassembler to emulate the stack.
11: 1 POP_MARK (MARK at 0)
12: h BINGET 1
14: . STOP
Try protocol 2.
>>> dis(pickle.dumps(L, 2))
0: \x80 PROTO 2
2: ] EMPTY_LIST
3: q BINPUT 0
5: h BINGET 0
7: \x85 TUPLE1
8: q BINPUT 1
10: a APPEND
11: . STOP
>>> dis(pickle.dumps(T, 2))
0: \x80 PROTO 2
2: ] EMPTY_LIST
3: q BINPUT 0
5: h BINGET 0
7: \x85 TUPLE1
8: q BINPUT 1
10: a APPEND
11: 0 POP
12: h BINGET 1
14: . STOP
"""
__test__ = {'disassembler_test': _dis_test,