Skip to content

Commit 8de9742

Browse files
committed
Update and document pickletools CLI
1 parent 55815a6 commit 8de9742

File tree

2 files changed

+24
-23
lines changed

2 files changed

+24
-23
lines changed

Doc/library/pickletools.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ Command line options
7575
When more than one pickle file are specified, print given preamble
7676
before each disassembly.
7777

78+
.. option:: pickle_file
79+
80+
A pickle file to read, or ``-`` to indicate reading from standard input.
81+
7882

7983

8084
Programmatic Interface

Lib/pickletools.py

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2845,7 +2845,7 @@ def __init__(self, value):
28452845
description='disassemble one or more pickle files')
28462846
parser.add_argument(
28472847
'pickle_file',
2848-
nargs='*', help='the pickle file')
2848+
nargs='+', help='the pickle file')
28492849
parser.add_argument(
28502850
'-o', '--output',
28512851
help='the file where the output should be written')
@@ -2863,26 +2863,23 @@ def __init__(self, value):
28632863
help='if more than one pickle file is specified, print this before'
28642864
' each disassembly')
28652865
args = parser.parse_args()
2866-
if not args.pickle_file:
2867-
parser.print_help()
2866+
annotate = 30 if args.annotate else 0
2867+
memo = {} if args.memo else None
2868+
if args.output is None:
2869+
output = sys.stdout
28682870
else:
2869-
annotate = 30 if args.annotate else 0
2870-
memo = {} if args.memo else None
2871-
if args.output is None:
2872-
output = sys.stdout
2873-
else:
2874-
output = open(args.output, 'w')
2875-
try:
2876-
for arg in args.pickle_file:
2877-
if len(args.pickle_file) > 1:
2878-
name = '<stdin>' if arg == '-' else arg
2879-
preamble = args.preamble.format(name=name)
2880-
output.write(preamble + '\n')
2881-
if arg == '-':
2882-
dis(sys.stdin.buffer, output, memo, args.indentlevel, annotate)
2883-
else:
2884-
with open(arg, 'rb') as f:
2885-
dis(f, output, memo, args.indentlevel, annotate)
2886-
finally:
2887-
if output is not sys.stdout:
2888-
output.close()
2871+
output = open(args.output, 'w')
2872+
try:
2873+
for arg in args.pickle_file:
2874+
if len(args.pickle_file) > 1:
2875+
name = '<stdin>' if arg == '-' else arg
2876+
preamble = args.preamble.format(name=name)
2877+
output.write(preamble + '\n')
2878+
if arg == '-':
2879+
dis(sys.stdin.buffer, output, memo, args.indentlevel, annotate)
2880+
else:
2881+
with open(arg, 'rb') as f:
2882+
dis(f, output, memo, args.indentlevel, annotate)
2883+
finally:
2884+
if output is not sys.stdout:
2885+
output.close()

0 commit comments

Comments
 (0)