Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

gh-93096: Update and document pickletools CLI #131273

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions 12 Doc/library/pickletools.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ ordinary users of the :mod:`pickle` module probably won't find the

.. _pickletools-cli:

Command line usage
Command-line usage
------------------

.. versionadded:: 3.2
Expand Down Expand Up @@ -48,7 +48,7 @@ For example, with a tuple ``(1, 2)`` pickled in file ``x.pickle``:
9: . STOP
highest protocol among opcodes = 2

Command line options
Command-line options
^^^^^^^^^^^^^^^^^^^^

.. program:: pickletools
Expand All @@ -72,12 +72,16 @@ Command line options

.. option:: -p, --preamble=<preamble>

When more than one pickle file are specified, print given preamble
When more than one pickle file is specified, print given preamble
before each disassembly.

.. option:: pickle_file

A pickle file to read, or ``-`` to indicate reading from standard input.

Programmatic Interface


Programmatic interface
----------------------


Expand Down
43 changes: 20 additions & 23 deletions 43 Lib/pickletools.py
Original file line number Diff line number Diff line change
Expand Up @@ -2845,7 +2845,7 @@ def __init__(self, value):
description='disassemble one or more pickle files')
parser.add_argument(
'pickle_file',
nargs='*', help='the pickle file')
nargs='+', help='the pickle file')
parser.add_argument(
'-o', '--output',
help='the file where the output should be written')
Expand All @@ -2863,26 +2863,23 @@ def __init__(self, value):
help='if more than one pickle file is specified, print this before'
' each disassembly')
args = parser.parse_args()
if not args.pickle_file:
parser.print_help()
annotate = 30 if args.annotate else 0
memo = {} if args.memo else None
if args.output is None:
output = sys.stdout
else:
annotate = 30 if args.annotate else 0
memo = {} if args.memo else None
if args.output is None:
output = sys.stdout
else:
output = open(args.output, 'w')
try:
for arg in args.pickle_file:
if len(args.pickle_file) > 1:
name = '<stdin>' if arg == '-' else arg
preamble = args.preamble.format(name=name)
output.write(preamble + '\n')
if arg == '-':
dis(sys.stdin.buffer, output, memo, args.indentlevel, annotate)
else:
with open(arg, 'rb') as f:
dis(f, output, memo, args.indentlevel, annotate)
finally:
if output is not sys.stdout:
output.close()
output = open(args.output, 'w')
try:
for arg in args.pickle_file:
if len(args.pickle_file) > 1:
name = '<stdin>' if arg == '-' else arg
preamble = args.preamble.format(name=name)
output.write(preamble + '\n')
if arg == '-':
dis(sys.stdin.buffer, output, memo, args.indentlevel, annotate)
else:
with open(arg, 'rb') as f:
dis(f, output, memo, args.indentlevel, annotate)
finally:
if output is not sys.stdout:
output.close()
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.