Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions Lib/gzip.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,18 +532,17 @@ def decompress(data):
return f.read()


def _test():
# Act like gzip; with -d, act like gunzip.
# The input file is not deleted, however, nor are any other gzip
# options or features supported.
args = sys.argv[1:]
decompress = args and args[0] == "-d"
if decompress:
args = args[1:]
if not args:
args = ["-"]
for arg in args:
if decompress:
def main():
from argparse import ArgumentParser
parser = ArgumentParser(description=
"A simple command line interface for the gzip module: act like gzip, "
"but do not delete the input file.")
parser.add_argument("-d", "--decompress", action="store_true",
help="act like gunzip instead of gzip")
parser.add_argument("args", nargs="*", default=["-"])
args = parser.parse_args()
for arg in args.args:
if args.decompress:
if arg == "-":
f = GzipFile(filename="", mode="rb", fileobj=sys.stdin.buffer)
g = sys.stdout.buffer
Expand Down Expand Up @@ -571,4 +570,4 @@ def _test():
f.close()

if __name__ == '__main__':
_test()
main()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use argparse for the command line of the gzip module. Patch by Antony Lee