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

Method _get_nargs_pattern

Lib/argparse.py:2601–2641  ·  view source on GitHub ↗
(self, action)

Source from the content-addressed store, hash-verified

2599 return result
2600
2601 def _get_nargs_pattern(self, action):
2602 # in all examples below, we have to allow for '--' args
2603 # which are represented as '-' in the pattern
2604 nargs = action.nargs
2605 # if this is an optional action, -- is not allowed
2606 option = action.option_strings
2607
2608 # the default (None) is assumed to be a single argument
2609 if nargs is None:
2610 nargs_pattern = '([A])' if option else '(-*A-*)'
2611
2612 # allow zero or one arguments
2613 elif nargs == OPTIONAL:
2614 nargs_pattern = '(A?)' if option else '(-*A?-*)'
2615
2616 # allow zero or more arguments
2617 elif nargs == ZERO_OR_MORE:
2618 nargs_pattern = '(A*)' if option else '(-*[A-]*)'
2619
2620 # allow one or more arguments
2621 elif nargs == ONE_OR_MORE:
2622 nargs_pattern = '(A+)' if option else '(-*A[A-]*)'
2623
2624 # allow any number of options or arguments
2625 elif nargs == REMAINDER:
2626 nargs_pattern = '(.*)'
2627
2628 # allow one argument followed by any number of options or arguments
2629 elif nargs == PARSER:
2630 nargs_pattern = '(A[AO]*)' if option else '(-*A[-AO]*)'
2631
2632 # suppress action, like nargs=0
2633 elif nargs == SUPPRESS:
2634 nargs_pattern = '()' if option else '(-*)'
2635
2636 # all others should be integers
2637 else:
2638 nargs_pattern = '([AO]{%d})' % nargs if option else '((?:-*A){%d}-*)' % nargs
2639
2640 # return the pattern
2641 return nargs_pattern
2642
2643 # ========================
2644 # Alt command line argument parsing, allowing free intermix

Callers 2

_match_argumentMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected