pickletools
就业培训 下载中心 Wiki 联络 登录 注册 首页 Python 3.12.4 索引 模块 下一 上一 Python 标准库 Python 语言服务 pickletools — 用于腌制开发者的工具 pickletools — 用于腌制开发者的工具 ¶ 源代码: Lib/pickletools.py 此模块包含的各种常量细节密切相关 pickle module, some lengthy comments about the implementation, and a few useful functions for analyzing pickled data. The contents of this module are useful for Python core developers who are working on the pickle ; ordinary users of the pickle module probably won’t find the pickletools module relevant. 命令行用法 ¶ Added in version 3.2. 当援引自命令行时, python -m pickletools will disassemble the contents of one or more pickle files. Note that if you want to see the Python object stored in the pickle rather than the details of pickle format, you may want to use -m pickle instead. However, when the pickle file that you want to examine comes from an untrusted source, -m pickletools is a safer option because it does not execute pickle bytecode. 例如,采用元组 (1, 2) pickled in file x.pickle : $ python -m pickle x.pickle (1, 2) $ python -m pickletools x.pickle 0: \x80 PROTO 3 2: K BININT1 1 4: K BININT1 2 6: \x86 TUPLE2 7: q BINPUT 0 9: . STOP highest protocol among opcodes = 2 命令行选项 ¶ -a , --annotate ¶ Annotate each line with a short opcode description. -o , --output =<file> ¶ Name of a file where the output should be written. -l , --indentlevel =<num> ¶ The number of blanks by which to indent a new MARK level. -m , --memo ¶ When multiple objects are disassembled, preserve memo between disassemblies. -p , --preamble =<preamble> ¶ When more than one pickle file are specified, print given preamble before each disassembly. 编程方式接口 ¶ pickletools. dis ( pickle , out = None , memo = None , indentlevel = 4 , annotate = 0 ) ¶ Outputs a symbolic disassembly of the pickle to the file-like object out ,默认为 sys.stdout . pickle can be a string or a file-like object. memo can be a Python dictionary that will be used as the pickle’s memo; it can be used to perform disassemblies across multiple pickles created by the same pickler. Successive levels, indicated by MARK opcodes in the stream, are indented by indentlevel spaces. If a nonzero value is given to annotate , each opcode in the output is annotated with a short description. The value of annotate is used as a hint for the column where annotation should start. 3.2 版改变: 添加 annotate 参数。 pickletools. genops ( pickle ) ¶ 提供 iterator over all of the opcodes in a pickle, returning a sequence of (opcode, arg, pos) 3 元组。 opcode 是实例化的 OpcodeInfo 类; arg is the decoded value, as a Python object, of the opcode’s argument; pos is the position at which this opcode is located. pickle can be a string or a file-like object. pickletools. optimize ( picklestring ) ¶ Returns a new equivalent pickle string after eliminating unused PUT opcodes. The optimized pickle is shorter, takes less transmission time, requires less storage space, and unpickles more efficiently. 内容表 pickletools — 用于腌制开发者的工具 命令行用法 命令行选项 编程方式接口 上一话题 dis — Python 字节码的反汇编程序 下一话题 MS Windows 特定服务 本页 报告 Bug 展示源 快速搜索 键入搜索术语或模块、类、函数名称。 首页 Python 3.12.4 索引 模块 下一 上一 Python 标准库 Python 语言服务 pickletools — 用于腌制开发者的工具
源代码: Lib/pickletools.py
此模块包含的各种常量细节密切相关 pickle module, some lengthy comments about the implementation, and a few useful functions for analyzing pickled data. The contents of this module are useful for Python core developers who are working on the pickle ; ordinary users of the pickle module probably won’t find the pickletools module relevant.
pickle
Added in version 3.2.
当援引自命令行时, python -m pickletools will disassemble the contents of one or more pickle files. Note that if you want to see the Python object stored in the pickle rather than the details of pickle format, you may want to use -m pickle instead. However, when the pickle file that you want to examine comes from an untrusted source, -m pickletools is a safer option because it does not execute pickle bytecode.
python -m pickletools
-m pickle
-m pickletools
例如,采用元组 (1, 2) pickled in file x.pickle :
(1, 2)
x.pickle
$ python -m pickle x.pickle (1, 2) $ python -m pickletools x.pickle 0: \x80 PROTO 3 2: K BININT1 1 4: K BININT1 2 6: \x86 TUPLE2 7: q BINPUT 0 9: . STOP highest protocol among opcodes = 2
Annotate each line with a short opcode description.
Name of a file where the output should be written.
The number of blanks by which to indent a new MARK level.
When multiple objects are disassembled, preserve memo between disassemblies.
When more than one pickle file are specified, print given preamble before each disassembly.
Outputs a symbolic disassembly of the pickle to the file-like object out ,默认为 sys.stdout . pickle can be a string or a file-like object. memo can be a Python dictionary that will be used as the pickle’s memo; it can be used to perform disassemblies across multiple pickles created by the same pickler. Successive levels, indicated by MARK opcodes in the stream, are indented by indentlevel spaces. If a nonzero value is given to annotate , each opcode in the output is annotated with a short description. The value of annotate is used as a hint for the column where annotation should start.
sys.stdout
MARK
3.2 版改变: 添加 annotate 参数。
提供 iterator over all of the opcodes in a pickle, returning a sequence of (opcode, arg, pos) 3 元组。 opcode 是实例化的 OpcodeInfo 类; arg is the decoded value, as a Python object, of the opcode’s argument; pos is the position at which this opcode is located. pickle can be a string or a file-like object.
(opcode, arg, pos)
OpcodeInfo
Returns a new equivalent pickle string after eliminating unused PUT opcodes. The optimized pickle is shorter, takes less transmission time, requires less storage space, and unpickles more efficiently.
PUT
dis — Python 字节码的反汇编程序
dis
MS Windows 特定服务
键入搜索术语或模块、类、函数名称。