Viewing File: /opt/alt/python35/lib64/python3.5/__pycache__/argparse.cpython-35.opt-1.pyc



Yf`@sdZdZdddddddd	d
ddd
dddddgZddlZddlZddlZddl	Z
ddlZddl
ZddlmZmZdZdZdZdZdZdZdZGdddeZdd ZGd!ddeZGd"ddeZGd#d	d	eZGd$ddeZGd%d
d
eZ d&d'Z!Gd(dde"Z#Gd)dde"Z$Gd*ddeZ%Gd+d,d,e%Z&Gd-d.d.e%Z'Gd/d0d0e'Z(Gd1d2d2e'Z)Gd3d4d4e%Z*Gd5d6d6e%Z+Gd7d8d8e%Z,Gd9d:d:e%Z-Gd;d<d<e%Z.Gd=d>d>e%Z/Gd?ddeZ0Gd@ddeZ1GdAdBdBeZ2GdCdDdDe2Z3GdEdFdFe3Z4GdGddee2Z5dS)Ha
Command-line parsing library

This module is an optparse-inspired command-line parsing library that:

    - handles both optional and positional arguments
    - produces highly informative usage messages
    - supports parsers that dispatch to sub-parsers

The following is a simple usage example that sums integers from the
command-line and writes the result to a file::

    parser = argparse.ArgumentParser(
        description='sum the integers at the command line')
    parser.add_argument(
        'integers', metavar='int', nargs='+', type=int,
        help='an integer to be summed')
    parser.add_argument(
        '--log', default=sys.stdout, type=argparse.FileType('w'),
        help='the file where the sum should be written')
    args = parser.parse_args()
    args.log.write('%s' % sum(args.integers))
    args.log.close()

The module contains the following public classes:

    - ArgumentParser -- The main entry point for command-line parsing. As the
        example above shows, the add_argument() method is used to populate
        the parser with actions for optional and positional arguments. Then
        the parse_args() method is invoked to convert the args at the
        command-line into an object with attributes.

    - ArgumentError -- The exception raised by ArgumentParser objects when
        there are errors with the parser's actions. Errors raised while
        parsing the command-line are caught by ArgumentParser and emitted
        as command-line messages.

    - FileType -- A factory for defining types of files to be created. As the
        example above shows, instances of FileType are typically passed as
        the type= argument of add_argument() calls.

    - Action -- The base class for parser actions. Typically actions are
        selected by passing strings like 'store_true' or 'append_const' to
        the action= argument of add_argument(). However, for greater
        customization of ArgumentParser actions, subclasses of Action may
        be defined and passed as the action= argument.

    - HelpFormatter, RawDescriptionHelpFormatter, RawTextHelpFormatter,
        ArgumentDefaultsHelpFormatter -- Formatter classes which
        may be passed as the formatter_class= argument to the
        ArgumentParser constructor. HelpFormatter is the default,
        RawDescriptionHelpFormatter and RawTextHelpFormatter tell the parser
        not to change the formatting for help text, and
        ArgumentDefaultsHelpFormatter adds information about argument defaults
        to the help.

All other classes in this module are considered implementation details.
(Also note that HelpFormatter and RawDescriptionHelpFormatter are only
considered public as object names -- the API of the formatter objects is
still considered an implementation detail.)
z1.1ArgumentParser
ArgumentErrorArgumentTypeErrorFileType
HelpFormatterArgumentDefaultsHelpFormatterRawDescriptionHelpFormatterRawTextHelpFormatterMetavarTypeHelpFormatter	NamespaceActionONE_OR_MOREOPTIONALPARSER	REMAINDERSUPPRESSZERO_OR_MOREN)gettextngettextz==SUPPRESS==?*+zA...z...Z_unrecognized_argsc@s:eZdZdZddZddZddZdS)	_AttributeHolderaAbstract base class that provides __repr__.

    The __repr__ method returns a string in the format::
        ClassName(attr=name, attr=name, ...)
    The attributes are determined either by a class-level attribute,
    '_kwarg_names', or by inspecting the instance __dict__.
    cCst|j}g}x'|jD]}|jt|q"Wx1|jD]#\}}|jd||fqLWd|dj|fS)Nz%s=%rz%s(%s)z, )type__name__	_get_argsappendrepr_get_kwargsjoin)selfZ	type_namearg_stringsargnamevaluer%-/opt/alt/python35/lib64/python3.5/argparse.py__repr__vsz_AttributeHolder.__repr__cCst|jjS)N)sorted__dict__items)r r%r%r&rsz_AttributeHolder._get_kwargscCsgS)Nr%)r r%r%r&rsz_AttributeHolder._get_argsN)r
__module____qualname____doc__r'rrr%r%r%r&rms	rcCs5t||ddkr(t|||t||S)N)getattrsetattr)	namespacer#r$r%r%r&
_ensure_valuesr1c@speZdZdZdddddZddZd	d
ZGdddeZd
dZ	ddZ
ddZddZdddZ
ddZddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,Zd-d.Zd/d0Zd1d2Zd3d4Zd5d6Zd7d8Zd9d:ZdS);rzFormatter for generating usage messages and argument help strings.

    Only the name of this class is considered a public API. All the methods
    provided by the class are considered an implementation detail.
    NcCs|dkrNyttjd}Wnttfk
rCd}YnX|d8}||_||_||_t|t	|d|d|_||_
d|_d|_d|_
|j|d|_|j|_tjdtj|_tjd|_dS)NZCOLUMNSPr2rz\s+z\n\n\n+)int_osenvironKeyError
ValueError_prog_indent_increment_max_help_positionminmax_width_current_indent_level_action_max_length_Section
_root_section_current_section_recompileASCII_whitespace_matcher_long_break_matcher)r progZindent_incrementZmax_help_positionwidthr%r%r&__init__s&
							zHelpFormatter.__init__cCs%|j|j7_|jd7_dS)N)rAr<rB)r r%r%r&_indentszHelpFormatter._indentcCs%|j|j8_|jd8_dS)NrO)rAr<rB)r r%r%r&_dedentszHelpFormatter._dedentc@s+eZdZdddZddZdS)zHelpFormatter._SectionNcCs(||_||_||_g|_dS)N)	formatterparentheadingr*)r rRrSrTr%r%r&rNs			zHelpFormatter._Section.__init__cCs|jdk	r|jj|jj}x!|jD]\}}||q2W|dd|jD}|jdk	r|jj|sdS|jtk	r|jdk	r|jj}d|d|jf}nd}|d||dgS)NcSs"g|]\}}||qSr%r%).0funcargsr%r%r&
<listcomp>s	z6HelpFormatter._Section.format_help.<locals>.<listcomp>z%*s%s:

)	rSrRrP_join_partsr*rQrTrrA)r rrVrWZ	item_helpZcurrent_indentrTr%r%r&format_helps

z"HelpFormatter._Section.format_help)rr+r,rNr\r%r%r%r&rDsrDcCs|jjj||fdS)N)rFr*r)r rVrWr%r%r&	_add_itemszHelpFormatter._add_itemcCsB|j|j||j|}|j|jg||_dS)N)rPrDrFr]r\)r rTZsectionr%r%r&
start_sections
zHelpFormatter.start_sectioncCs|jj|_|jdS)N)rFrSrQ)r r%r%r&end_sectionszHelpFormatter.end_sectioncCs2|tk	r.|dk	r.|j|j|gdS)N)rr]_format_text)r textr%r%r&add_textszHelpFormatter.add_textcCs5|tk	r1||||f}|j|j|dS)N)rr]
_format_usage)r usageactionsgroupsprefixrWr%r%r&	add_usageszHelpFormatter.add_usagecCs|jtk	r|j}||g}x*|j|D]}|j||q7Wtdd|D}||j}t|j||_|j|j	|gdS)NcSsg|]}t|qSr%)len)rUsr%r%r&rXs	z.HelpFormatter.add_argument.<locals>.<listcomp>)
helpr_format_action_invocation_iter_indented_subactionsrr?rArCr]_format_action)r actionZget_invocationZinvocations	subactionZinvocation_lengthZ
action_lengthr%r%r&add_arguments	
	zHelpFormatter.add_argumentcCs"x|D]}|j|qWdS)N)rq)r reror%r%r&
add_argumentss
zHelpFormatter.add_argumentscCsA|jj}|r=|jjd|}|jdd}|S)Nz

rZ)rEr\rKsubstrip)r rkr%r%r&r\s
zHelpFormatter.format_helpcCsdjdd|DS)NrYcSs(g|]}|r|tk	r|qSr%)r)rUpartr%r%r&rXs	z-HelpFormatter._join_parts.<locals>.<listcomp>)r)r Zpart_stringsr%r%r&r[szHelpFormatter._join_partscs|dkrtd}|dk	r=|td|j}n|dkri|ridtd|j}nY|dkrdtd|j}g}g}x4|D],}|jr|j|q|j|qW|j}	|	|||}
djdd||
gD}|j|jt	|t	|krd}|	||}|	||}
t
j||}t
j||
}dfdd	}t	|t	|d
kr9dt	|t	|d}|r||g|||}|j|||q|r-||g|||}q|g}nzdt	|}||}|||}t	|dkrg}|j||||j||||g|}dj|}d
||fS)Nzusage: rLz%(prog)s cSsg|]}|r|qSr%r%)rUrjr%r%r&rX=s	z/HelpFormatter._format_usage.<locals>.<listcomp>z\(.*?\)+|\[.*?\]+|\S+csg}g}|dk	r+t|d}nt|d}x|D]w}|dt|kr|r|j|dj|g}t|d}|j||t|d7}qBW|r|j|dj||dk	r|dt|d|d<|S)NrOrvr)rirr)partsindentrglineslineZline_lenru)
text_widthr%r&	get_linesMs"
 
z.HelpFormatter._format_usage.<locals>.get_linesg?rOrZz%s%s

)
_dictr;option_stringsr_format_actions_usagerr@rArirGfindallextend)r rdrerfrgrLZ	optionalspositionalsroformatZaction_usageZpart_regexpZ	opt_usageZ	pos_usageZ	opt_partsZ	pos_partsr|rxryrwr%)r{r&rc!sV
		" 

zHelpFormatter._format_usagec
Cst}i}x#|D]}y|j|jd}Wntk
rMwYqX|t|j}||||jkrx|jD]}|j|qW|js||kr||d7<n
d||<d||<n1||kr||d7<n
d||<d||<x%t|d|D]}	d	||	<qWqWg}
xt|D]w\}	}|j	t
kr|
jd|j|	d	kr|j
|	q|j|	dd	kr|j
|	dqH|js8|j|}|j||}||kr(|ddkr(|ddkr(|dd}|
j|qH|jd}
|jdkrad
|
}n1|j|}|j||}d|
|f}|jr||krd|}|
j|qHWx1t|d
dD]}	||	g|
|	|	<qWdjdd|
D}d}d}tjd|d|}tjd|d|}tjd||fd|}tjdd|}|j}|S)Nrz [[]z (()rO|z%sz%s %sz[%s]reverseTrvcSs"g|]}|dk	r|qS)Nr%)rUitemr%r%r&rXs	z7HelpFormatter._format_actions_usage.<locals>.<listcomp>z[\[(]z[\])]z(%s) z\1z (%s)z%s *%srYz\(([^|]*)\)r)setindex_group_actionsr:riaddrequiredrange	enumeraterkrrgetpopr#_get_default_metavar_for_positional_format_argsnargs!_get_default_metavar_for_optionalr(rrGrsrt)r rerf
group_actionsZinsertsgroupstartendroirwdefaultru
option_stringargs_stringraopencloser%r%r&r}sr	

	




	 


z#HelpFormatter._format_actions_usagecCs_d|kr"|td|j}t|j|jd}d|j}|j|||dS)Nz%(prog)rLrvz

)r~r;r?r@rA
_fill_text)r rar{rxr%r%r&r`s

zHelpFormatter._format_textc
Cst|jd|j}t|j|d}||jd}|j|}|jsw|jd|f}d|}n\t||kr|jd||f}d|}d}n"|jd|f}d|}|}|g}|jr\|j	|}	|j
|	|}
|jd|d|
dfxQ|
ddD] }|jd|d|fq5Wn|jdsx|jdx-|j
|D]}|j|j|qW|j|S)	Nr2rrYz%*s%s
z	%*s%-*s  rrOrZ)r>rCr=r?r@rArlrkri_expand_help_split_linesrendswithrmrnr[)
r roZ
help_positionZ
help_widthZaction_widthZ
action_headertupZindent_firstrwZ	help_textZ
help_linesrzrpr%r%r&rns6
	

	
		!
zHelpFormatter._format_actioncCs|js7|j|}|j||d\}|Sg}|jdkr_|j|jnL|j|}|j||}x(|jD]}|jd||fqWdj|SdS)NrOrz%s %sz, )	rr_metavar_formatterrrrrrr)r rormetavarrwrrr%r%r&rls	z'HelpFormatter._format_action_invocationcsr|jdk	r|jnA|jdk	rVdd|jD}ddj|n|fdd}|S)NcSsg|]}t|qSr%)str)rUZchoicer%r%r&rX0s	z4HelpFormatter._metavar_formatter.<locals>.<listcomp>z{%s},cs"ttrSf|SdS)N)
isinstancetuple)Z
tuple_size)resultr%r&r5sz0HelpFormatter._metavar_formatter.<locals>.format)rchoicesr)r rodefault_metavarZchoice_strsrr%)rr&r,sz HelpFormatter._metavar_formattercCs|j||}|jdkr4d|d}n|jtkrVd|d}n|jtkrxd|d}n|jtkrd|d}nr|jtkrd}nZ|jtkrd|d}n8d	d
t|jD}dj|||j}|S)Nz%srOz[%s]z
[%s [%s ...]]r2z%s [%s ...]z...z%s ...cSsg|]}dqS)z%sr%)rUr}r%r%r&rXKs	z.HelpFormatter._format_args.<locals>.<listcomp>rv)	rrr
rrrrrr)r rorZget_metavarrZformatsr%r%r&r<s 	zHelpFormatter._format_argscCstt|d|j}x+t|D]}||tkr(||=q(Wx8t|D]*}t||drV||j||<qVW|jddk	rdjdd|dD}||d<|j	||S)NrLrrz, cSsg|]}t|qSr%)r)rUcr%r%r&rXXs	z.HelpFormatter._expand_help.<locals>.<listcomp>)
r~varsr;listrhasattrrrr_get_help_string)r roZparamsr#Zchoices_strr%r%r&rOs 
zHelpFormatter._expand_helpccsFy
|j}Wntk
r!Yn!X|j|EdH|jdS)N)_get_subactionsAttributeErrorrPrQ)r roZget_subactionsr%r%r&rm\s


z'HelpFormatter._iter_indented_subactionscCs+|jjd|j}tj||S)Nrv)rJrsrt	_textwrapZwrap)r rarMr%r%r&rfszHelpFormatter._split_linescCs7|jjd|j}tj||d|d|S)NrvZinitial_indentZsubsequent_indent)rJrsrtrZfill)r rarMrxr%r%r&rjszHelpFormatter._fill_textcCs|jS)N)rk)r ror%r%r&roszHelpFormatter._get_help_stringcCs
|jjS)N)destupper)r ror%r%r&rrsz/HelpFormatter._get_default_metavar_for_optionalcCs|jS)N)r)r ror%r%r&rusz1HelpFormatter._get_default_metavar_for_positional) rr+r,r-rNrPrQobjectrDr]r^r_rbrhrqrrr\r[rcrr`rnrlrrrrmrrrrrr%r%r%r&rs<!\a/

c@s"eZdZdZddZdS)rzHelp message formatter which retains any formatting in descriptions.

    Only the name of this class is considered a public API. All the methods
    provided by the class are considered an implementation detail.
    cs,djfdd|jddDS)NrYc3s|]}|VqdS)Nr%)rUrz)rxr%r&	<genexpr>sz9RawDescriptionHelpFormatter._fill_text.<locals>.<genexpr>keependsT)r
splitlines)r rarMrxr%)rxr&rsz&RawDescriptionHelpFormatter._fill_textN)rr+r,r-rr%r%r%r&rysc@s"eZdZdZddZdS)rzHelp message formatter which retains formatting of all help text.

    Only the name of this class is considered a public API. All the methods
    provided by the class are considered an implementation detail.
    cCs
|jS)N)r)r rarMr%r%r&rsz!RawTextHelpFormatter._split_linesN)rr+r,r-rr%r%r%r&rsc@s"eZdZdZddZdS)rzHelp message formatter which adds default values to argument help.

    Only the name of this class is considered a public API. All the methods
    provided by the class are considered an implementation detail.
    cCsY|j}d|jkrU|jtk	rUttg}|jsK|j|krU|d7}|S)Nz
%(default)z (default: %(default)s))rkrrr
rrr)r rorkZdefaulting_nargsr%r%r&rs	
z.ArgumentDefaultsHelpFormatter._get_help_stringN)rr+r,r-rr%r%r%r&rsc@s.eZdZdZddZddZdS)r	aHelp message formatter which uses the argument 'type' as the default
    metavar value (instead of the argument 'dest')

    Only the name of this class is considered a public API. All the methods
    provided by the class are considered an implementation detail.
    cCs
|jjS)N)rr)r ror%r%r&rsz:MetavarTypeHelpFormatter._get_default_metavar_for_optionalcCs
|jjS)N)rr)r ror%r%r&rsz<MetavarTypeHelpFormatter._get_default_metavar_for_positionalN)rr+r,r-rrr%r%r%r&r	scCsi|dkrdS|jr)dj|jS|jdtfkrE|jS|jdtfkra|jSdSdS)N/)rrrrr)argumentr%r%r&_get_action_names	rc@s.eZdZdZddZddZdS)rzAn error from creating or using an argument (optional or positional).

    The string value of this exception is the message, augmented with
    information about the argument that caused it.
    cCst||_||_dS)N)r
argument_namemessage)r rrr%r%r&rNszArgumentError.__init__cCs;|jdkrd}nd}|td|jd|jS)Nz%(message)sz'argument %(argument_name)s: %(message)srr)rr~r)r rr%r%r&__str__s
	zArgumentError.__str__N)rr+r,r-rNrr%r%r%r&rsc@seZdZdZdS)rz@An error from trying to convert a command line string to a type.N)rr+r,r-r%r%r%r&rsc
@sUeZdZdZddddddddddZddZddd	ZdS)
ra\	Information about how to convert command line strings to Python objects.

    Action objects are used by an ArgumentParser to represent the information
    needed to parse a single argument from one or more strings from the
    command line. The keyword arguments to the Action constructor are also
    all attributes of Action instances.

    Keyword Arguments:

        - option_strings -- A list of command-line option strings which
            should be associated with this action.

        - dest -- The name of the attribute to hold the created object(s)

        - nargs -- The number of command-line arguments that should be
            consumed. By default, one argument will be consumed and a single
            value will be produced.  Other values include:
                - N (an integer) consumes N arguments (and produces a list)
                - '?' consumes zero or one arguments
                - '*' consumes zero or more arguments (and produces a list)
                - '+' consumes one or more arguments (and produces a list)
            Note that the difference between the default and nargs=1 is that
            with the default, a single value will be produced, while with
            nargs=1, a list containing a single value will be produced.

        - const -- The value to be produced if the option is specified and the
            option uses an action that takes no values.

        - default -- The value to be produced if the option is not specified.

        - type -- A callable that accepts a single string argument, and
            returns the converted value.  The standard Python types str, int,
            float, and complex are useful examples of such callables.  If None,
            str is used.

        - choices -- A container of values that should be allowed. If not None,
            after a command-line argument has been converted to the appropriate
            type, an exception will be raised if it is not a member of this
            collection.

        - required -- True if the action must always be specified at the
            command line. This is only meaningful for optional command-line
            arguments.

        - help -- The help string describing the argument.

        - metavar -- The name to be used for the option's argument with the
            help string. If None, the 'dest' value will be used as the name.
    NFcCs^||_||_||_||_||_||_||_||_|	|_|
|_	dS)N)
rrrconstrrrrrkr)r rrrrrrrrrkrr%r%r&rNs									zAction.__init__c	s8ddddddddd	g	}fd
d|DS)Nrrrrrrrrkrcs%g|]}|t|fqSr%)r.)rUr#)r r%r&rX3s	z&Action._get_kwargs.<locals>.<listcomp>r%)r namesr%)r r&r's	zAction._get_kwargscCsttddS)Nz.__call__() not defined)NotImplementedErrorr})r parserr0valuesrr%r%r&__call__5szAction.__call__)rr+r,r-rNrrr%r%r%r&rs1csIeZdZddddddddfddZdddZS)_StoreActionNFcs|dkrtd|dk	r@|tkr@tdttt|jd|d|d|d|d|d	|d
|d|d|	d
|

dS)Nrznargs for store actions must be > 0; if you have nothing to store, actions such as store true or store const may be more appropriatez nargs must be %r to supply constrrrrrrrrrkr)r:r
superrrN)r rrrrrrrrrkr)	__class__r%r&rN;sz_StoreAction.__init__cCst||j|dS)N)r/r)r rr0rrr%r%r&rXsz_StoreAction.__call__)rr+r,rNrr%r%)rr&r9srcs=eZdZddddfddZdddZS)_StoreConstActionNFcsAtt|jd|d|ddd|d|d|d|dS)	Nrrrrrrrrk)rrrN)r rrrrrrkr)rr%r&rN^sz_StoreConstAction.__init__cCst||j|jdS)N)r/rr)r rr0rrr%r%r&rosz_StoreConstAction.__call__)rr+r,rNrr%r%)rr&r\s

rcs+eZdZdddfddZS)_StoreTrueActionFNc
s;tt|jd|d|ddd|d|d|dS)NrrrTrrrk)rrrN)r rrrrrk)rr%r&rNusz_StoreTrueAction.__init__)rr+r,rNr%r%)rr&rssrcs+eZdZdddfddZS)_StoreFalseActionTFNc
s;tt|jd|d|ddd|d|d|dS)NrrrFrrrk)rrrN)r rrrrrk)rr%r&rNsz_StoreFalseAction.__init__)rr+r,rNr%r%)rr&rsrcsIeZdZddddddddfddZdddZS)
_AppendActionNFcs|dkrtd|dk	r@|tkr@tdttt|jd|d|d|d|d|d	|d
|d|d|	d
|

dS)Nrznargs for append actions must be > 0; if arg strings are not supplying the value to append, the append const action may be more appropriatez nargs must be %r to supply constrrrrrrrrrkr)r:r
rrrN)r rrrrrrrrrkr)rr%r&rNsz_AppendAction.__init__cCsBtjt||jg}|j|t||j|dS)N)_copycopyr1rrr/)r rr0rrr*r%r%r&rs
z_AppendAction.__call__)rr+r,rNrr%r%)rr&rsrcs=eZdZddddfddZdddZS)_AppendConstActionNFcsGtt|jd|d|ddd|d|d|d|d	|dS)
Nrrrrrrrrkr)rrrN)r rrrrrrkr)rr%r&rNsz_AppendConstAction.__init__cCsEtjt||jg}|j|jt||j|dS)N)rrr1rrrr/)r rr0rrr*r%r%r&rsz_AppendConstAction.__call__)rr+r,rNrr%r%)rr&rs
rcs:eZdZdddfddZdddZS)_CountActionNFc
s;tt|jd|d|ddd|d|d|dS)Nrrrrrrrk)rrrN)r rrrrrk)rr%r&rNsz_CountAction.__init__cCs0t||jdd}t||j|dS)NrrO)r1rr/)r rr0rrZ	new_countr%r%r&rsz_CountAction.__call__)rr+r,rNrr%r%)rr&rs	rcs:eZdZeedfddZdddZS)_HelpActionNcs5tt|jd|d|d|ddd|dS)Nrrrrrrk)rrrN)r rrrrk)rr%r&rNsz_HelpAction.__init__cCs|j|jdS)N)
print_helpexit)r rr0rrr%r%r&rs
z_HelpAction.__call__)rr+r,rrNrr%r%)rr&rsrcs=eZdZdeedfddZdddZS)_VersionActionNz&show program's version number and exitcs>tt|jd|d|d|ddd|||_dS)Nrrrrrrk)rrrNversion)r rrrrrk)rr%r&rNsz_VersionAction.__init__cCs^|j}|dkr|j}|j}|j||j|jtj|jdS)N)r_get_formatterrb_print_messager\_sysstdoutr)r rr0rrrrRr%r%r&rs		
z_VersionAction.__call__)rr+r,rrNrr%r%)rr&rs
	rcsheZdZGdddeZeddfddZddZdd	Zdd
dZ	S)_SubParsersActioncs"eZdZfddZS)z&_SubParsersAction._ChoicesPseudoActionc	s_|}}|r'|ddj|7}ttj|}|jdgd|d|d|dS)Nz (%s)z, rrrkr)rrr_ChoicesPseudoActionrN)r r#aliasesrkrrZsup)rr%r&rNs
z/_SubParsersAction._ChoicesPseudoAction.__init__)rr+r,rNr%r%)rr&rsrNc
sh||_||_tj|_g|_tt|jd|d|dt	d|jd|d|dS)Nrrrrrkr)
_prog_prefix
_parser_class_collectionsOrderedDict_name_parser_map_choices_actionsrrrNr)r rrLparser_classrrkr)rr%r&rN"s				z_SubParsersAction.__init__cKs|jddkr,d|j|f|d<|jdf}d|kr~|jd}|j|||}|jj||j|}||j|<x|D]}||j|<qW|S)NrLz%s %srrk)rrrrrrrr)r r#kwargsrrkZ
choice_actionraliasr%r%r&
add_parser7s

z_SubParsersAction.add_parsercCs|jS)N)r)r r%r%r&rNsz!_SubParsersAction._get_subactionsc
Cs |d}|dd}|jtk	r<t||j|y|j|}WnOtk
rd|ddj|ji}td|}t||YnX|j|d\}	}x0t	|	j
D]\}
}t||
|qW|rt	|jtgt
|tj|dS)NrrOparser_namerz, z5unknown parser %(parser_name)r (choices: %(choices)s))rrr/rr9rr}rparse_known_argsrr*
setdefault_UNRECOGNIZED_ARGS_ATTRr.r)r rr0rrrr!rWmsgZsubnamespacekeyr$r%r%r&rQs"

	z_SubParsersAction.__call__)
rr+r,rrrrNrrrr%r%)rr&rsrc@sFeZdZdZddddddZddZd	d
ZdS)raFactory for creating file object types

    Instances of FileType are typically passed as type= arguments to the
    ArgumentParser add_argument() method.

    Keyword Arguments:
        - mode -- A string indicating how the file is to be opened. Accepts the
            same values as the builtin open() function.
        - bufsize -- The file's desired buffer size. Accepts the same values as
            the builtin open() function.
        - encoding -- The file's encoding. Accepts the same values as the
            builtin open() function.
        - errors -- A string indicating how encoding and decoding errors are to
            be handled. Accepts the same value as the builtin open() function.
    rrONcCs(||_||_||_||_dS)N)_mode_bufsize	_encoding_errors)r modebufsizeencodingerrorsr%r%r&rNs			zFileType.__init__cCs|dkrWd|jkr"tjSd|jkr8tjStd|j}t|y&t||j|j|j|j	SWnGt
k
r}z'td}t|||fWYdd}~XnXdS)N-rwzargument "-" with mode %rzcan't open '%s': %s)rrstdinrr}r:rrrrOSErrorr)r stringrerr%r%r&rszFileType.__call__cCst|j|jf}d|jfd|jfg}djdd|Ddd|D}dt|j|fS)Nrrz, cSs(g|]}|dkrt|qS)rOr)r)rUr"r%r%r&rXs	z%FileType.__repr__.<locals>.<listcomp>cSs2g|](\}}|dk	rd||fqS)Nz%s=%rr%)rUkwr"r%r%r&rXs		z%s(%s))rrrrrrr)r rWrZargs_strr%r%r&r's
zFileType.__repr__r)rr+r,r-rNrr'r%r%r%r&rvsc@s:eZdZdZddZddZddZdS)	r
zSimple object for storing attributes.

    Implements equality by attribute names and values, and provides a simple
    string representation.
    cKs)x"|D]}t||||qWdS)N)r/)r rr#r%r%r&rNs
zNamespace.__init__cCs)t|tstSt|t|kS)N)rr
NotImplementedr)r otherr%r%r&__eq__szNamespace.__eq__cCs
||jkS)N)r))r rr%r%r&__contains__szNamespace.__contains__N)rr+r,r-rNrrr%r%r%r&r
scseZdZfddZddZdddZdd	Zd
dZdd
ZddZ	ddZ
ddZddZddZ
ddZddZdddZddZd d!Zd"d#Zd$d%ZS)&_ActionsContainercsgtt|j||_||_||_||_i|_|jddt	|jddt	|jddt
|jddt|jddt|jddt
|jddt|jddt|jdd	t|jdd
t|jddt|jg|_i|_g|_g|_i|_tjd|_g|_dS)
NroZstoreZstore_const
store_trueZstore_falserZappend_constcountrkrparsersz^-\d+$|^-\d*\.\d+$)rrrNdescriptionargument_defaultprefix_charsconflict_handler_registriesregisterrrrrrrrrrr_get_handler_actions_option_string_actions_action_groups_mutually_exclusive_groups	_defaultsrGrH_negative_number_matcher_has_negative_number_optionals)r rrr
r)rr%r&rNs2					
					z_ActionsContainer.__init__cCs#|jj|i}|||<dS)N)rr)r 
registry_namer$rregistryr%r%r&rsz_ActionsContainer.registerNcCs|j|j||S)N)rr)r rr$rr%r%r&
_registry_getsz_ActionsContainer._registry_getcKsG|jj|x0|jD]%}|j|kr||j|_qWdS)N)rupdaterrr)r rror%r%r&set_defaultssz_ActionsContainer.set_defaultscCsLx6|jD]+}|j|kr
|jdk	r
|jSq
W|jj|dS)N)rrrrr)r rror%r%r&get_default	sz_ActionsContainer.get_defaultcOs|j}|s6t|dkri|dd|kri|rTd|krTtd|j||}n|j||}d|kr|d}||jkr|j||d<n|jdk	r|j|d<|j|}t|std|f||}|j	d|j
|j
}t|sDtd	|ft|d
ry|jj
|dWntk
rtdYnX|j|S)z
        add_argument(dest, ..., name=value, ...)
        add_argument(option_string, option_string, ..., name=value, ...)
        rOrrz+dest supplied twice for positional argumentrNzunknown action "%s"rz%r is not callablerz,length of metavar tuple does not match nargs)rrir:_get_positional_kwargs_get_optional_kwargsrr
_pop_action_classcallablerrrrr	TypeError_add_action)r rWrcharsrZaction_classro	type_funcr%r%r&rqs2		-


z_ActionsContainer.add_argumentcOs&t|||}|jj||S)N)_ArgumentGrouprr)r rWrrr%r%r&add_argument_groupBsz$_ActionsContainer.add_argument_groupcKs#t||}|jj||S)N)_MutuallyExclusiveGrouprr)r rrr%r%r&add_mutually_exclusive_groupGsz._ActionsContainer.add_mutually_exclusive_groupcCs|j||jj|||_x|jD]}||j|<q0Wx<|jD]1}|jj|rQ|jsQ|jjdqQW|S)NT)	_check_conflictrr	containerrrrmatchr)r rorr%r%r&r%Ls
		z_ActionsContainer._add_actioncCs|jj|dS)N)rremove)r ror%r%r&_remove_actionasz _ActionsContainer._remove_actioncCsIi}xL|jD]A}|j|krDtd}t||j|||j<qWi}xs|jD]h}|j|kr|jd|jd|jd|j||j<x"|jD]}||j||<qWqeWxD|jD]9}|j	d|j
}x|jD]}|||<qWqWx*|jD]}|j||j
|q"WdS)Nz.cannot merge actions - two groups are named %rtitlerrr)rr1r}r:r)rrrrr+rrrr%)r r-Ztitle_group_maprrZ	group_mapromutex_groupr%r%r&_add_container_actionsds,				z(_ActionsContainer._add_container_actionscKsd|kr$td}t||jdttgkrId|d<|jdtkrtd|krtd|d<t|d|dgS)Nrz1'required' is an invalid argument for positionalsrTrrr)r}r$rr
rr~)r rrrr%r%r&r s
!
z(_ActionsContainer._get_positional_kwargsc	OsJg}g}x|D]}|d|jkr]d|d|ji}td}t|||j||d|jkrt|dkr|d|jkr|j|qW|jdd}|dkr4|r|d}n
|d}|j|j}|s"td}t|||jdd	}t|d|d
|S)NroptionrzNinvalid option string %(option)r: must start with a character %(prefix_chars)rrOrz%dest= is required for options like %rrr}r)	rr}r:rrirlstripreplacer~)	r rWrrZlong_option_stringsrrrZdest_option_stringr%r%r&r!s0



z&_ActionsContainer._get_optional_kwargscCs%|jd|}|jd||S)Nro)rr)r rrror%r%r&r"sz#_ActionsContainer._pop_action_classcCsVd|j}yt||SWn1tk
rQtd}t||jYnXdS)Nz_handle_conflict_%sz%invalid conflict_resolution value: %r)rr.rr}r:)r Zhandler_func_namerr%r%r&rs

z_ActionsContainer._get_handlercCslg}x@|jD]5}||jkr|j|}|j||fqW|rh|j}|||dS)N)rrrr)r roZconfl_optionalsrZconfl_optionalrr%r%r&r,s
z!_ActionsContainer._check_conflictcCsKtddt|}djdd|D}t|||dS)Nzconflicting option string: %szconflicting option strings: %sz, cSsg|]\}}|qSr%r%)rUrror%r%r&rXs	z<_ActionsContainer._handle_conflict_error.<locals>.<listcomp>)rrirr)r roconflicting_actionsrZconflict_stringr%r%r&_handle_conflict_errors
z(_ActionsContainer._handle_conflict_errorcCsWxP|D]H\}}|jj||jj|d|js|jj|qWdS)N)rr/rrr-r0)r ror7rr%r%r&_handle_conflict_resolves
	z*_ActionsContainer._handle_conflict_resolve)rr+r,rNrrrrrqr)r+r%r0r3r r!r"rr,r8r9r%r%)rr&rs$4	
/($		rcsLeZdZddfddZfddZfddZS)r(Ncs|j}|d|j|d|j|d|jtt|j}|d||||_g|_|j	|_	|j
|_
|j|_|j|_|j
|_
|j|_dS)Nrrr
r)rrrr
rr(rNr1rrrrrrr)r r-r1rrrZ
super_init)rr%r&rNs			z_ArgumentGroup.__init__cs,tt|j|}|jj||S)N)rr(r%rr)r ro)rr%r&r%sz_ArgumentGroup._add_actioncs*tt|j||jj|dS)N)rr(r0rr/)r ro)rr%r&r0sz_ArgumentGroup._remove_action)rr+r,rNr%r0r%r%)rr&r(sr(cs=eZdZdfddZddZddZS)r*Fcs,tt|j|||_||_dS)N)rr*rNr
_container)r r-r)rr%r&rNs	z _MutuallyExclusiveGroup.__init__cCsG|jr!td}t||jj|}|jj||S)Nz-mutually exclusive arguments must be optional)rr}r:r:r%rr)r rorr%r%r&r%s	z#_MutuallyExclusiveGroup._add_actioncCs$|jj||jj|dS)N)r:r0rr/)r ror%r%r&r0$sz&_MutuallyExclusiveGroup._remove_action)rr+r,rNr%r0r%r%)rr&r*sr*cseZdZdZddddgeddddddfddZdd	Zd
dZdd
ZddZ	ddZ
ddddZddddZddZ
ddZddZddZddZd d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-Zd.d/Zd0d1Zdd2d3Zdd4d5Zdd6d7Zd8dd9d:Zd;d<ZS)=raObject for parsing command line strings into Python objects.

    Keyword Arguments:
        - prog -- The name of the program (default: sys.argv[0])
        - usage -- A usage message (default: auto-generated from arguments)
        - description -- A description of what the program does
        - epilog -- Text following the argument descriptions
        - parents -- Parsers whose arguments should be copied into this one
        - formatter_class -- HelpFormatter class for printing help messages
        - prefix_chars -- Characters that prefix optional arguments
        - fromfile_prefix_chars -- Characters that prefix files containing
            additional arguments
        - argument_default -- The default value for all arguments
        - conflict_handler -- String indicating how to handle conflicts
        - add_help -- Add a -h/-help option
        - allow_abbrev -- Allow long options to be abbreviated unambiguously
    NrerrorTc
stt|j}
|
d|d|d|	d|
|dkrVtjjtjd}||_||_	||_
||_||_||_
||_|j}|td|_|td|_d|_dd	}|jd
d|d|krdn|d}|j
rI|j|d|d
ddddtdtdxM|D]E}|j|y
|j}Wntk
rYqPX|jj|qPWdS)Nrrr
rrzpositional argumentszoptional argumentscSs|S)Nr%)rr%r%r&identitybsz)ArgumentParser.__init__.<locals>.identityrrhr2rkrorzshow this help message and exit)rrrNr7pathbasenamerargvrLrdepilogformatter_classfromfile_prefix_charsadd_helpallow_abbrevr)r}_positionals
_optionals_subparsersrrqrr3rrr)r rLrdrrAparentsrBrrCr
rrDrEZ	superinitZ	add_groupr<Zdefault_prefixrSZdefaults)rr%r&rN<sB										




zArgumentParser.__init__cs/ddddddg}fdd|DS)	NrLrdrrBrrDcs%g|]}|t|fqSr%)r.)rUr#)r r%r&rXs	z.ArgumentParser._get_kwargs.<locals>.<listcomp>r%)r rr%)r r&r|s	zArgumentParser._get_kwargsc	KsA|jdk	r"|jtd|jdt|d|ksPd|krt|jdd}t|jdd}|j|||_n|j|_|jddkr	|j	}|j
}|j}|j|j
||d|jj|d<|j|d}|d	g|}|jj||S)
Nz(cannot have multiple subparser argumentsrr1rZsubcommandsrLrYrr)rHr;r}rrrr)rFrr_get_positional_actionsrrhrdr\rtr"r%)	r rr1rrRrrfZ
parsers_classror%r%r&add_subparserss$	zArgumentParser.add_subparserscCs0|jr|jj|n|jj||S)N)rrGr%rF)r ror%r%r&r%s	zArgumentParser._add_actioncCsdd|jDS)NcSsg|]}|jr|qSr%)r)rUror%r%r&rXs	z8ArgumentParser._get_optional_actions.<locals>.<listcomp>)r)r r%r%r&_get_optional_actionss	z$ArgumentParser._get_optional_actionscCsdd|jDS)NcSsg|]}|js|qSr%)r)rUror%r%r&rXs	z:ArgumentParser._get_positional_actions.<locals>.<listcomp>)r)r r%r%r&rJs	z&ArgumentParser._get_positional_actionscCsH|j||\}}|rDtd}|j|dj||S)Nzunrecognized arguments: %srv)rr}r;r)r rWr0r@rr%r%r&
parse_argss
zArgumentParser.parse_argscCsk|dkr"tjdd}nt|}|dkrCt}xW|jD]L}|jtk	rMt||jsM|jtk	rMt	||j|jqMWx7|j
D],}t||st	|||j
|qWyX|j||\}}t|tr$|j
t|tt|t||fSWn5tk
rftjd}|jt|YnXdS)NrO)rr@rr
rrrrrr/r_parse_known_argsrrr.delattrrexc_infor;r)r rWr0rorerrr%r%r&rs,	

zArgumentParser.parse_known_argscs.	jdk	r	jix~	jD]s}|j}xat|jD]P\}}j|g}|j|d||j||ddqMWq.Wig}t}	xt|	D]\}}
|
dkr|jdx_|	D]}
|jdqWq	j	|
}|dkr4d}n||<d}|j|qWdj
|ttd	fdd	fd	d
}
	j	fdd}gd

rt
}nd}x
|krt
fddD}
|krm|
}|
krg|
qn|

kr
|}j||
|


qW|
}j|dg}x	jD]}|kr|jr|jt|q|jdk	rt|jtrt|jr|jt|jkrt|j	j||jqW|r	jtddj
|xw	jD]l}|jrxZ|jD]}|krPqWdd|jD}td}	j|dj
|qWfS)NrOz--rAOrYcsj|j||}||jk	rj|xQj|gD]=}|krNtd}t|}t|||qNW|tk	r|||dS)Nznot allowed with argument %s)r_get_valuesrrr}rrr)roZargument_stringsrZargument_valuesZconflict_actionrZaction_name)action_conflictsr0seen_actionsseen_non_default_actionsr r%r&take_actions

z5ArgumentParser._parse_known_args.<locals>.take_actioncs|}|\}}}j}g}x|dkrPj||dS|dk	ry||d}j}|dkr|d|kr|j|g|f|d}	|	|d}|ddpd}
j}||kr||}|
}qvtd}t|||q|dkrW|d}
|g}|j|||fPqtd}t|||q+|d}|d}|||}||}
||
}|j|||fPq+Wx'|D]\}}}|||qW|
S)NrOrRrzignored explicit argument %r)_match_argumentrrrr}r)start_indexoption_tuplerorexplicit_argZmatch_argumentZ
action_tuples	arg_countr&charZnew_explicit_argZ
optionals_maprstoprWrZselected_patterns)r!arg_strings_patternextrasoption_string_indicesr rXr%r&consume_optional+sN
		
	
	
	

z:ArgumentParser._parse_known_args.<locals>.consume_optionalcsj}|d}||}xHt|D]7\}}|||}||7}||q8Wt|ddd<|S)N)_match_arguments_partialzipri)rZZ
match_partialZselected_patternZ
arg_countsror]rW)r!r`rr rXr%r&consume_positionalsxs	
 z=ArgumentParser._parse_known_args.<locals>.consume_positionalsrcs"g|]}|kr|qSr%r%)rUr)rZr%r&rXs	z4ArgumentParser._parse_known_args.<locals>.<listcomp>z(the following arguments are required: %sz, cSs+g|]!}|jtk	rt|qSr%)rkrr)rUror%r%r&rXs	z#one of the arguments %s is requiredrvr)rC_read_args_from_filesrrrrriterr_parse_optionalrrrJr?r>rrrrrrrrr.r/
_get_valuer;r})r r!r0r2rrZmutex_actionZ	conflictsZarg_string_pattern_partsZarg_strings_iter
arg_stringr[patternrcrfZmax_option_string_indexZnext_option_string_indexZpositionals_end_indexZstringsZ
stop_indexZrequired_actionsrorrrr%)rUr!r`rar0rbrrVrWr rZrXr&rNs	#

	
		!!J

			
z ArgumentParser._parse_known_argscCsg}x|D]}|s-|d|jkr=|j|q
yt|ddm}g}xA|jjD]-}x$|j|D]}|j|qWqrW|j|}|j|WdQRXWq
tk
rt	j
d}|jt|Yq
Xq
W|S)NrrO)
rCrrreadrconvert_arg_line_to_argsrgrrrrPr;r)r r!Znew_arg_stringsrkZ	args_filearg_liner"rQr%r%r&rgs 

z$ArgumentParser._read_args_from_filescCs|gS)Nr%)r ror%r%r&rnsz'ArgumentParser.convert_arg_line_to_argscCs|j|}tj||}|dkrdtdttdttdi}tdd|j|j}|j|j|}t	||t
|jdS)Nzexpected one argumentzexpected at most one argumentzexpected at least one argumentzexpected %s argumentzexpected %s argumentsrO)_get_nargs_patternrGr.r}r
rrrrrrir)r ror`
nargs_patternr.Znargs_errorsrrr%r%r&rYszArgumentParser._match_argumentcsg}xtt|ddD]w}|d|}djfdd|D}tj||}|dk	r|jdd|jDPqW|S)NrrOrYcsg|]}j|qSr%)rp)rUro)r r%r&rXs	z;ArgumentParser._match_arguments_partial.<locals>.<listcomp>cSsg|]}t|qSr%)ri)rUrr%r%r&rXs	r)rrirrGr.rrf)r rer`rrZ
actions_slicerlr.r%)r r&rds
 z'ArgumentParser._match_arguments_partialc
Cs|s
dS|d|jkr!dS||jkrJ|j|}||dfSt|dkr`dSd|kr|jdd\}}||jkr|j|}|||fS|jrD|j|}t|dkr%djdd|D}d|d|i}td	}|j||nt|dkrD|\}	|	S|j	j
|rc|jscdSd
|krsdSd|dfS)NrrO=z, cSsg|]\}}}|qSr%r%)rUrorr\r%r%r&rX?s	z2ArgumentParser._parse_optional.<locals>.<listcomp>r4Zmatchesz4ambiguous option: %(option)s could match %(matches)srv)rrrisplitrE_get_option_tuplesrr}r;rr.r)
r rkrorr\Z
option_tuplesZoptionsrWrr[r%r%r&ris>



	
		zArgumentParser._parse_optionalc
Csg}|j}|d|kr|d|krd|krV|jdd\}}n|}d}x6|jD]>}|j|rl|j|}|||f}|j|qlWn|d|kr|d|kr|}d}|dd}|dd}	x|jD]v}||krE|j|}|||	f}|j|q|j|r|j|}|||f}|j|qWn|jtd||S)NrrOrrr2zunexpected option string: %s)rrsr
startswithrr;r})
r rrr&Z
option_prefixr\rorZshort_option_prefixZshort_explicit_argr%r%r&rtZs8	 
 

z!ArgumentParser._get_option_tuplescCs|j}|dkrd}n|tkr3d}nk|tkrHd}nV|tkr]d}nA|tkrrd}n,|tkrd}nddjd	|}|jr|jdd
}|jdd
}|S)Nz(-*A-*)z(-*A?-*)z	(-*[A-]*)z
(-*A[A-]*)z([-AO]*)z(-*A[-AO]*)z(-*%s-*)z-*rRrYr)	rr
rrrrrrr6)r rorrqr%r%r&rps$								z!ArgumentParser._get_nargs_patterncsjttgkr;y|jdWntk
r:YnX|rjtkrjrfj}n	j}t	|t
rj|}j|nV|rjt
krjrjdk	rj}n|}j|nt|dkrLjdtgkrL|\}j|}j|njtkrzfdd|D}njtkrfdd|D}j|dn=fdd|D}x|D]}j|qW|S)Nz--rOcs"g|]}j|qSr%)rj)rUv)ror r%r&rXs	z.ArgumentParser._get_values.<locals>.<listcomp>cs"g|]}j|qSr%)rj)rUrv)ror r%r&rXs	rcs"g|]}j|qSr%)rj)rUrv)ror r%r&rXs	)rrrr/r:r
rrrrrrj_check_valuerri)r ror!r$rkrvr%)ror r&rTs>
		
'	
zArgumentParser._get_valuescCs|jd|j|j}t|sFtd}t|||y||}Wntk
rt|jdt|j}tt	j
d}t||Yngttfk
rt|jdt|j}d|d|i}td}t|||YnX|S)Nrz%r is not callablerrOr$z!invalid %(type)s value: %(value)r)
rrr#r}rrr.rrrrPr$r:)r rorkr'rrr#rWr%r%r&rjs 
zArgumentParser._get_valuecCsh|jdk	rd||jkrdd|ddjtt|ji}td}t|||dS)Nr$rz, z3invalid choice: %(value)r (choose from %(choices)s))rrmaprr}r)r ror$rWrr%r%r&rw	s
!zArgumentParser._check_valuecCs2|j}|j|j|j|j|jS)N)rrhrdrrr\)r rRr%r%r&format_usage	s
zArgumentParser.format_usagecCs|j}|j|j|j|j|j|jxK|jD]@}|j|j	|j|j|j
|j|jqBW|j|j
|jS)N)rrhrdrrrbrrr^r1rrrr_rAr\)r rRZaction_groupr%r%r&r\	s
zArgumentParser.format_helpcCs|jd|jS)NrL)rBrL)r r%r%r&r(	szArgumentParser._get_formattercCs/|dkrtj}|j|j|dS)N)rrrry)r filer%r%r&print_usage.	s	zArgumentParser.print_usagecCs/|dkrtj}|j|j|dS)N)rrrr\)r rzr%r%r&r3	s	zArgumentParser.print_helpcCs,|r(|dkrtj}|j|dS)N)rstderrwrite)r rrzr%r%r&r8	s	zArgumentParser._print_messagercCs*|r|j|tjtj|dS)N)rrr|r)r Zstatusrr%r%r&rA	szArgumentParser.exitcCsC|jtjd|jd|i}|jdtd|dS)zerror(message: string)

        Prints a usage message incorporating the message to stderr and
        exits.

        If you override this in a subclass, it should not return -- it
        should either exit or raise an exception.
        rLrr2z%(prog)s: error: %(message)s
N)r{rr|rLrr})r rrWr%r%r&r;F	s	zArgumentParser.error) rr+r,r-rrNrrKr%rLrJrMrrNrgrnrYrdrirtrprTrjrwryr\rr{rrrr;r%r%)rr&r)sN4#;,,4	)6r-__version____all__collectionsrrrosr7rerGsysrtextwraprrr}rrr
rrrrrrrr1rrrrr	r	Exceptionrrrrrrrrrrrrrrr
rr(r*rr%r%r%r&<module>>sz	

	[#%`64"
Back to Directory File Manager