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

Method _process_short_opts

Lib/optparse.py:1493–1529  ·  view source on GitHub ↗
(self, rargs, values)

Source from the content-addressed store, hash-verified

1491 option.process(opt, value, values, self)
1492
1493 def _process_short_opts(self, rargs, values):
1494 arg = rargs.pop(0)
1495 stop = False
1496 i = 1
1497 for ch in arg[1:]:
1498 opt = "-" + ch
1499 option = self._short_opt.get(opt)
1500 i += 1 # we have consumed a character
1501
1502 if not option:
1503 raise BadOptionError(opt)
1504 if option.takes_value():
1505 # Any characters left in arg? Pretend they're the
1506 # next arg, and stop consuming characters of arg.
1507 if i < len(arg):
1508 rargs.insert(0, arg[i:])
1509 stop = True
1510
1511 nargs = option.nargs
1512 if len(rargs) < nargs:
1513 self.error(ngettext(
1514 "%(option)s option requires %(number)d argument",
1515 "%(option)s option requires %(number)d arguments",
1516 nargs) % {"option": opt, "number": nargs})
1517 elif nargs == 1:
1518 value = rargs.pop(0)
1519 else:
1520 value = tuple(rargs[0:nargs])
1521 del rargs[0:nargs]
1522
1523 else: # option doesn't take a value
1524 value = None
1525
1526 option.process(opt, value, values, self)
1527
1528 if stop:
1529 break
1530
1531
1532 # -- Feedback methods ----------------------------------------------

Callers 1

_process_argsMethod · 0.95

Calls 8

errorMethod · 0.95
ngettextFunction · 0.90
BadOptionErrorClass · 0.85
takes_valueMethod · 0.80
popMethod · 0.45
getMethod · 0.45
insertMethod · 0.45
processMethod · 0.45

Tested by

no test coverage detected