summaryrefslogtreecommitdiffstats
path: root/Lib/pickle.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2024-01-05 22:12:34 (GMT)
committerGitHub <noreply@github.com>2024-01-05 22:12:34 (GMT)
commitbd754b93ca837aa1f239252437a211271d068b71 (patch)
tree8c932d96f67820fcb53484bae7e293716fcbb6bc /Lib/pickle.py
parent3c4e972d6d0945a5401377bed25b307a88b19c75 (diff)
downloadcpython-bd754b93ca837aa1f239252437a211271d068b71.zip
cpython-bd754b93ca837aa1f239252437a211271d068b71.tar.gz
cpython-bd754b93ca837aa1f239252437a211271d068b71.tar.bz2
gh-85567: Fix resouce warnings in pickle and pickletools CLIs (GH-113618)
Explicitly open and close files instead of using FileType.
Diffstat (limited to 'Lib/pickle.py')
-rw-r--r--Lib/pickle.py10
1 files changed, 7 insertions, 3 deletions
diff --git a/Lib/pickle.py b/Lib/pickle.py
index 988c088..33c97c8 100644
--- a/Lib/pickle.py
+++ b/Lib/pickle.py
@@ -1793,7 +1793,7 @@ if __name__ == "__main__":
parser = argparse.ArgumentParser(
description='display contents of the pickle files')
parser.add_argument(
- 'pickle_file', type=argparse.FileType('br'),
+ 'pickle_file',
nargs='*', help='the pickle file')
parser.add_argument(
'-t', '--test', action='store_true',
@@ -1809,6 +1809,10 @@ if __name__ == "__main__":
parser.print_help()
else:
import pprint
- for f in args.pickle_file:
- obj = load(f)
+ for fn in args.pickle_file:
+ if fn == '-':
+ obj = load(sys.stdin.buffer)
+ else:
+ with open(fn, 'rb') as f:
+ obj = load(f)
pprint.pprint(obj)