3 \a@s,dZddddddddd d d d d ddddgZddlZddlZddlZddlZ ddl Z ddl Z ddlmZmZdZdZdZdZdZdZdZGdddeZddZGd ddeZGd!ddeZGd"ddeZGd#ddeZGd$d d eZd%d&Z Gd'dde!Z"Gd(dde!Z#Gd)d d eZ$Gd*d+d+e$Z%Gd,d-d-e$Z&Gd.d/d/e&Z'Gd0d1d1e&Z(Gd2d3d3e$Z)Gd4d5d5e$Z*Gd6d7d7e$Z+Gd8d9d9e$Z,Gd:d;d;e$Z-GdddeZ/Gd?d d eZ0Gd@dAdAeZ1GdBdCdCe1Z2GdDdEdEe2Z3GdFddee1Z4dS)Gz1.1ArgumentParser ArgumentErrorArgumentTypeErrorFileType HelpFormatterArgumentDefaultsHelpFormatterRawDescriptionHelpFormatterRawTextHelpFormatterMetavarTypeHelpFormatter NamespaceAction ONE_OR_MOREOPTIONALPARSER REMAINDERSUPPRESS ZERO_OR_MOREN)gettextngettextz ==SUPPRESS==?*+zA...z...Z_unrecognized_argsc@s$eZdZddZddZddZdS)_AttributeHoldercCst|j}g}i}x|jD]}|jt|qWx8|jD],\}}|jr`|jd||fq<|||<qsz6HelpFormatter._Section.format_help..z%*s%s:  ) rSrRrP _join_partsr+rQrTrrA)r!r Z item_helpZcurrent_indentrTr&r&r' format_helps    z"HelpFormatter._Section.format_help)N)rr,r-rNr\r&r&r&r'rDs rDcCs|jjj||fdS)N)rFr+r)r!rVrWr&r&r' _add_itemszHelpFormatter._add_itemcCs0|j|j||j|}|j|jg||_dS)N)rPrDrFr]r\)r!rTZsectionr&r&r' start_sectionszHelpFormatter.start_sectioncCs|jj|_|jdS)N)rFrSrQ)r!r&r&r' end_sections zHelpFormatter.end_sectioncCs$|tk r |dk r |j|j|gdS)N)rr] _format_text)r!textr&r&r'add_textszHelpFormatter.add_textcCs&|tk r"||||f}|j|j|dS)N)rr] _format_usage)r!usageactionsgroupsprefixrWr&r&r' add_usages zHelpFormatter.add_usagecCsz|jtk rv|j}||g}x |j|D]}|j||q&Wtdd|D}||j}t|j||_|j|j |gdS)NcSsg|] }t|qSr&)len)rUsr&r&r'rX sz.HelpFormatter.add_argument..) helpr_format_action_invocation_iter_indented_subactionsrr?rArCr]_format_action)r!actionZget_invocationZ invocations subactionZinvocation_lengthZ action_lengthr&r&r' add_arguments   zHelpFormatter.add_argumentcCsx|D]}|j|qWdS)N)rq)r!reror&r&r' add_argumentss zHelpFormatter.add_argumentscCs.|jj}|r*|jjd|}|jdd}|S)Nz rZ)rEr\rKsubstrip)r!rkr&r&r'r\s  zHelpFormatter.format_helpcCsdjdd|DS)NrYcSsg|]}|r|tk r|qSr&)r)rUpartr&r&r'rX!sz-HelpFormatter._join_parts..)r )r!Z part_stringsr&r&r'r[ s zHelpFormatter._join_partscs|dkrtd}|dk r,|t|jd}n|dkrN| rNdt|jd}n|dkrdt|jd}g}g}x(|D] }|jr|j|qv|j|qvW|j} | |||} djdd|| gD}|j|jt |t |krd} | ||} | ||} t j | | }t j | | }dfdd }t |t |d krdt |t |d }|r||g|||}|j |||n |r||g|||}n|g}nZdt |}||}|||}t |d krg}|j ||||j ||||g|}d j|}d ||fS)Nzusage: )rLz%(prog)s cSsg|] }|r|qSr&r&)rUrjr&r&r'rXAsz/HelpFormatter._format_usage..z%\(.*?\)+(?=\s|$)|\[.*?\]+(?=\s|$)|\S+csg}g}|dk rt|d}n t|d}xb|D]Z}|dt|krp|rp|j|dj|g}t|d}|j||t|d7}q0W|r|j|dj||dk r|dt|d|d<|S)NrOrvr)rirr )partsindentrglineslineZline_lenru) text_widthr&r' get_linesUs"    z.HelpFormatter._format_usage..get_linesg?rOrZz%s%s )N) _dictr;option_stringsr_format_actions_usager r@rArirGfindallextend)r!rdrerfrgrLZ optionals positionalsroformatZ action_usageZ part_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 r>wYqX|t|j}||||jkrx|jD]}|j|qhW|js||kr||d7<nd||<d||<n*||kr||d7<nd||<d||<xt|d|D] } d || <qWqWg} x2t|D]$\} }|j t krj| j d|j | d krF|j | n"|j | dd kr.|j | dn|js|j|} |j|| } ||kr| ddkr| ddkr| dd} | j | nh|jd} |jdkrd | } n"|j|} |j|| }d | |f} |j r$||kr$d | } | j | q Wx(t|d dD]} || g| | | <qBWdjdd| D}d}d}tjd|d|}tjd|d|}tjd||fd|}tjdd|}|j}|S)Nrz [[]z (()rO|z%sz%s %sz[%s]T)reverservcSsg|]}|dk r|qS)Nr&)rUitemr&r&r'rXsz7HelpFormatter._format_actions_usage..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)r rGrsrt)r!rerf group_actionsZinsertsgroupstartendroirwdefaultru option_string args_stringraopencloser&r&r'rsr                 z#HelpFormatter._format_actions_usagecCsFd|kr|t|jd}t|j|jd}d|j}|j|||dS)Nz%(prog))rL rvz )r~r;r?r@rA _fill_text)r!rar{rxr&r&r'r`s  zHelpFormatter._format_textc CsBt|jd|j}t|j|d}||jd}|j|}|jsV|jd|f}d|}n@t||kr~|jd||f}d|}d}n|jd|f}d|}|}|g}|jr|j |} |j | |} |j d|d| dfx@| ddD]} |j d|d| fqWn|j ds|j dx$|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|js&|j|}|j||d\}|Sg}|jdkrB|j|jn8|j|}|j||}x |jD]}|jd||fq`Wdj|SdS)NrOrz%s %sz, ) rr_metavar_formatterrrrrrr )r!rormetavarrwrrr&r&r'rls     z'HelpFormatter._format_action_invocationcsP|jdk r|jn.|jdk r.z{%s},csttrSf|SdS)N) isinstancetuple)Z tuple_size)resultr&r'r=s z0HelpFormatter._metavar_formatter..format)rchoicesr )r!rodefault_metavarZ choice_strsrr&)rr'r4s   z HelpFormatter._metavar_formattercCs|j||}|jdkr$d|d}n|jtkr.rv) rrr rr rrrr )r!rorZ get_metavarrZformatsr&r&r'rDs        zHelpFormatter._format_argscCstt||jd}x"t|D]}||tkr||=qWx,t|D] }t||dr@||j||<q@W|jddk rdjdd|dD}||d<|j ||S)N)rLrrz, cSsg|] }t|qSr&)r)rUcr&r&r'rX`sz.HelpFormatter._expand_help..) r~varsr;listrhasattrrrr _get_help_string)r!roZparamsr$Z choices_strr&r&r'rWs  zHelpFormatter._expand_helpc cs@y |j}Wntk rYnX|j|EdH|jdS)N)_get_subactionsAttributeErrorrPrQ)r!roZget_subactionsr&r&r'rmds  z'HelpFormatter._iter_indented_subactionscCs|jjd|j}tj||S)Nrv)rJrsrt _textwrapZwrap)r!rarMr&r&r'rnszHelpFormatter._split_linescCs$|jjd|j}tj||||dS)Nrv)Zinitial_indentZsubsequent_indent)rJrsrtrZfill)r!rarMrxr&r&r'rrs zHelpFormatter._fill_textcCs|jS)N)rk)r!ror&r&r'rwszHelpFormatter._get_help_stringcCs |jjS)N)destupper)r!ror&r&r'rzsz/HelpFormatter._get_default_metavar_for_optionalcCs|jS)N)r)r!ror&r&r'r}sz1HelpFormatter._get_default_metavar_for_positional)r2r3N)N)rr,r-rNrPrQobjectrDr]r^r_rbrhrqrrr\r[rcrr`rnrlrrrrmrrrrrr&r&r&r'rs:   `a/  c@seZdZddZdS)rcs djfdd|jddDS)NrYc3s|]}|VqdS)Nr&)rUrz)rxr&r' sz9RawDescriptionHelpFormatter._fill_text..T)keepends)r splitlines)r!rarMrxr&)rxr'rsz&RawDescriptionHelpFormatter._fill_textN)rr,r-rr&r&r&r'rsc@seZdZddZdS)rcCs|jS)N)r)r!rarMr&r&r'rsz!RawTextHelpFormatter._split_linesN)rr,r-rr&r&r&r'rsc@seZdZddZdS)rcCs>|j}d|jkr:|jtk r:ttg}|js2|j|kr:|d7}|S)Nz %(default)z (default: %(default)s))rkrrr rrr)r!rorkZdefaulting_nargsr&r&r'rs  z.ArgumentDefaultsHelpFormatter._get_help_stringN)rr,r-rr&r&r&r'rsc@seZdZddZddZdS)r cCs|jjS)N)rr)r!ror&r&r'rsz:MetavarTypeHelpFormatter._get_default_metavar_for_optionalcCs|jjS)N)rr)r!ror&r&r'rsz.r&)r!namesr&)r!r'r/szAction._get_kwargscCsttddS)Nz.__call__() not defined)NotImplementedErrorr})r!parserr0valuesrr&r&r'__call__=szAction.__call__)NNNNNFNN)N)rr,r-rNrrr&r&r&r'r s6 cs(eZdZdfdd ZdddZZS) _StoreActionNFc sT|dkrtd|dk r,|tkr,tdttt|j||||||||| | 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 const) rrrrrrrrrkr)r:r superrrN) r!rrrrrrrrrkr) __class__r&r'rNCs   z_StoreAction.__init__cCst||j|dS)N)r/r)r!rr0rrr&r&r'r`sz_StoreAction.__call__)NNNNNFNN)N)rr,r-rNr __classcell__r&r&)rr'rAsrcs(eZdZdfdd ZdddZZS) _StoreConstActionNFc s"tt|j||d||||ddS)Nr)rrrrrrrk)rrrN)r!rrrrrrkr)rr&r'rNfs z_StoreConstAction.__init__cCst||j|jdS)N)r/rr)r!rr0rrr&r&r'rwsz_StoreConstAction.__call__)NFNN)N)rr,r-rNrrr&r&)rr'rds  rcseZdZdfdd ZZS)_StoreTrueActionFNcs tt|j||d|||ddS)NT)rrrrrrk)rrrN)r!rrrrrk)rr&r'rN}s z_StoreTrueAction.__init__)FFN)rr,r-rNrr&r&)rr'r{srcseZdZdfdd ZZS)_StoreFalseActionTFNcs tt|j||d|||ddS)NF)rrrrrrk)rrrN)r!rrrrrk)rr&r'rNs z_StoreFalseAction.__init__)TFN)rr,r-rNrr&r&)rr'rsrcs(eZdZdfdd ZdddZZS) _AppendActionNFc sT|dkrtd|dk r,|tkr,tdttt|j||||||||| | 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 const) rrrrrrrrrkr)r:r rrrN) r!rrrrrrrrrkr)rr&r'rNs   z_AppendAction.__init__cCs0tjt||jg}|j|t||j|dS)N)_copycopyr1rrr/)r!rr0rrr+r&r&r'rs z_AppendAction.__call__)NNNNNFNN)N)rr,r-rNrrr&r&)rr'rsrcs(eZdZdfdd ZdddZZS) _AppendConstActionNFc s$tt|j||d|||||ddS)Nr)rrrrrrrkr)rrrN)r!rrrrrrkr)rr&r'rNs z_AppendConstAction.__init__cCs2tjt||jg}|j|jt||j|dS)N)rrr1rrrr/)r!rr0rrr+r&r&r'rs z_AppendConstAction.__call__)NFNN)N)rr,r-rNrrr&r&)rr'rs  rcs(eZdZdfdd ZdddZZS) _CountActionNFcs tt|j||d|||ddS)Nr)rrrrrrk)rrrN)r!rrrrrk)rr&r'rNs z_CountAction.__init__cCs$t||jdd}t||j|dS)NrrO)r1rr/)r!rr0rrZ new_countr&r&r'rsz_CountAction.__call__)NFN)N)rr,r-rNrrr&r&)rr'rs rcs.eZdZeedffdd ZdddZZS) _HelpActionNcstt|j|||d|ddS)Nr)rrrrrk)rrrN)r!rrrrk)rr&r'rNs  z_HelpAction.__init__cCs|j|jdS)N) print_helpexit)r!rr0rrr&r&r'rsz_HelpAction.__call__)N)rr,r-rrNrrr&r&)rr'rsrcs0eZdZdeedffdd ZdddZZS)_VersionActionNz&show program's version number and exitcs$tt|j|||d|d||_dS)Nr)rrrrrk)rrrNversion)r!rrrrrk)rr&r'rNs z_VersionAction.__init__cCsD|j}|dkr|j}|j}|j||j|jtj|jdS)N)r_get_formatterrb_print_messager\_sysstdoutr)r!rr0rrrrRr&r&r'rs z_VersionAction.__call__)N)rr,r-rrNrrr&r&)rr'rs  rcsNeZdZGdddeZeddffdd ZddZdd Zd d d Z Z S) _SubParsersActioncseZdZfddZZS)z&_SubParsersAction._ChoicesPseudoActioncs@|}}|r|ddj|7}ttj|}|jg|||ddS)Nz (%s)z, )rrrkr)r rr_ChoicesPseudoActionrN)r!r$aliasesrkrrZsup)rr&r'rN"s   z/_SubParsersAction._ChoicesPseudoAction.__init__)rr,r-rNrr&r&)rr'r srNcs>||_||_tj|_g|_tt|j||t |j||ddS)N)rrrrrkr) _prog_prefix _parser_class _collections OrderedDict_name_parser_map_choices_actionsrrrNr)r!rrL parser_classrrkr)rr&r'rN*s  z_SubParsersAction.__init__cKs|jddkr d|j|f|d<|jdf}d|krX|jd}|j|||}|jj||jf|}||j|<x|D]}||j|<qtW|S)NrLz%s %srrk)rrrrrrrr)r!r$kwargsrrkZ choice_actionraliasr&r&r' add_parser?s      z_SubParsersAction.add_parsercCs|jS)N)r)r!r&r&r'rVsz!_SubParsersAction._get_subactionsc Cs|d}|dd}|jtk r,t||j|y|j|}Wn<tk rv|dj|jd}td|}t||YnX|j|d\} }x$t | j D]\} } t|| | qW|rt |j t gt |t j|dS)NrrOz, ) parser_namerz5unknown parser %(parser_name)r (choices: %(choices)s))rrr/rr9r r}rparse_known_argsrr+ setdefault_UNRECOGNIZED_ARGS_ATTRr.r) r!rr0rrrr"rWmsgZ subnamespacekeyr%r&r&r'rYs"    z_SubParsersAction.__call__)N) rr,r-r rrrNrrrrr&r&)rr'rsrc@s&eZdZd ddZddZdd ZdS) rrrONcCs||_||_||_||_dS)N)_mode_bufsize _encoding_errors)r!modebufsizeencodingerrorsr&r&r'rNszFileType.__init__cCs|dkr>d|jkrtjSd|jkr(tjStd|j}t|yt||j|j|j|j St k r}ztd}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, cSsg|]}|dkrt|qS)rOr)r)rUr#r&r&r'rXsz%FileType.__repr__..cSs$g|]\}}|dk rd||fqS)Nz%s=%rr&)rUkwr#r&r&r'rXsz%s(%s))rrrrr rr)r!rWrZargs_strr&r&r'r(s  zFileType.__repr__r)rrNN)rr,r-rNrr(r&r&r&r'r~s c@s$eZdZddZddZddZdS)r cKs"x|D]}t||||qWdS)N)r/)r!rr$r&r&r'rNs zNamespace.__init__cCst|tstSt|t|kS)N)rr NotImplementedr)r!otherr&r&r'__eq__s zNamespace.__eq__cCs ||jkS)N)r*)r!rr&r&r' __contains__szNamespace.__contains__N)rr,r-rNrrr&r&r&r'r scseZdZfddZddZd&ddZdd Zd d Zd d ZddZ ddZ ddZ ddZ ddZ ddZddZd'ddZddZd d!Zd"d#Zd$d%ZZS)(_ActionsContainercstt|j||_||_||_||_i|_|jddt |jddt |jddt |jddt |jddt |jddt |jddt|jddt|jdd t|jdd t|jdd t|jg|_i|_g|_g|_i|_tjd |_g|_dS) NroZstoreZ store_const store_trueZ store_falserZ append_constcountrkrparsersz^-\d+$|^-\d*\.\d+$)rr rN descriptionargument_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 rrr)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_getcKs6|jj|x$|jD]}|j|kr||j|_qWdS)N)rupdaterrr)r!rror&r&r' set_defaultss   z_ActionsContainer.set_defaultscCs8x(|jD]}|j|kr|jdk r|jSqW|jj|dS)N)rrrrr)r!rror&r&r' get_defaults  z_ActionsContainer.get_defaultc Os0|j}| s(t|dkrJ|dd|krJ|r|js>|jjdq>W|S)NT) _check_conflictrr containerrrrmatchr)r!rorr&r&r'r&Ts     z_ActionsContainer._add_actioncCs|jj|dS)N)rremove)r!ror&r&r'_remove_actionisz _ActionsContainer._remove_actioncCsi}x8|jD].}|j|kr0td}t||j|||j<q Wi}xR|jD]H}|j|krt|j|j|j|jd||j<x|jD]}||j||<q|WqJWx4|jD]*}|j |j d}x|jD] }|||<qWqWx |j D]}|j ||j |qWdS)Nz.cannot merge actions - two groups are named %r)titler r)r)rr2r}r:r*r rrrr,rrrr&)r!r.Ztitle_group_maprrZ group_mapro mutex_groupr&r&r'_add_container_actionsls,         z(_ActionsContainer._add_container_actionscKs^d|krtd}t||jdttgkr2d|d<|jdtkrPd|krPd|d<t||gdS)Nrz1'required' is an invalid argument for positionalsrTr)rr)r}r%rr rr~)r!rrrr&r&r'r!sz(_ActionsContainer._get_positional_kwargsc Osg}g}xv|D]n}|d|jkr@||jd}td}t|||j||d|jkrt|dkr|d|jkr|j|qW|jdd}|dkr|r|d}n|d}|j|j}|std}t|||jdd}t|||d S) Nr)optionrzNinvalid option string %(option)r: must start with a character %(prefix_chars)rrOrz%dest= is required for options like %rrr})rr) 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#s z#_ActionsContainer._pop_action_classc CsDd|j}y t||Stk r>td}t||jYnXdS)Nz_handle_conflict_%sz%invalid conflict_resolution value: %r)rr.rr}r:)r!Zhandler_func_namerr&r&r'rs   z_ActionsContainer._get_handlercCsPg}x0|jD]&}||jkr |j|}|j||fq W|rL|j}|||dS)N)rrrr)r!roZconfl_optionalsrZconfl_optionalrr&r&r'r-s   z!_ActionsContainer._check_conflictcCs6tddt|}djdd|D}t|||dS)Nzconflicting option string: %szconflicting option strings: %sz, cSsg|] \}}|qSr&r&)rUrror&r&r'rXsz<_ActionsContainer._handle_conflict_error..)rrir r)r!roconflicting_actionsrZconflict_stringr&r&r'_handle_conflict_errors    z(_ActionsContainer._handle_conflict_errorcCsBx<|D]4\}}|jj||jj|d|js|jj|qWdS)N)rr0rrr.r1)r!ror8rr&r&r'_handle_conflict_resolves  z*_ActionsContainer._handle_conflict_resolve)N)N)rr,r-rNrrrr rqr*r,r&r1r4r!r"r#rr-r9r:rr&r&)rr'r s$ 4   /($   r cs6eZdZdfdd ZfddZfddZZS) r)Nc s|j}|d|j|d|j|d|jtt|j}|fd|i|||_g|_|j |_ |j |_ |j |_ |j |_ |j |_ |j|_dS)Nrrrr )rrrrrr)rNr2rrrrrrr)r!r.r2r rrZ super_init)rr&r'rNs    z_ArgumentGroup.__init__cs tt|j|}|jj||S)N)rr)r&rr)r!ro)rr&r'r&s z_ArgumentGroup._add_actioncs tt|j||jj|dS)N)rr)r1rr0)r!ro)rr&r'r1sz_ArgumentGroup._remove_action)NN)rr,r-rNr&r1rr&r&)rr'r)s r)cs.eZdZdfdd ZddZddZZS) r+Fcs tt|j|||_||_dS)N)rr+rNr _container)r!r.r)rr&r'rNsz _MutuallyExclusiveGroup.__init__cCs2|jrtd}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;r1rr0)r!ror&r&r'r1,s z&_MutuallyExclusiveGroup._remove_action)F)rr,r-rNr&r1rr&r&)rr'r+sr+c seZdZddddgeddddddf fdd ZddZd d Zd d Zd dZddZ dd1d2Zd?d3d4Zd@d5d6ZdAd8d9Zd:d;ZZS)BrNrerrorTc  s&tt|j} | ||| | d|dkr6tjjtjd}||_||_ ||_ ||_ ||_ | |_ | |_|j}|td|_|td|_d|_dd}|jdd|d|krdn|d}|j r|j|d |d d d ttd d xD|D]<}|j|y |j}Wntk rYqX|jj|qWdS)N)r rrrrzpositional argumentszoptional argumentscSs|S)Nr&)rr&r&r'identityjsz)ArgumentParser.__init__..identityrrhr2rkzshow this help message and exit)rorrk)rrrNr7pathbasenamerargvrLrdepilogformatter_classfromfile_prefix_charsadd_help allow_abbrevr*r} _positionals _optionals _subparsersrrqrr4rrr)r!rLrdr rBparentsrCrrDrrrErFZ superinitZ add_groupr=Zdefault_prefixrSZdefaults)rr&r'rNDsB     zArgumentParser.__init__cs"ddddddg}fdd|DS) NrLrdr rCrrEcsg|]}|t|fqSr&)r.)rUr$)r!r&r'rXsz.ArgumentParser._get_kwargs..r&)r!rr&)r!r'rszArgumentParser._get_kwargsc Ks|jdk r|jtd|jdt|d|ks8d|krht|jdd}t|jdd}|j|||_n|j|_|jddkr|j }|j }|j }|j |j ||d|jj|d<|j|d}|fd gi|}|jj||S) Nz(cannot have multiple subparser argumentsrr2r Z subcommandsrLrYr r)rIr<r}rrrr*rGrr_get_positional_actionsrrhrdr\rtr#r&) r!rr2r rRrrfZ parsers_classror&r&r'add_subparserss$   zArgumentParser.add_subparserscCs$|jr|jj|n |jj||S)N)rrHr&rG)r!ror&r&r'r&s zArgumentParser._add_actioncCsdd|jDS)NcSsg|]}|jr|qSr&)r)rUror&r&r'rXsz8ArgumentParser._get_optional_actions..)r)r!r&r&r'_get_optional_actionssz$ArgumentParser._get_optional_actionscCsdd|jDS)NcSsg|]}|js|qSr&)r)rUror&r&r'rXsz:ArgumentParser._get_positional_actions..)r)r!r&r&r'rKsz&ArgumentParser._get_positional_actionscCs4|j||\}}|r0td}|j|dj||S)Nzunrecognized arguments: %srv)rr}r<r )r!rWr0rArr&r&r' parse_argss zArgumentParser.parse_argsc Cs |dkrtjdd}nt|}|dkr.t}x>|jD]4}|jtk r6t||js6|jtk r6t ||j|jq6Wx*|j D] }t||svt |||j |qvWy<|j ||\}}t|t r|j t|t t|t ||fStk rtjd}|jt|YnXdS)NrO)rrArr rrrrrr/r_parse_known_argsrrr.delattrrexc_infor<r)r!rWr0rorerrr&r&r'rs,         zArgumentParser.parse_known_argscs" jdk r jix` jD]V}|j}xJt|jD]<\}}j|g}|j|d||j||ddq6Wq Wig}t} xnt| D]b\}} | dkr|jdxF| D]} |jdqWq j | } | dkrd} n | |<d} |j| qWdj |t t d fdd  fd d } j  fd d }gd rpt }nd}x| |krt fddD} |kr| }| kr| qvn| kr |}j|| |  qvW| }j|dg}x jD]|}|kr|jr>|jt|nT|jdk rt|jtrt|jr|jt|jkrt|j j||jqW|r jtddj |xb jD]X}|jrxH|jD]}|krPqWdd|jD}td} j|dj |qWfS)NrOz--rAOrYcsj|j||}||jk rfj|x:j|gD]*}|kr8td}t|}t|||q8W|tk r||||dS)Nznot allowed with argument %s)r _get_valuesrrr}rrr)roZargument_stringsrZargument_valuesZconflict_actionrZ action_name)action_conflictsr0 seen_actionsseen_non_default_actionsr!r&r' take_actions    z5ArgumentParser._parse_known_args..take_actioncs|}|\}}}j}g}x>|dkr>j||dS|dk r||d}j}|dkr|d|kr|j|g|f|d} | |d}|ddpd} j} || kr| |}| }ntd} t|| |n@|dkr|d} |g}|j|||fPntd} t|| |q |d}|d}|||}||} || }|j|||fPq Wx |D]\}}}|||qdW| S)NrOrSrzignored 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!rYr&r'consume_optional3sN       z:ArgumentParser._parse_known_args..consume_optionalcsrj}|d}||}x8t|D]*\}}|||}||7}||q(Wt|ddd<|S)N)_match_arguments_partialzipri)r[Z match_partialZselected_patternZ arg_countsror^rW)r"rarr!rYr&r'consume_positionalss  z=ArgumentParser._parse_known_args..consume_positionalsrcsg|]}|kr|qSr&r&)rUr)r[r&r'rXsz4ArgumentParser._parse_known_args..z(the following arguments are required: %sz, cSsg|]}|jtk rt|qSr&)rkrr)rUror&r&r'rXsz#one of the arguments %s is requiredrv)Nr)rD_read_args_from_filesrrrrriterr_parse_optionalr rrKr?r>rrrrrrrrr.r/ _get_valuer<r})r!r"r0r3rrZ mutex_actionZ conflictsZarg_string_pattern_partsZarg_strings_iter arg_stringr\patternrdrgZmax_option_string_indexZnext_option_string_indexZpositionals_end_indexZstringsZ stop_indexZrequired_actionsrorrrr&) rVr"rarbr0rcrrWrXr!r[rYr'rOs        J                 z ArgumentParser._parse_known_argscCsg}x|D]}| s"|d|jkr.|j|q ylt|ddR}g}x2|jjD]"}x|j|D]}|j|qdWqTW|j|}|j|WdQRXWq tk rt j d}|j t |Yq Xq W|S)NrrO) rDrrreadrconvert_arg_line_to_argsrhrrrrQr<r)r!r"Znew_arg_stringsrlZ args_filearg_liner#rRr&r&r'rhs     z$ArgumentParser._read_args_from_filescCs|gS)Nr&)r!rpr&r&r'rosz'ArgumentParser.convert_arg_line_to_argscCst|j|}tj||}|dkrfdtdttdttdi}tdd|j|j}|j|j|}t ||t |j dS)Nzexpected one argumentzexpected at most one argumentzexpected at least one argumentzexpected %s argumentzexpected %s argumentsrO) _get_nargs_patternrGr/r}r r rrrrrir)r!rora nargs_patternr/Z nargs_errorsrrr&r&r'rZs    zArgumentParser._match_argumentcstg}xjtt|ddD]V}|d|}djfdd|D}tj||}|dk r|jdd|jDPqW|S)NrrOrYcsg|]}j|qSr&)rq)rUro)r!r&r'rXsz;ArgumentParser._match_arguments_partial..cSsg|] }t|qSr&)ri)rUrr&r&r'rX!sr)rrir rGr/rrf)r!rerarrZ actions_slicermr/r&)r!r'res   z'ArgumentParser._match_arguments_partialc Cs|sdS|d|jkrdS||jkr8|j|}||dfSt|dkrHdSd|kr~|jdd\}}||jkr~|j|}|||fS|jr|j|}t|dkrdjdd|D}||d}td}|j||nt|dkr|\} | S|j j |r|j sdSd |krdSd|dfS) NrrO=z, cSsg|]\}}}|qSr&r&)rUrorr]r&r&r'rXGsz2ArgumentParser._parse_optional..)r5Zmatchesz4ambiguous option: %(option)s could match %(matches)srv) rrrisplitrF_get_option_tuplesr r}r<rr/r) r!rlrorr]Z option_tuplesZoptionsrWrr\r&r&r'rj's>              zArgumentParser._parse_optionalc Cs0g}|j}|d|kr~|d|kr~d|kr<|jdd\}}n|}d}x|jD],}|j|rL|j|}|||f}|j|qLWn|d|ko|d|kr|}d}|dd}|dd} xr|jD]T}||kr|j|}||| f}|j|q|j|r|j|}|||f}|j|qWn|jtd||S)NrrOrsr2zunexpected option string: %s)rrtr startswithrr<r}) r!rrr'Z option_prefixr]rorZshort_option_prefixZshort_explicit_argr&r&r'rubs8             z!ArgumentParser._get_option_tuplescCs|j}|dkrd}nX|tkr"d}nJ|tkr0d}n<|tkr>d}n.|tkrLd}n |tkrZd}nddjd |}|jr|jdd }|jd d }|S) Nz(-*A-*)z(-*A?-*)z (-*[A-]*)z (-*A[A-]*)z([-AO]*)z (-*A[-AO]*)z(-*%s-*)z-*rSrYr) rr rr rrr rr7)r!rorrrr&r&r'rqs$  z!ArgumentParser._get_nargs_patternc sxjttgkr2y|jdWntk r0YnX| rzjtkrzjrPj}nj}t |t rxj |}j |n| rjt krj rjdk rj}n|}j |nt|dkrjdtgkr|\}j |}j |njtkrfdd|D}nbjtkrDfdd|D}j |dn0fdd|D}x|D]}j |q^W|S)Nz--rOcsg|]}j|qSr&)rk)rUv)ror!r&r'rXsz.ArgumentParser._get_values..csg|]}j|qSr&)rk)rUrw)ror!r&r'rXsrcsg|]}j|qSr&)rk)rUrw)ror!r&r'rXs)rrrr0r:r rrrrrrk _check_valuerri)r!ror"r%rlrwr&)ror!r'rUs>       zArgumentParser._get_valuesc Cs|jd|j|j}t|s0td}t|||y ||}Wntk r~t|jdt|j}tt j d}t||YnLt t fk rt|jdt|j}||d}td}t|||YnX|S)Nrz%r is not callablerrO)rr%z!invalid %(type)s value: %(value)r) rrr$r}rrr.rrrrQr%r:)r!rorlr(rrr$rWr&r&r'rks   zArgumentParser._get_valuecCsF|jdk rB||jkrB|djtt|jd}td}t|||dS)Nz, )r%rz3invalid choice: %(value)r (choose from %(choices)s))rr maprr}r)r!ror%rWrr&r&r'rx s zArgumentParser._check_valuecCs$|j}|j|j|j|j|jS)N)rrhrdrrr\)r!rRr&r&r' format_usage s zArgumentParser.format_usagecCsx|j}|j|j|j|j|j|jx:|jD]0}|j|j |j|j|j |j |j q0W|j|j |jS)N)rrhrdrrrbr rr^r2rrrr_rBr\)r!rRZ action_groupr&r&r'r\ s        zArgumentParser.format_helpcCs|j|jdS)N)rL)rCrL)r!r&r&r'r0 szArgumentParser._get_formattercCs"|dkrtj}|j|j|dS)N)rrrrz)r!filer&r&r' print_usage6 szArgumentParser.print_usagecCs"|dkrtj}|j|j|dS)N)rrrr\)r!r{r&r&r'r; szArgumentParser.print_helpcCs |r|dkrtj}|j|dS)N)rstderrwrite)r!rr{r&r&r'r@ szArgumentParser._print_messagercCs |r|j|tjtj|dS)N)rrr}r)r!Zstatusrr&r&r'rI szArgumentParser.exitcCs0|jtj|j|d}|jdtd|dS)N)rLrr2z%(prog)s: error: %(message)s )r|rr}rLrr})r!rrWr&r&r'r<N s  zArgumentParser.error)NN)NN)N)N)N)rN) rr,r-rrNrrLr&rMrKrNrrOrhrorZrerjrurqrUrkrxrzr\rr|rrrr<rr&r&)rr'r1sN4  #w;,,4    )5 __version____all__ collectionsrrrosr7rerGsysrtextwraprrr}rrr rr rrrrrr1rrrrr r Exceptionrrr rrrrrrrrrrrr r r)r+rr&r&r&r'@s~ n    [#%`65"