MCPcopy Index your code
hub / github.com/RustPython/RustPython / main

Function main

Lib/gzip.py:666–714  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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