Commit dfb64076 authored by Tim Peters's avatar Tim Peters

Added a brief comment to each pickle opcode declaration.

parent bcbb2060
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
See module cPickle for a (much) faster implementation. See module cPickle for a (much) faster implementation.
See module copy_reg for a mechanism for registering custom picklers. See module copy_reg for a mechanism for registering custom picklers.
See module pickletools source for extensive comments.
Classes: Classes:
...@@ -77,50 +78,54 @@ try: ...@@ -77,50 +78,54 @@ try:
except NameError: except NameError:
UnicodeType = None UnicodeType = None
# Pickle opcodes. See pickletools.py for extensive docs. The listing
MARK = '(' # here is in kind-of alphabetical order of 1-character pickle code.
STOP = '.' # pickletools groups them by purpose.
POP = '0'
POP_MARK = '1' MARK = '(' # push special markobject on stack
DUP = '2' STOP = '.' # every pickle ends with STOP
FLOAT = 'F' POP = '0' # discard topmost stack item
INT = 'I' POP_MARK = '1' # discard stack top through topmost markobject
BININT = 'J' DUP = '2' # duplicate top stack item
BININT1 = 'K' FLOAT = 'F' # push float object; decimal string argument
LONG = 'L' INT = 'I' # push integer or bool; decimal string argument
BININT2 = 'M' BININT = 'J' # push four-byte signed int
NONE = 'N' BININT1 = 'K' # push 1-byte unsigned int
PERSID = 'P' LONG = 'L' # push long; decimal string argument
BINPERSID = 'Q' BININT2 = 'M' # push 2-byte unsigned int
REDUCE = 'R' NONE = 'N' # push None
STRING = 'S' PERSID = 'P' # push persistent object; id is taken from string arg
BINSTRING = 'T' BINPERSID = 'Q' # " " " ; " " " " stack
SHORT_BINSTRING = 'U' REDUCE = 'R' # apply callable to argtuple, both on stack
UNICODE = 'V' STRING = 'S' # push string; NL-terminated string argument
BINUNICODE = 'X' BINSTRING = 'T' # push string; counted binary string argument
APPEND = 'a' SHORT_BINSTRING = 'U' # " " ; " " " " < 256 bytes
BUILD = 'b' UNICODE = 'V' # push Unicode string; raw-unicode-escaped'd argument
GLOBAL = 'c' BINUNICODE = 'X' # " " " ; counted UTF-8 string argument
DICT = 'd' APPEND = 'a' # append stack top to list below it
EMPTY_DICT = '}' BUILD = 'b' # call __setstate__ or __dict__.update()
APPENDS = 'e' GLOBAL = 'c' # push self.find_class(modname, name); 2 string args
GET = 'g' DICT = 'd' # build a dict from stack items
BINGET = 'h' EMPTY_DICT = '}' # push empty dict
INST = 'i' APPENDS = 'e' # extend list on stack by topmost stack slice
LONG_BINGET = 'j' GET = 'g' # push item from memo on stack; index is string arg
LIST = 'l' BINGET = 'h' # " " " " " " ; " " 1-byte arg
EMPTY_LIST = ']' INST = 'i' # build & push class instance
OBJ = 'o' LONG_BINGET = 'j' # push item from memo on stack; index is 4-byte arg
PUT = 'p' LIST = 'l' # build list from topmost stack items
BINPUT = 'q' EMPTY_LIST = ']' # push empty list
LONG_BINPUT = 'r' OBJ = 'o' # build & push class instance
SETITEM = 's' PUT = 'p' # store stack top in memo; index is string arg
TUPLE = 't' BINPUT = 'q' # " " " " " ; " " 1-byte arg
EMPTY_TUPLE = ')' LONG_BINPUT = 'r' # " " " " " ; " " 4-byte arg
SETITEMS = 'u' SETITEM = 's' # add key+value pair to dict
BINFLOAT = 'G' TUPLE = 't' # build tuple from topmost stack items
TRUE = 'I01\n' EMPTY_TUPLE = ')' # push empty tuple
FALSE = 'I00\n' SETITEMS = 'u' # modify dict by adding topmost key+value pairs
BINFLOAT = 'G' # push float; arg is 8-byte float encoding
TRUE = 'I01\n' # not an opcode; see INT docs in pickletools.py
FALSE = 'I00\n' # not an opcode; see INT docs in pickletools.py
__all__.extend([x for x in dir() if re.match("[A-Z][A-Z0-9_]+$",x)]) __all__.extend([x for x in dir() if re.match("[A-Z][A-Z0-9_]+$",x)])
...@@ -303,7 +308,7 @@ class Pickler: ...@@ -303,7 +308,7 @@ class Pickler:
if not callable(acallable): if not callable(acallable):
raise PicklingError("__reduce__() must return callable as " raise PicklingError("__reduce__() must return callable as "
"first argument, not %s" % `acallable`) "first argument, not %s" % `acallable`)
save(acallable) save(acallable)
save(arg_tup) save(arg_tup)
write(REDUCE) write(REDUCE)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment