MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / parseargs

Function parseargs

tools/python-3.11.9-amd64/Lib/smtpd.py:790–853  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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

Callers 1

smtpd.pyFile · 0.85

Calls 7

usageFunction · 0.70
OptionsClass · 0.70
printFunction · 0.50
getoptMethod · 0.45
exitMethod · 0.45
joinMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected