B YN^@sdZddddddddd d d d d ddddgZddlZddlZddlZddlmZ m Z dZ dZ dZ dZdZdZdZGdddeZddZGd ddeZGd!ddeZGd"ddeZGd#ddeZGd$d d eZd%d&ZGd'ddeZGd(ddeZGd)d d eZGd*d+d+eZGd,d-d-eZ Gd.d/d/e Z!Gd0d1d1e Z"Gd2d3d3eZ#Gd4d5d5eZ$Gd6d7d7eZ%Gd8d9d9eZ&Gd:d;d;eZ'GdddeZ)Gd?d d eZ*Gd@dAdAeZ+GdBdCdCe+Z,GdDdEdEe,Z-GdFddee+Z.dS)Gz1.1ArgumentParser ArgumentErrorArgumentTypeErrorFileType HelpFormatterArgumentDefaultsHelpFormatterRawDescriptionHelpFormatterRawTextHelpFormatterMetavarTypeHelpFormatter NamespaceAction ONE_OR_MOREOPTIONALPARSER REMAINDERSUPPRESS ZERO_OR_MOREN)gettextngettextz ==SUPPRESS==?*+zA...z..._unrecognized_argsc@s$eZdZddZddZddZdS)_AttributeHoldercCst|j}g}i}x|D]}|t|qWx8|D],\}}|r`|d||fq<|||<qsz6HelpFormatter._Section.format_help..z%*s%s:  ) rXrWrU _join_partsr.rVrYrrD)r"r! item_helpcurrent_indentrYr)r)r* format_helps    z"HelpFormatter._Section.format_help)N)rr/r0rSrcr)r)r)r*rGs rGcCs|jj||fdS)N)rIr.r)r"r[r\r)r)r* _add_itemszHelpFormatter._add_itemcCs0||||j|}||jg||_dS)N)rUrGrIrdrc)r"rYsectionr)r)r* start_sectionszHelpFormatter.start_sectioncCs|jj|_|dS)N)rIrXrV)r"r)r)r* end_sections zHelpFormatter.end_sectioncCs$|tk r |dk r ||j|gdS)N)rrd _format_text)r"textr)r)r*add_textszHelpFormatter.add_textcCs&|tk r"||||f}||j|dS)N)rrd _format_usage)r"usageactionsgroupsprefixr\r)r)r* add_usages zHelpFormatter.add_usagecCsz|jtk rv|j}||g}x ||D]}|||q&Wtdd|D}||j}t|j||_||j |gdS)NcSsg|] }t|qSr))len)rZsr)r)r*r] sz.HelpFormatter.add_argument..) helpr_format_action_invocation_iter_indented_subactionsrrBrDrFrd_format_action)r"actionget_invocation invocations subactioninvocation_length action_lengthr)r)r* add_arguments   zHelpFormatter.add_argumentcCsx|D]}||qWdS)N)r})r"rmrwr)r)r* add_argumentss zHelpFormatter.add_argumentscCs.|j}|r*|jd|}|dd}|S)Nz r_)rHrcrNsubstrip)r"rsr)r)r*rcs  zHelpFormatter.format_helpcCsddd|DS)Nr^cSsg|]}|r|tk r|qSr))r)rZpartr)r)r*r]#sz-HelpFormatter._join_parts..)r!)r" part_stringsr)r)r*r`"s zHelpFormatter._join_partscs|dkrtd}|dk r,|t|jd}n|dkrL|sLdt|jd}n|dkrdt|jd}g}g}x(|D] }|jr||qt||qtW|j} | |||} ddd|| gD}|j|jt |t |krd} | ||} | ||} t | | }t | | }dfdd }t |t |d krdt |t |d }|r||g|||}| |||n |r||g|||}n|g}nZdt |}||}|||}t |d krg}| |||| ||||g|}d |}d ||fS)Nzusage: )rOz%(prog)s cSsg|] }|r|qSr)r))rZrrr)r)r*r]Csz/HelpFormatter._format_usage..z%\(.*?\)+(?=\s|$)|\[.*?\]+(?=\s|$)|\S+csg}g}|dk rt|d}n t|d}xb|D]Z}|dt|krp|rp||d|g}t|d}|||t|d7}q0W|r||d||dk r|dt|d|d<|S)NrTrr)rqrr!)partsindentrolineslineline_lenr) text_widthr)r* get_linesWs"    z.HelpFormatter._format_usage..get_linesg?rTr_z%s%s )N) _dictr>option_stringsr_format_actions_usager!rCrDrqrJfindallextend)r"rlrmrnrorO optionals positionalsrwformat action_usage part_regexp opt_usage pos_usage opt_parts pos_partsrrrrr))rr*rk'sV             zHelpFormatter._format_usagec Cst}i}x(|D]}y||jd}Wntk rBwYqX|t|j}||||jkrx|jD]}||qlW|js||kr||d7<nd||<||kr||d7<nd||<nF||kr||d7<nd||<||kr||d7<nd||<x t|d|D]} d || <q WqWg} x0t|D]"\} }|j t kr| d| | d kr| | n"| | dd krh| | dn|js||} ||| } ||kr| ddkr| d dkr| dd } | | nf|jd} |jdkr"d | } n"||} ||| }d | |f} |js^||kr^d | } | | qFWx(t|ddD]} || g| | | <q|Wddd| D}d}d}td|d|}td|d|}td||fd|}tdd|}|}|S)Nrz [[]z (()rT|z%sz%s %sz[%s]T)reversercSsg|]}|dk r|qS)Nr))rZitemr)r)r*r]sz7HelpFormatter._format_actions_usage..z[\[(]z[\])]z(%s) z\1z (%s)z%s *%sr^z \(([^|]*)\))setindex_group_actionsr=rqaddrequiredrange enumeratersrrgetpopr#_get_default_metavar_for_positional _format_argsnargs!_get_default_metavar_for_optionalr,r!rJrr)r"rmrn group_actionsinsertsgroupstartendrwirdefaultr option_string args_stringriopencloser)r)r*rsz                 z#HelpFormatter._format_actions_usagecCsFd|kr|t|jd}t|j|jd}d|j}||||dS)Nz%(prog))rO rz )rr>rBrCrD _fill_text)r"rirrr)r)r*rhs  zHelpFormatter._format_textc CsBt|jd|j}t|j|d}||jd}||}|jsV|jd|f}d|}n@t||kr~|jd||f}d|}d}n|jd|f}d|}|}|g}|jr| |} | | |} | d|d| dfx@| ddD]} | d|d| fqWn| ds| dx$| |D]} | || qW||S) Nr4rr^z%*s%s z %*s%-*s rrTr_)rArFr@rBrCrDrtrsrq _expand_help _split_linesrendswithrurvr`) r"rw help_position help_width action_width action_headertup indent_firstr help_text help_linesrrzr)r)r*rvs6          zHelpFormatter._format_actioncCs|js&||}|||d\}|Sg}|jdkrB||jn8||}|||}x |jD]}|d||fq`Wd|SdS)NrTrz%s %sz, ) rr_metavar_formatterrrrrrr!)r"rwrmetavarrrrr)r)r*rt$s     z'HelpFormatter._format_action_invocationcsP|jdk r|jn.|jdk r.z{%s},csttrSf|SdS)N) isinstancetuple) tuple_size)resultr)r*rEs z0HelpFormatter._metavar_formatter..format)rchoicesr!)r"rwdefault_metavar choice_strsrr))rr*r<s   z HelpFormatter._metavar_formattercCs|||}|jdkr$d|d}n|jtkr.r) rrr rr rrrrr!)r"rwr get_metavarrformatsr)r)r*rLs$        zHelpFormatter._format_argscCstt||jd}x"t|D]}||tkr||=qWx,t|D] }t||dr@||j||<q@W|ddk rddd|dD}||d<| ||S)N)rOrrz, cSsg|] }t|qSr))r)rZcr)r)r*r]jsz.HelpFormatter._expand_help..) rvarsr>r1rhasattrrrr!_get_help_string)r"rwparamsr' choices_strr)r)r*ras  zHelpFormatter._expand_helpccs@y |j}Wntk rYnX||EdH|dS)N)_get_subactionsAttributeErrorrUrV)r"rwget_subactionsr)r)r*runs  z'HelpFormatter._iter_indented_subactionscCs&|jd|}ddl}|||S)Nrr)rMrrtextwrapwrap)r"rirRrr)r)r*rxszHelpFormatter._split_linescCs,|jd|}ddl}|j||||dS)Nrr)initial_indentsubsequent_indent)rMrrrfill)r"rirRrrr)r)r*rs zHelpFormatter._fill_textcCs|jS)N)rs)r"rwr)r)r*rszHelpFormatter._get_help_stringcCs |jS)N)destupper)r"rwr)r)r*rsz/HelpFormatter._get_default_metavar_for_optionalcCs|jS)N)r)r"rwr)r)r*rsz1HelpFormatter._get_default_metavar_for_positional)r4r5N)N)rr/r0rSrUrVobjectrGrdrfrgrjrpr}r~rcr`rkrrhrvrtrrrrurrrrrr)r)r)r*rs:   `g/  c@seZdZddZdS)rcs dfdd|jddDS)Nr^c3s|]}|VqdS)Nr))rZr)rr)r* sz9RawDescriptionHelpFormatter._fill_text..T)keepends)r! splitlines)r"rirRrr))rr*rsz&RawDescriptionHelpFormatter._fill_textN)rr/r0rr)r)r)r*rsc@seZdZddZdS)rcCs|S)N)r)r"rirRr)r)r*rsz!RawTextHelpFormatter._split_linesN)rr/r0rr)r)r)r*rsc@seZdZddZdS)rcCs>|j}d|jkr:|jtk r:ttg}|js2|j|kr:|d7}|S)Nz %(default)z (default: %(default)s))rsrrr rrr)r"rwrsdefaulting_nargsr)r)r*rs  z.ArgumentDefaultsHelpFormatter._get_help_stringN)rr/r0rr)r)r)r*rsc@seZdZddZddZdS)r cCs|jjS)N)rr)r"rwr)r)r*rsz:MetavarTypeHelpFormatter._get_default_metavar_for_optionalcCs|jjS)N)rr)r"rwr)r)r*rsz.r))r"namesr))r"r*r>szAction._get_kwargscCsttddS)Nz.__call__() not defined)NotImplementedErrorr)r"parser namespacevaluesrr)r)r*__call__LszAction.__call__)NNNNNFNN)N)rr/r0rSrrr)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) rrrrrrrrrsr)r=r superrrS) r"rrrrrrrrrsr) __class__r)r*rSRs   z_StoreAction.__init__cCst||j|dS)N)setattrr)r"rrrrr)r)r*rosz_StoreAction.__call__)NNNNNFNN)N)rr/r0rSr __classcell__r)r))rr*rPsrcs(eZdZdfdd ZdddZZS) _StoreConstActionNFc s"tt|j||d||||ddS)Nr)rrrrrrrs)rrrS)r"rrrrrrsr)rr)r*rSus z_StoreConstAction.__init__cCst||j|jdS)N)rrr)r"rrrrr)r)r*rsz_StoreConstAction.__call__)NFNN)N)rr/r0rSrrr)r))rr*rss  rcseZdZdfdd ZZS)_StoreTrueActionFNcs tt|j||d|||ddS)NT)rrrrrrs)rrrS)r"rrrrrs)rr)r*rSs z_StoreTrueAction.__init__)FFN)rr/r0rSrr)r))rr*rsrcseZdZdfdd ZZS)_StoreFalseActionTFNcs tt|j||d|||ddS)NF)rrrrrrs)rrrS)r"rrrrrs)rr)r*rSs z_StoreFalseAction.__init__)TFN)rr/r0rSrr)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) rrrrrrrrrsr)r=r rrrS) r"rrrrrrrrrsr)rr)r*rSs   z_AppendAction.__init__cCs2t||jd}t|}||t||j|dS)N)rrr3rr)r"rrrrr.r)r)r*rs z_AppendAction.__call__)NNNNNFNN)N)rr/r0rSrrr)r))rr*rsrcs(eZdZdfdd ZdddZZS) _AppendConstActionNFc s$tt|j||d|||||ddS)Nr)rrrrrrrsr)rrrS)r"rrrrrrsr)rr)r*rSs z_AppendConstAction.__init__cCs4t||jd}t|}||jt||j|dS)N)rrr3rrr)r"rrrrr.r)r)r*rs z_AppendConstAction.__call__)NFNN)N)rr/r0rSrrr)r))rr*rs  rcs(eZdZdfdd ZdddZZS) _CountActionNFcs tt|j||d|||ddS)Nr)rrrrrrs)rrrS)r"rrrrrs)rr)r*rSs z_CountAction.__init__cCs0t||jd}|dkrd}t||j|ddS)NrrT)rrr)r"rrrrcountr)r)r*rsz_CountAction.__call__)NFN)N)rr/r0rSrrr)r))rr*rs rcs.eZdZeedffdd ZdddZZS) _HelpActionNcstt|j|||d|ddS)Nr)rrrrrs)rrrS)r"rrrrs)rr)r*rSs  z_HelpAction.__init__cCs||dS)N) print_helpexit)r"rrrrr)r)r*rsz_HelpAction.__call__)N)rr/r0rrSrrr)r))rr*rsrcs0eZdZdeedffdd ZdddZZS)_VersionActionNz&show program's version number and exitcs$tt|j|||d|d||_dS)Nr)rrrrrs)rrrSversion)r"rrrrrs)rr)r*rSs z_VersionAction.__init__cCsD|j}|dkr|j}|}||||tj|dS)N)r_get_formatterrj_print_messagerc_sysstdoutr)r"rrrrrrWr)r)r*r's z_VersionAction.__call__)N)rr/r0rrSrrr)r))rr*rs  rcsPeZdZGdddeZedddffdd ZddZd d Zd d d Z Z S)_SubParsersActioncseZdZfddZZS)z&_SubParsersAction._ChoicesPseudoActioncs@|}}|r|dd|7}ttj|}|jg|||ddS)Nz (%s)z, )rrrsr)r!rr _ChoicesPseudoActionrS)r"r'aliasesrsrrsup)rr)r*rS5s   z/_SubParsersAction._ChoicesPseudoAction.__init__)rr/r0rSrr)r))rr*r3srFNc s<||_||_i|_g|_tt|j||t|j|||ddS)N)rrrrrrsr) _prog_prefix _parser_class_name_parser_map_choices_actionsrr rSr)r"rrO parser_classrrrsr)rr)r*rS=s  z_SubParsersAction.__init__cKs|ddkr d|j|f|d<|dd}d|krX|d}||||}|j||jf|}||j|<x|D]}||j|<qtW|S)NrOz%s %srr)rs)rrrrrrrr)r"r'kwargsrrs choice_actionraliasr)r)r* add_parserTs      z_SubParsersAction.add_parsercCs|jS)N)r)r"r)r)r*rksz!_SubParsersAction._get_subactionsc Cs|d}|dd}|jtk r,t||j|y|j|}Wn<tk rv|d|jd}td|}t||YnX||d\} }x$t |  D]\} } t|| | qW|rt | t gt |t |dS)NrrTz, ) parser_namerz5unknown parser %(parser_name)r (choices: %(choices)s))rrrrr<r!rrparse_known_argsrr. setdefault_UNRECOGNIZED_ARGS_ATTRrr) r"rrrrrr$r\msg subnamespacekeyr(r)r)r*rns"    z_SubParsersAction.__call__)N) rr/r0r rrrSrrrrr)r))rr*r 1sr c@s&eZdZd ddZddZdd ZdS) rrrNcCs||_||_||_||_dS)N)_mode_bufsize _encoding_errors)r"modebufsizeencodingerrorsr)r)r*rSszFileType.__init__c Cs|dkr>d|jkrtjSd|jkr(tjStd|j}t|yt||j|j|j|j St k r}ztd}t |||fWdd}~XYnXdS)N-r!wzargument "-" with mode %rzcan't open '%s': %s) r"r stdinr rr=rr#r$r%OSErrorr)r"stringrerr)r)r*rs  zFileType.__call__cCsT|j|jf}d|jfd|jfg}ddd|Ddd|D}dt|j|fS)Nr(r)z, cSsg|]}|dkrt|qS)r)r)rZr&r)r)r*r]sz%FileType.__repr__..cSs$g|]\}}|dk rd||fqS)Nz%s=%rr))rZkwr&r)r)r*r]sz%s(%s))r"r#r$r%r!rr)r"r\rargs_strr)r)r*r+s  zFileType.__repr__)r!rNN)rr/r0rSrr+r)r)r)r*rs c@s$eZdZddZddZddZdS)r cKs"x|D]}t||||qWdS)N)r)r"rr'r)r)r*rSs zNamespace.__init__cCst|tstSt|t|kS)N)rr NotImplementedr)r"otherr)r)r*__eq__s zNamespace.__eq__cCs ||jkS)N)r-)r"r r)r)r* __contains__szNamespace.__contains__N)rr/r0rSr4r5r)r)r)r*r scseZdZfddZddZd&ddZdd Zd d Zd d ZddZ ddZ ddZ ddZ ddZ ddZddZd'ddZddZd d!Zd"d#Zd$d%ZZS)(_ActionsContainercstt|||_||_||_||_i|_|ddt |ddt |ddt |ddt |ddt |ddt |ddt|ddt|dd t|dd t|dd t|g|_i|_g|_g|_i|_td |_g|_dS) Nrwstore store_const store_true store_falser append_constrrsrparsersz^-\d+$|^-\d*\.\d+$)rr6rS descriptionargument_default prefix_charsconflict_handler _registriesregisterrrrrrrrrrr  _get_handler_actions_option_string_actions_action_groups_mutually_exclusive_groups _defaultsrJrK_negative_number_matcher_has_negative_number_optionals)r"r=r?r>r@)rr)r*rSs2 z_ActionsContainer.__init__cCs|j|i}|||<dS)N)rAr)r" registry_namer(rregistryr)r)r*rBsz_ActionsContainer.registerNcCs|j|||S)N)rAr)r"rKr(rr)r)r* _registry_getsz_ActionsContainer._registry_getcKs6|j|x$|jD]}|j|kr||j|_qWdS)N)rHupdaterDrr)r"rrwr)r)r* set_defaultss   z_ActionsContainer.set_defaultscCs8x(|jD]}|j|kr|jdk r|jSqW|j|dS)N)rDrrrHr)r"rrwr)r)r* get_default&s  z_ActionsContainer.get_defaultcOs.|j}|r&t|dkrH|dd|krH|r:d|kr:td|j||}n |j||}d|kr|d}||jkr~|j||d<n|jdk r|j|d<||}t|std|f|f|}| d|j |j }t|std|ft |d r$y| |dWntk r"td YnX||S) NrTrrz+dest supplied twice for positional argumentrzunknown action "%s"rz%r is not callabler z,length of metavar tuple does not match nargs)r?rqr=_get_positional_kwargs_get_optional_kwargsrHr>_pop_action_classcallablerMrrr r TypeError _add_action)r"r\rcharsr action_classrw type_funcr)r)r*r}0s2          z_ActionsContainer.add_argumentcOs t|f||}|j||S)N)_ArgumentGrouprFr)r"r\rrr)r)r*add_argument_group_s z$_ActionsContainer.add_argument_groupcKst|f|}|j||S)N)_MutuallyExclusiveGrouprGr)r"rrr)r)r*add_mutually_exclusive_groupds  z._ActionsContainer.add_mutually_exclusive_groupcCsh|||j|||_x|jD]}||j|<q$Wx,|jD]"}|j|r>|js>|jdq>W|S)NT) _check_conflictrDr containerrrErImatchrJ)r"rwrr)r)r*rVis     z_ActionsContainer._add_actioncCs|j|dS)N)rDremove)r"rwr)r)r*_remove_action~sz _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]}| || |qWdS)Nz.cannot merge actions - two groups are named %r)titler=r@)r)rFrcrr=r[r=r@rrGr]rrDrrV)r"r_title_group_maprr group_maprw mutex_groupr)r)r*_add_container_actionss,         z(_ActionsContainer._add_container_actionscKs^d|krtd}t||dttgkr2d|d<|dtkrPd|krPd|d<t||gdS)Nrz1'required' is an invalid argument for positionalsrTr)rr)rrUrr rr)r"rrrr)r)r*rQsz(_ActionsContainer._get_positional_kwargsc Osg}g}xv|D]n}|d|jkr@||jd}td}t|||||d|jkrt|dkr|d|jkr||qW|dd}|dkr|r|d}n|d}||j}|std}t|||dd}t|||d S) Nr)optionr?zNinvalid option string %(option)r: must start with a character %(prefix_chars)rrTrz%dest= is required for options like %rr*r)rr) r?rr=rrqrlstripreplacer) r"r\rrlong_option_stringsrrrdest_option_stringr)r)r*rRs0          z&_ActionsContainer._get_optional_kwargscCs|d|}|d||S)Nrw)rrM)r"rrrwr)r)r*rSs z#_ActionsContainer._pop_action_classcCsDd|j}y t||Stk r>td}t||jYnXdS)Nz_handle_conflict_%sz%invalid conflict_resolution value: %r)r@rrrr=)r"handler_func_namerr)r)r*rCs   z_ActionsContainer._get_handlercCsPg}x0|jD]&}||jkr |j|}|||fq W|rL|}|||dS)N)rrErrC)r"rwconfl_optionalsrconfl_optionalr@r)r)r*r^s   z!_ActionsContainer._check_conflictcCs6tddt|}ddd|D}t|||dS)Nzconflicting option string: %szconflicting option strings: %sz, cSsg|] \}}|qSr)r))rZrrwr)r)r*r]sz<_ActionsContainer._handle_conflict_error..)rrqr!r)r"rwconflicting_actionsrconflict_stringr)r)r*_handle_conflict_errors    z(_ActionsContainer._handle_conflict_errorcCsBx<|D]4\}}|j||j|d|js|j|qWdS)N)rrarErr_rb)r"rwrprr)r)r*_handle_conflict_resolves  z*_ActionsContainer._handle_conflict_resolve)N)N)rr/r0rSrBrMrOrPr}r[r]rVrbrgrQrRrSrCr^rrrsrr)r))rr*r6s$ 4   /($   r6cs6eZdZdfdd ZfddZfddZZS) rZNc s|j}|d|j|d|j|d|jtt|j}|fd|i|||_g|_|j |_ |j |_ |j |_ |j |_ |j |_ |j|_dS)Nr@r?r>r=)rr@r?r>rrZrSrcrrArDrErHrJrG)r"r_rcr=rrN super_init)rr)r*rSs    z_ArgumentGroup.__init__cs tt||}|j||S)N)rrZrVrr)r"rw)rr)r*rV(s z_ArgumentGroup._add_actioncs tt|||j|dS)N)rrZrbrra)r"rw)rr)r*rb-sz_ArgumentGroup._remove_action)NN)rr/r0rSrVrbrr)r))rr*rZs rZcs.eZdZdfdd ZddZddZZS) r\Fcs tt||||_||_dS)N)rr\rSr _container)r"r_r)rr)r*rS4sz _MutuallyExclusiveGroup.__init__cCs2|jrtd}t||j|}|j||S)Nz-mutually exclusive arguments must be optional)rrr=rurVrr)r"rwrr)r)r*rV9s   z#_MutuallyExclusiveGroup._add_actioncCs|j||j|dS)N)rurbrra)r"rwr)r)r*rbAs z&_MutuallyExclusiveGroup._remove_action)F)rr/r0rSrVrbrr)r))rr*r\2sr\c s&eZdZddddgeddddddf fdd ZddZd d Zd d Zd dZddZ d@ddZ dAddZ ddZ ddZ ddZddZddZdd Zd!d"Zd#d$ZdBd%d&ZdCd'd(Zd)d*Zd+d,Zd-d.Zd/d0Zd1d2Zd3d4ZdDd5d6ZdEd7d8ZdFd9d:ZdGdd?Z Z!S)HrNr*errorTc  s&tt|j} | ||| | d|dkr6tjtjd}||_||_ ||_ ||_ ||_ | |_ | |_|j}|td|_|td|_d|_dd}|dd|d|krdn|d}|j r|j|d |d d d ttd d xD|D]<}||y |j}Wntk rYqX|j|qWdS)N)r=r?r>r@rzpositional argumentszoptional argumentscSs|S)Nr))r.r)r)r*identitysz)ArgumentParser.__init__..identityrr*hr4rszshow this help message and exit)rwrrs)rrrSr:pathbasenamer argvrOrlepilogformatter_classfromfile_prefix_charsadd_help allow_abbrevr[r _positionals _optionals _subparsersrBr}rrgrHrrN)r"rOrlr=r|parentsr}r?r~r>r@rr superinit add_grouprwdefault_prefixrXdefaults)rr)r*rSYsB     zArgumentParser.__init__cs"ddddddg}fdd|DS) NrOrlr=r}r@rcsg|]}|t|fqSr))r)rZr')r"r)r*r]sz.ArgumentParser._get_kwargs..r))r"rr))r"r*rszArgumentParser._get_kwargsc Ks|jdk r|td|dt|d|ks8d|krht|dd}t|dd}||||_n|j|_|ddkr| }| }|j }| |j ||d||d<||d}|fd gi|}|j||S) Nz(cannot have multiple subparser argumentsrrcr= subcommandsrOr^r<r)rrvrrrrr[rrr _get_positional_actionsrGrprlrcrrSrV) r"rrcr=rWrrn parsers_classrwr)r)r*add_subparserss$   zArgumentParser.add_subparserscCs$|jr|j|n |j||S)N)rrrVr)r"rwr)r)r*rVs zArgumentParser._add_actioncCsdd|jDS)NcSsg|]}|jr|qSr))r)rZrwr)r)r*r]sz8ArgumentParser._get_optional_actions..)rD)r"r)r)r*_get_optional_actionssz$ArgumentParser._get_optional_actionscCsdd|jDS)NcSsg|]}|js|qSr))r)rZrwr)r)r*r]sz:ArgumentParser._get_positional_actions..)rD)r"r)r)r*rsz&ArgumentParser._get_positional_actionscCs4|||\}}|r0td}||d||S)Nzunrecognized arguments: %sr)rrrvr!)r"r\rr{rr)r)r* parse_argss zArgumentParser.parse_argscCs |dkrtjdd}nt|}|dkr.t}x>|jD]4}|jtk r6t||js6|jtk r6t ||j|jq6Wx*|j D] }t||svt |||j |qvWy<| ||\}}t|t r| t|t t|t ||fStk rtd}|t|YnXdS)NrT)r r{r1r rDrrrrrrH_parse_known_argsrrrdelattrrexc_inforvr)r"r\rrwrerrr)r)r*rs,         zArgumentParser.parse_known_argscs" jdk r ix` jD]V}|j}xJt|jD]<\}}|g}||d||||ddq6Wq Wig}t} xnt| D]b\}} | dkr|dxF| D]} |dqWq | } | dkrd} n | |<d} || qWd |t t d fdd  fd d }  fd d }gd rpt }nd}x| |krt fddD} |kr| }| kr| qvn| kr |}|| |  qvW| }|dg}x jD]|}|kr|jr>|t|nT|jdk rt|jtrt|jr|jt|jkrt|j ||jqW|r tdd |xb jD]X}|jrxH|jD]}|krPqWdd|jD}td} |d |qWfS)NrTz--r*AOr^cs|||}||jk rf|x:|gD]*}|kr8td}t|}t|||q8W|tk r||||dS)Nznot allowed with argument %s)r _get_valuesrrrrrr)rwargument_stringsrargument_valuesconflict_actionr action_name)action_conflictsr seen_actionsseen_non_default_actionsr"r)r* take_action3s    z5ArgumentParser._parse_known_args..take_actioncs|}|\}}}j}g}x>|dkr>||dS|dk r||d}j}|dkr|d|kr||g|f|d} | |d}|ddpd} j} || kr| |}| }ntd} t|| |n@|dkr|d} |g}||||fPntd} t|| |q |d}|d}|||}||} || }||||fPq Wx |D]\}}}|||qdW| S)NrTrrzignored explicit argument %r)_match_argumentrr?rErr) start_index option_tuplerwr explicit_argmatch_argument action_tuples arg_countrWcharnew_explicit_arg optionals_maprstopr\rselected_patterns)r$arg_strings_patternextrasoption_string_indicesr"rr)r*consume_optionalHsN       z:ArgumentParser._parse_known_args..consume_optionalcsrj}|d}||}x8t|D]*\}}|||}||7}||q(Wt|ddd<|S)N)_match_arguments_partialziprq)r match_partialselected_pattern arg_countsrwrr\)r$rrr"rr)r*consume_positionalss  z=ArgumentParser._parse_known_args..consume_positionalsrrcsg|]}|kr|qSr)r))rZr)rr)r*r]sz4ArgumentParser._parse_known_args..z(the following arguments are required: %sz, cSsg|]}|jtk rt|qSr))rsrr)rZrwr)r)r*r]sz#one of the arguments %s is requiredr)N)r~_read_args_from_filesrGrrrriterr_parse_optionalr!rrrBrArDrrrrrrrrr _get_valuervr)r"r$rrfrr mutex_action conflictsarg_string_pattern_partsarg_strings_iter arg_stringrpatternrrmax_option_string_indexnext_option_string_indexpositionals_end_indexstrings stop_indexrequired_actionsrwrrrr)) rr$rrrrrrrr"rrr*rs        J                 z ArgumentParser._parse_known_argsc Csg}x|D]}|r |d|jkr,||q ylt|ddR}g}x2|D]"}x||D]}||qbWqRW||}||WdQRXWq tk rt d}| t |Yq Xq W|S)NrrT) r~rrreadrconvert_arg_line_to_argsrrr-r rrvr)r"r$new_arg_stringsr args_filearg_liner&rr)r)r*rs     z$ArgumentParser._read_args_from_filescCs|gS)Nr))r"rr)r)r*rsz'ArgumentParser.convert_arg_line_to_argscCsz||}t||}|dkrldtdttdttdi}||j}|dkrbtdd|j|j}t ||t | dS)Nzexpected one argumentzexpected at most one argumentzexpected at least one argumentzexpected %s argumentzexpected %s argumentsrT) _get_nargs_patternrJr`rr r rrrrrqr)r"rwr nargs_patternr` nargs_errorsrr)r)r*rs     zArgumentParser._match_argumentcstg}xjtt|ddD]V}|d|}dfdd|D}t||}|dk r|dd|DPqW|S)Nrrr^csg|]}|qSr))r)rZrw)r"r)r*r]3sz;ArgumentParser._match_arguments_partial..cSsg|] }t|qSr))rq)rZr.r)r)r*r]7s)rrqr!rJr`rrn)r"rmrrr actions_slicerr`r))r"r*r-s   z'ArgumentParser._match_arguments_partialc Cs|sdS|d|jkrdS||jkr8|j|}||dfSt|dkrHdSd|kr~|dd\}}||jkr~|j|}|||fS|jr||}t|dkrddd|D}||d}td}|||nt|dkr|\} | S|j |r|j sdSd |kr dSd|dfS) NrrT=z, cSsg|]\}}}|qSr)r))rZrwrrr)r)r*r]]sz2ArgumentParser._parse_optional..)rhmatchesz4ambiguous option: %(option)s could match %(matches)sr) r?rErqsplitr_get_option_tuplesr!rrvrIr`rJ) r"rrwrr option_tuplesoptionsr\rrr)r)r*r=s>               zArgumentParser._parse_optionalc Cs2g}|j}|d|kr~|d|kr~d|kr<|dd\}}n|}d}x|jD],}||rL|j|}|||f}||qLWn|d|kr|d|kr|}d}|dd}|dd} xr|jD]T}||kr|j|}||| f}||q||r|j|}|||f}||qWn|td||S)NrrTrr4zunexpected option string: %s)r?rrE startswithrrvr) r"rrrW option_prefixrrwrshort_option_prefixshort_explicit_argr)r)r*rxs8             z!ArgumentParser._get_option_tuplescCs|j}|dkrd}nf|tkr"d}nX|tkr0d}nJ|tkr>d}n<|tkrLd}n.|tkrZd}n |tkrhd}ndd d |}|jr| d d }| d d }|S) Nz(-*A-*)z(-*A?-*)z (-*[A-]*)z (-*A[A-]*)z([-AO]*)z (-*A[-AO]*)z(-*-*)z(-*%s-*)z-*rr^r*) rr rr rrrr!rrj)r"rwrrr)r)r*rs(  z!ArgumentParser._get_nargs_patterncCs4|||\}}|r0td}||d||S)Nzunrecognized arguments: %sr)parse_known_intermixed_argsrrvr!)r"r\rr{rr)r)r*parse_intermixed_argss z$ArgumentParser.parse_intermixed_argsc s|ddD}|r,td|djfdd|jDrHtdzl|j}z|jdkrp|dd|_x(D] }|j|_t|_|j|_ t|_qvW| ||\}}xRD]J}t ||j rt ||j gkrddlm}|d |j |ft||j qWWdxD]}|j|_|j |_qWX|}zRx|D]}|j|_d |_q4Wx|jD]} | j| _d | _qTW| ||\}} Wdx|D]}|j|_qWx|jD]} | j| _qWXWd||_X|| fS) NcSsg|]}|jttgkr|qSr))rrr)rZrwr)r)r*r]sz>ArgumentParser.parse_known_intermixed_args..z3parse_intermixed_args: positional arg with nargs=%srcs&g|]}|jD]}|kr|jqqSr))rr)rZrrw)rr)r*r]sz;parse_intermixed_args: positional in mutuallyExclusiveGroup)warnzDo not expect %s in %sF)rrUrrGrl format_usage save_nargsrr save_defaultrrrrwarningsrrrr save_required) r"r\ra save_usagerwremaining_argsrrrrr))rr*rsX               z*ArgumentParser.parse_known_intermixed_argscsjttgkr2y|dWntk r0YnX|szjtkrzjrNj}nj}t |t rv |} |n|sjt krjsjdk rj}n|} |nt|dkrjdtgkr|\} |} |njtkrfdd|D}ntjtkr@fdd|D} |dnBjtkrRt}n0fdd|D}x|D]} |qlW|S)Nz--rTcsg|]}|qSr))r)rZv)rwr"r)r*r]M sz.ArgumentParser._get_values..csg|]}|qSr))r)rZr)rwr"r)r*r]Q srcsg|]}|qSr))r)rZr)rwr"r)r*r]Z s)rrrrar=r rrrrrr _check_valuerrqr)r"rwr$r(rrr))rwr"r*r) sB        zArgumentParser._get_valuesc Cs|d|j|j}t|s0td}t|||y ||}Wntk r~t|jdt|j}tt d}t||YnLt t fk rt|jdt|j}||d}td}t|||YnX|S)Nrz%r is not callablerrT)rr(z!invalid %(type)s value: %(value)r) rMrrTrrrrrrr rrUr=)r"rwrrYrrr'r\r)r)r*ra s   zArgumentParser._get_valuecCsF|jdk rB||jkrB|dtt|jd}td}t|||dS)Nz, )r(rz3invalid choice: %(value)r (choose from %(choices)s))rr!maprrr)r"rwr(r\rr)r)r*r{ s zArgumentParser._check_valuecCs$|}||j|j|j|S)N)r rprlrDrGrc)r"rWr)r)r*r s zArgumentParser.format_usagecCsx|}||j|j|j||jx:|jD]0}||j ||j| |j | q0W||j |S)N)r rprlrDrGrjr=rFrfrcr~rrgr|rc)r"rW action_groupr)r)r*rc s        zArgumentParser.format_helpcCs|j|jdS)N)rO)r}rO)r"r)r)r*r  szArgumentParser._get_formattercCs"|dkrtj}|||dS)N)r r r r)r"filer)r)r* print_usage szArgumentParser.print_usagecCs"|dkrtj}|||dS)N)r r r rc)r"rr)r)r*r szArgumentParser.print_helpcCs |r|dkrtj}||dS)N)r stderrwrite)r"rrr)r)r*r  szArgumentParser._print_messagercCs |r||tjt|dS)N)r r rr)r"statusrr)r)r*r szArgumentParser.exitcCs0|tj|j|d}|dtd|dS)N)rOrr4z%(prog)s: error: %(message)s )rr rrOrr)r"rr\r)r)r*rv s  zArgumentParser.error)NN)NN)NN)NN)N)N)N)rN)"rr/r0rrSrrrVrrrrrrrrrrrrrrrrrrrcr rrr rrvrr)r))rr*rFsR4  #w;,1  M8    )/ __version____all__osr:rerJsysr rrrrr rr rrrrrr3rrrrr r Exceptionrrr rrrrrrrrrr rr r6rZr\rr)r)r)r*@sx{    [#&b65"