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

Function parseargs

Lib/test/support/smtpd.py:780–843  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

778
779
780def parseargs():
781 global DEBUGSTREAM
782 try:
783 opts, args = getopt.getopt(
784 sys.argv[1:], 'nVhc:s:du',
785 ['class=', 'nosetuid', 'version', 'help', 'size=', 'debug',
786 'smtputf8'])
787 except getopt.error as e:
788 usage(1, e)
789
790 options = Options()
791 for opt, arg in opts:
792 if opt in ('-h', '--help'):
793 usage(0)
794 elif opt in ('-V', '--version'):
795 print(__version__)
796 sys.exit(0)
797 elif opt in ('-n', '--nosetuid'):
798 options.setuid = False
799 elif opt in ('-c', '--class'):
800 options.classname = arg
801 elif opt in ('-d', '--debug'):
802 DEBUGSTREAM = sys.stderr
803 elif opt in ('-u', '--smtputf8'):
804 options.enable_SMTPUTF8 = True
805 elif opt in ('-s', '--size'):
806 try:
807 int_size = int(arg)
808 options.size_limit = int_size
809 except:
810 print('Invalid size: ' + arg, file=sys.stderr)
811 sys.exit(1)
812
813 # parse the rest of the arguments
814 if len(args) < 1:
815 localspec = 'localhost:8025'
816 remotespec = 'localhost:25'
817 elif len(args) < 2:
818 localspec = args[0]
819 remotespec = 'localhost:25'
820 elif len(args) < 3:
821 localspec = args[0]
822 remotespec = args[1]
823 else:
824 usage(1, 'Invalid arguments: %s' % COMMASPACE.join(args))
825
826 # split into host/port pairs
827 i = localspec.find(':')
828 if i < 0:
829 usage(1, 'Bad local spec: %s' % localspec)
830 options.localhost = localspec[:i]
831 try:
832 options.localport = int(localspec[i+1:])
833 except ValueError:
834 usage(1, 'Bad local port: %s' % localspec)
835 i = remotespec.find(':')
836 if i < 0:
837 usage(1, 'Bad remote spec: %s' % remotespec)

Callers 1

smtpd.pyFile · 0.85

Calls 7

usageFunction · 0.85
lenFunction · 0.85
OptionsClass · 0.70
printFunction · 0.50
exitMethod · 0.45
joinMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected