|
5 | 5 | :synopsis: Contains extensive comments about the pickle protocols and |
6 | 6 | pickle-machine opcodes, as well as some useful functions. |
7 | 7 |
|
| 8 | +**Source code:** :source:`Lib/pickletools.py` |
| 9 | + |
| 10 | +-------------- |
| 11 | + |
| 12 | + |
8 | 13 | This module contains various constants relating to the intimate details of the |
9 | 14 | :mod:`pickle` module, some lengthy comments about the implementation, and a |
10 | 15 | few useful functions for analyzing pickled data. The contents of this module |
11 | 16 | are useful for Python core developers who are working on the :mod:`pickle`; |
12 | 17 | ordinary users of the :mod:`pickle` module probably won't find the |
13 | 18 | :mod:`pickletools` module relevant. |
14 | 19 |
|
| 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 | + |
15 | 79 |
|
16 | 80 | .. function:: dis(pickle, out=None, memo=None, indentlevel=4, annotate=0) |
17 | 81 |
|
|
0 commit comments