[Python-checkins] python/nondist/sandbox/pickletools pickletools.py,1.31,1.32
tim_one@users.sourceforge.net
tim_one@users.sourceforge.net
Mon, 27 Jan 2003 07:38:17 -0800
Update of /cvsroot/python/python/nondist/sandbox/pickletools
In directory sc8-pr-cvs1:/tmp/cvs-serv12961
Modified Files:
pickletools.py
Log Message:
dis(): Indenting MARK blocks improves clarity.
All over: minor typo repair and fiddling.
Index: pickletools.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/pickletools/pickletools.py,v
retrieving revision 1.31
retrieving revision 1.32
diff -C2 -d -r1.31 -r1.32
*** pickletools.py 27 Jan 2003 14:26:48 -0000 1.31
--- pickletools.py 27 Jan 2003 15:38:14 -0000 1.32
***************
*** 1403,1409 ****
stack_after=[anyobject],
proto=0,
! doc="""Push an object identified by a persisent ID.
! The pickle module doesn't define what a persisent ID means. PERSID's
argument is a newline-terminated str-style (no embedded escapes, no
bracketing quote characters) string, which *is* "the persistent ID".
--- 1403,1409 ----
stack_after=[anyobject],
proto=0,
! doc="""Push an object identified by a persistent ID.
! The pickle module doesn't define what a persistent ID means. PERSID's
argument is a newline-terminated str-style (no embedded escapes, no
bracketing quote characters) string, which *is* "the persistent ID".
***************
*** 1434,1439 ****
code2i = {}
! i = 0
! for d in opcodes:
if d.name in name2i:
raise ValueError("repeated name %r at indices %d and %d" %
--- 1434,1438 ----
code2i = {}
! for i, d in enumerate(opcodes):
if d.name in name2i:
raise ValueError("repeated name %r at indices %d and %d" %
***************
*** 1445,1449 ****
name2i[d.name] = i
code2i[d.code] = i
- i += 1
del name2i, code2i, i, d
--- 1444,1447 ----
***************
*** 1559,1563 ****
# A symbolic pickle disassembler.
! def dis(pickle, out=None):
"""Produce a symbolic disassembly of a pickle.
--- 1557,1561 ----
# A symbolic pickle disassembler.
! def dis(pickle, out=None, indentlevel=4):
"""Produce a symbolic disassembly of a pickle.
***************
*** 1568,1582 ****
Optional arg 'out' is a file-like object to which the disassembly is
printed. It defaults to sys.stdout.
"""
markstack = []
for opcode, arg, pos in genops(pickle):
if pos is not None:
print >> out, "%5d:" % pos,
! line = opcode.code + " " + opcode.name
markmsg = None
if markstack and markobject in opcode.stack_before:
markpos = markstack.pop()
if markpos is not None:
--- 1566,1587 ----
Optional arg 'out' is a file-like object to which the disassembly is
printed. It defaults to sys.stdout.
+
+ Optional arg indentlevel is the number of blanks by which to indent
+ a new MARK level. It defaults to 4.
"""
markstack = []
+ indentchunk = ' ' * indentlevel
for opcode, arg, pos in genops(pickle):
if pos is not None:
print >> out, "%5d:" % pos,
! line = "%s %s%s" % (opcode.code,
! indentchunk * len(markstack),
! opcode.name)
markmsg = None
if markstack and markobject in opcode.stack_before:
+ assert markobject not in opcode.stack_after
markpos = markstack.pop()
if markpos is not None:
***************
*** 1585,1589 ****
if arg is not None or markmsg:
# make a mild effort to align arguments
! line += (' ' * 10)[len(opcode.name):]
if arg is not None:
line += ' ' + repr(arg)
--- 1590,1594 ----
if arg is not None or markmsg:
# make a mild effort to align arguments
! line += ' ' * (10 - len(opcode.name))
if arg is not None:
line += ' ' + repr(arg)
***************
*** 1593,1596 ****
--- 1598,1602 ----
if markobject in opcode.stack_after:
+ assert markobject not in opcode.stack_before
markstack.append(pos)
***************
*** 1602,1606 ****
>>> dis(pik)
0: ( MARK
! 1: l LIST (MARK at 0)
2: p PUT 0
5: I INT 1
--- 1608,1612 ----
>>> dis(pik)
0: ( MARK
! 1: l LIST (MARK at 0)
2: p PUT 0
5: I INT 1
***************
*** 1609,1619 ****
12: a APPEND
13: ( MARK
! 14: I INT 3
! 17: I INT 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: S STRING 'abc'
--- 1615,1625 ----
12: a APPEND
13: ( MARK
! 14: I INT 3
! 17: I INT 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: S STRING 'abc'
***************
*** 1632,1650 ****
1: q BINPUT 0
3: ( MARK
! 4: K BININT1 1
! 6: K BININT1 2
! 8: ( MARK
! 9: K BININT1 3
! 11: K BININT1 4
! 13: t TUPLE (MARK at 8)
! 14: q BINPUT 1
! 16: } EMPTY_DICT
! 17: q BINPUT 2
! 19: U SHORT_BINSTRING 'abc'
! 24: q BINPUT 3
! 26: X BINUNICODE u'def'
! 34: q BINPUT 4
! 36: s SETITEM
! 37: e APPENDS (MARK at 3)
38: . STOP
--- 1638,1656 ----
1: q BINPUT 0
3: ( MARK
! 4: K BININT1 1
! 6: K BININT1 2
! 8: ( MARK
! 9: K BININT1 3
! 11: K BININT1 4
! 13: t TUPLE (MARK at 8)
! 14: q BINPUT 1
! 16: } EMPTY_DICT
! 17: q BINPUT 2
! 19: U SHORT_BINSTRING 'abc'
! 24: q BINPUT 3
! 26: X BINUNICODE u'def'
! 34: q BINPUT 4
! 36: s SETITEM
! 37: e APPENDS (MARK at 3)
38: . STOP
***************
*** 1660,1675 ****
>>> dis(pickle.dumps(x))
0: ( MARK
! 1: l LIST (MARK at 0)
2: p PUT 0
5: ( MARK
! 6: i INST 'pickle.PicklingError' (MARK at 5)
28: p PUT 1
31: ( MARK
! 32: d DICT (MARK at 31)
33: p PUT 2
36: S STRING 'args'
44: p PUT 3
47: ( MARK
! 48: t TUPLE (MARK at 47)
49: p PUT 4
52: s SETITEM
--- 1666,1681 ----
>>> dis(pickle.dumps(x))
0: ( MARK
! 1: l LIST (MARK at 0)
2: p PUT 0
5: ( MARK
! 6: i INST 'pickle.PicklingError' (MARK at 5)
28: p PUT 1
31: ( MARK
! 32: d DICT (MARK at 31)
33: p PUT 2
36: S STRING 'args'
44: p PUT 3
47: ( MARK
! 48: t TUPLE (MARK at 47)
49: p PUT 4
52: s SETITEM
***************
*** 1684,1701 ****
1: q BINPUT 0
3: ( MARK
! 4: ( MARK
! 5: c GLOBAL 'pickle.PicklingError'
! 27: q BINPUT 1
! 29: o OBJ (MARK at 4)
! 30: q BINPUT 2
! 32: } EMPTY_DICT
! 33: q BINPUT 3
! 35: U SHORT_BINSTRING 'args'
! 41: q BINPUT 4
! 43: ) EMPTY_TUPLE
! 44: s SETITEM
! 45: b BUILD
! 46: h BINGET 2
! 48: e APPENDS (MARK at 3)
49: . STOP
"""
--- 1690,1707 ----
1: q BINPUT 0
3: ( MARK
! 4: ( MARK
! 5: c GLOBAL 'pickle.PicklingError'
! 27: q BINPUT 1
! 29: o OBJ (MARK at 4)
! 30: q BINPUT 2
! 32: } EMPTY_DICT
! 33: q BINPUT 3
! 35: U SHORT_BINSTRING 'args'
! 41: q BINPUT 4
! 43: ) EMPTY_TUPLE
! 44: s SETITEM
! 45: b BUILD
! 46: h BINGET 2
! 48: e APPENDS (MARK at 3)
49: . STOP
"""