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

Function main

Lib/base64.py:583–614  ·  view source on GitHub ↗

Small main program

()

Source from the content-addressed store, hash-verified

581
582# Usable as a script...
583def main():
584 """Small main program"""
585 import sys, getopt
586 usage = f"""usage: {sys.argv[0]} [-h|-d|-e|-u] [file|-]
587 -h: print this help message and exit
588 -d, -u: decode
589 -e: encode (default)"""
590 try:
591 opts, args = getopt.getopt(sys.argv[1:], 'hdeu')
592 except getopt.error as msg:
593 sys.stdout = sys.stderr
594 print(msg)
595 print(usage)
596 sys.exit(2)
597 func = encode
598 for o, a in opts:
599 if o == '-e': func = encode
600 if o == '-d': func = decode
601 if o == '-u': func = decode
602 if o == '-h': print(usage); return
603 if args and args[0] != '-':
604 with open(args[0], 'rb') as f:
605 func(f, sys.stdout.buffer)
606 else:
607 if sys.stdin.isatty():
608 # gh-138775: read terminal input data all at once to detect EOF
609 import io
610 data = sys.stdin.buffer.read()
611 buffer = io.BytesIO(data)
612 else:
613 buffer = sys.stdin.buffer
614 func(buffer, sys.stdout.buffer)
615
616
617if __name__ == '__main__':

Callers 1

base64.pyFile · 0.70

Calls 6

openFunction · 0.70
printFunction · 0.50
funcFunction · 0.50
exitMethod · 0.45
isattyMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected