From d0f680b37995fac942dd00087fc2e19a50ad0e48 Mon Sep 17 00:00:00 2001 From: CPython Developers <> Date: Tue, 23 Apr 2024 18:04:46 +0900 Subject: [PATCH] Update pickletools from CPython 3.12.3 --- Lib/pickletools.py | 33 ++++++++++++++++++++++----------- Lib/test/test_pickletools.py | 2 -- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/Lib/pickletools.py b/Lib/pickletools.py index 95706e746..51ee4a7a2 100644 --- a/Lib/pickletools.py +++ b/Lib/pickletools.py @@ -1253,7 +1253,7 @@ opcodes = [ stack_before=[], stack_after=[pyint], proto=2, - doc="""Long integer using found-byte length. + doc="""Long integer using four-byte length. A more efficient encoding of a Python long; the long4 encoding says it all."""), @@ -2848,10 +2848,10 @@ if __name__ == "__main__": parser = argparse.ArgumentParser( description='disassemble one or more pickle files') parser.add_argument( - 'pickle_file', type=argparse.FileType('br'), + 'pickle_file', nargs='*', help='the pickle file') parser.add_argument( - '-o', '--output', default=sys.stdout, type=argparse.FileType('w'), + '-o', '--output', help='the file where the output should be written') parser.add_argument( '-m', '--memo', action='store_true', @@ -2876,15 +2876,26 @@ if __name__ == "__main__": if args.test: _test() else: - annotate = 30 if args.annotate else 0 if not args.pickle_file: parser.print_help() - elif len(args.pickle_file) == 1: - dis(args.pickle_file[0], args.output, None, - args.indentlevel, annotate) else: + annotate = 30 if args.annotate else 0 memo = {} if args.memo else None - for f in args.pickle_file: - preamble = args.preamble.format(name=f.name) - args.output.write(preamble + '\n') - dis(f, args.output, memo, args.indentlevel, annotate) + 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 = '' 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() diff --git a/Lib/test/test_pickletools.py b/Lib/test/test_pickletools.py index 7dde4b17e..f3b9dccb0 100644 --- a/Lib/test/test_pickletools.py +++ b/Lib/test/test_pickletools.py @@ -65,8 +65,6 @@ class OptimizedPickleTests(AbstractPickleTests, unittest.TestCase): # Test relies on writing by chunks into a file object. test_framed_write_sizes_with_delayed_writer = None - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_optimize_long_binget(self): data = [str(i) for i in range(257)] data.append(data[-1])