Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cc75a86

Browse files
committed
Issue #9268: Documented -m pickletools usage.
Also added a source code link.
1 parent d958ea7 commit cc75a86

1 file changed

Lines changed: 64 additions & 0 deletions

File tree

Doc/library/pickletools.rst

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,77 @@
55
:synopsis: Contains extensive comments about the pickle protocols and
66
pickle-machine opcodes, as well as some useful functions.
77

8+
**Source code:** :source:`Lib/pickletools.py`
9+
10+
--------------
11+
12+
813
This module contains various constants relating to the intimate details of the
914
:mod:`pickle` module, some lengthy comments about the implementation, and a
1015
few useful functions for analyzing pickled data. The contents of this module
1116
are useful for Python core developers who are working on the :mod:`pickle`;
1217
ordinary users of the :mod:`pickle` module probably won't find the
1318
:mod:`pickletools` module relevant.
1419

20+
Command line usage
21+
------------------
22+
23+
.. versionadded:: 3.2
24+
25+
When invoked from the command line, ``python -m pickletools`` will
26+
disassemble the contents of one or more pickle files. Note that if
27+
you want to see the Python object stored in the pickle rather than the
28+
details of pickle format, you may want to use ``-m pickle`` instead.
29+
However, when the pickle file that you want to examine comes from an
30+
untrusted source, ``-m pickletools`` is a safer option because it does
31+
not execute pickle bytecode.
32+
33+
For example, with a tuple ``(1, 2)`` pickled in file ``x.pickle``::
34+
35+
$ python -m pickle x.pickle
36+
(1, 2)
37+
38+
$ python -m pickletools x.pickle
39+
0: \x80 PROTO 3
40+
2: K BININT1 1
41+
4: K BININT1 2
42+
6: \x86 TUPLE2
43+
7: q BINPUT 0
44+
9: . STOP
45+
highest protocol among opcodes = 2
46+
47+
Command line options
48+
^^^^^^^^^^^^^^^^^^^^
49+
50+
.. program:: pickletools
51+
52+
.. cmdoption:: -a, --annotate
53+
54+
Annotate each line with a short opcode description.
55+
56+
.. cmdoption:: -o, --output=<file>
57+
58+
Name of a file where the output should be written.
59+
60+
.. cmdoption:: -l, --indentlevel=<num>
61+
62+
The number of blanks by which to indent a new MARK level.
63+
64+
.. cmdoption:: -m, --memo
65+
66+
When multiple objects are disassembled, preserve memo between
67+
disassemblies.
68+
69+
.. cmdoption:: -p, --preamble=<preamble>
70+
71+
When more than one pickle file are specified, print given preamble
72+
before each disassembly.
73+
74+
75+
76+
Programmatic Interface
77+
----------------------
78+
1579

1680
.. function:: dis(pickle, out=None, memo=None, indentlevel=4, annotate=0)
1781

0 commit comments

Comments
 (0)