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

Function main

Lib/base64.py:437–468  ·  view source on GitHub ↗

Small main program

()

Source from the content-addressed store, hash-verified

435
436# Usable as a script...
437def main():
438 """Small main program"""
439 import sys, getopt
440 usage = f"""usage: {sys.argv[0]} [-h|-d|-e|-u] [file|-]
441 -h: print this help message and exit
442 -d, -u: decode
443 -e: encode (default)"""
444 try:
445 opts, args = getopt.getopt(sys.argv[1:], 'hdeu')
446 except getopt.error as msg:
447 sys.stdout = sys.stderr
448 print(msg)
449 print(usage)
450 sys.exit(2)
451 func = encode
452 for o, a in opts:
453 if o == '-e': func = encode
454 if o == '-d': func = decode
455 if o == '-u': func = decode
456 if o == '-h': print(usage); return
457 if args and args[0] != '-':
458 with open(args[0], 'rb') as f:
459 func(f, sys.stdout.buffer)
460 else:
461 if sys.stdin.isatty():
462 # gh-138775: read terminal input data all at once to detect EOF
463 import io
464 data = sys.stdin.buffer.read()
465 buffer = io.BytesIO(data)
466 else:
467 buffer = sys.stdin.buffer
468 func(buffer, sys.stdout.buffer)
469
470
471if __name__ == '__main__':

Callers 1

base64.pyFile · 0.70

Calls 5

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

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…