MCPcopy Index your code
hub / github.com/python/cpython / main

Function main

Lib/gzip.py:664–712  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

662
663
664def main():
665 from argparse import ArgumentParser
666 parser = ArgumentParser(description=
667 "A simple command line interface for the gzip module: act like gzip, "
668 "but do not delete the input file.",
669 color=True,
670 )
671 group = parser.add_mutually_exclusive_group()
672 group.add_argument('--fast', action='store_true', help='compress faster')
673 group.add_argument('--best', action='store_true', help='compress better')
674 group.add_argument("-d", "--decompress", action="store_true",
675 help="act like gunzip instead of gzip")
676
677 parser.add_argument("args", nargs="*", default=["-"], metavar='file')
678 args = parser.parse_args()
679
680 compresslevel = _COMPRESS_LEVEL_TRADEOFF
681 if args.fast:
682 compresslevel = _COMPRESS_LEVEL_FAST
683 elif args.best:
684 compresslevel = _COMPRESS_LEVEL_BEST
685
686 for arg in args.args:
687 if args.decompress:
688 if arg == "-":
689 f = GzipFile(filename="", mode="rb", fileobj=sys.stdin.buffer)
690 g = sys.stdout.buffer
691 else:
692 if arg[-3:] != ".gz":
693 sys.exit(f"filename doesn't end in .gz: {arg!r}")
694 f = open(arg, "rb")
695 g = builtins.open(arg[:-3], "wb")
696 else:
697 if arg == "-":
698 f = sys.stdin.buffer
699 g = GzipFile(filename="", mode="wb", fileobj=sys.stdout.buffer,
700 compresslevel=compresslevel)
701 else:
702 f = builtins.open(arg, "rb")
703 g = open(arg + ".gz", "wb")
704 while True:
705 chunk = f.read(READ_BUFFER_SIZE)
706 if not chunk:
707 break
708 g.write(chunk)
709 if g is not sys.stdout.buffer:
710 g.close()
711 if f is not sys.stdin.buffer:
712 f.close()
713
714if __name__ == '__main__':
715 main()

Callers 1

gzip.pyFile · 0.70

Calls 11

parse_argsMethod · 0.95
readMethod · 0.95
writeMethod · 0.95
closeMethod · 0.95
ArgumentParserClass · 0.90
GzipFileClass · 0.85
openFunction · 0.70
add_argumentMethod · 0.45
exitMethod · 0.45
openMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…