3 \xEã@sàddlZddlZddlZddlZddlTdZejdeƒZejdeefƒZe j ddƒZ Gdd „d ƒZ d d „Z d d „ejDƒZdd„Zdd„ZGdd„dƒZedkrÜdZx2dD]*Zedeƒedjeeeƒƒƒeƒq®WdS)éN)Ú*z[a-zA-Z](?:[a-zA-Z0-9-]*)z^%s$z ^(%s)=!(%s)$ú-Ú_c@s†eZdZddd„Zdd„Zdd„Zddd „Zd d „Zd d „Zdd„Z dd„Z dd„Z dd„Z d dd„Z dd„Zd!dd„Zd"dd„ZdS)#Ú FancyGetoptNcCsN||_i|_|jr|jƒi|_i|_g|_g|_i|_i|_i|_ g|_ dS)N) Ú option_tableÚ option_indexÚ _build_indexÚaliasÚnegative_aliasÚ short_optsÚ long_optsÚ short2longÚ attr_nameÚ takes_argÚ option_order)Úselfr©rú./usr/lib64/python3.6/distutils/fancy_getopt.pyÚ__init__)s zFancyGetopt.__init__cCs,|jjƒx|jD]}||j|d<qWdS)Nr)rÚclearr)rÚoptionrrrrQs  zFancyGetopt._build_indexcCs||_|jƒdS)N)rr)rrrrrÚset_option_tableVszFancyGetopt.set_option_tablecCs<||jkrtd|ƒ‚n |||f}|jj|ƒ||j|<dS)Nz'option conflict: already an option '%s')rÚDistutilsGetoptErrorrÚappend)rÚ long_optionZ short_optionZ help_stringrrrrÚ add_optionZs     zFancyGetopt.add_optioncCs ||jkS)N)r)rrrrrÚ has_optioncszFancyGetopt.has_optioncCs |jtƒS)N)Ú translateÚ longopt_xlate)rrrrrÚ get_attr_namehszFancyGetopt.get_attr_namecCsRxL|jƒD]@\}}||jkr.td|||fƒ‚||jkr td|||fƒ‚q WdS)Nz(invalid %s '%s': option '%s' not definedz0invalid %s '%s': aliased option '%s' not defined)Úitemsrr)rÚaliasesZwhatr ÚoptrrrÚ_check_alias_dictns  zFancyGetopt._check_alias_dictcCs|j|dƒ||_dS)Nr )r#r )rr rrrÚ set_aliasesxs zFancyGetopt.set_aliasescCs|j|dƒ||_dS)Nznegative alias)r#r )rr rrrÚset_negative_aliases}s z FancyGetopt.set_negative_aliasescCsÖg|_g|_|jjƒi|_�x²|jD�]¦}t|ƒdkrH|\}}}d}n(t|ƒdkrb|\}}}}ntd|fƒ‚t|t ƒ sˆt|ƒdkr”t d|ƒ‚|dkp°t|t ƒo°t|ƒdks¾t d|ƒ‚||j|<|jj |ƒ|dd k�r|rî|d }|dd…}d|j |<nF|j j|ƒ}|dk �rB|j |�r8t d ||fƒ‚||jd<d|j |<|jj|ƒ}|dk �rˆ|j ||j |k�rˆt d ||fƒ‚tj|ƒ�s t d |ƒ‚|j|ƒ|j|<|r&|jj |ƒ||j|d<q&WdS)Nérézinvalid option tuple: %réz9invalid long option '%s': must be a string of length >= 2éz:invalid short option '%s': must a single character or Noneú=ú:z>invalid negative alias '%s': aliased option '%s' takes a valuezginvalid alias '%s': inconsistent with aliased option '%s' (one of them takes a value, the other doesn'tzEinvalid long option name '%s' (must be letters, numbers, hyphens onlyéÿÿÿÿr,r,)r r r rÚrepeatrÚlenÚ ValueErrorÚ isinstanceÚstrrrrr Úgetr Ú longopt_reÚmatchrr)rrÚlongÚshortÚhelpr-Zalias_torrrÚ_grok_option_table…s^                   zFancyGetopt._grok_option_tablec Csr|dkrtjdd…}|dkr*tƒ}d}nd}|jƒdj|jƒ}ytj|||jƒ\}}Wn,tjk r†}zt |ƒ‚WYdd}~XnXxÒ|D]Ê\}}t |ƒdkr¾|ddkr¾|j |d}n |dd…}|j j |ƒ} | rÞ| }|j|�s |jj |ƒ} | �r| }d}nd}|j|} |�r<|jj | ƒdk �rÒsB        zFancyGetopt.getoptcCs|jdkrtdƒ‚n|jSdS)Nz!'getopt()' hasn't been called yet)rÚ RuntimeError)rrrrÚget_option_orders  zFancyGetopt.get_option_ordercCsxd}xV|jD]L}|d}|d}t|ƒ}|ddkr<|d}|dk rL|d}||kr |}q W|ddd}d}||} d|} |rŒ|g} ndg} xà|jD]Ö}|dd …\}}} t| | ƒ} |ddkrÒ|dd…}|dk�r| �rü| jd ||| dfƒn| jd ||fƒn:d ||f}| �r<| jd ||| dfƒn| jd |ƒx$| dd…D]}| j| |ƒ�qXWqšW| S)Nrr)r*ér(éNr9zOption summary:r&z --%-*s %sz --%-*s z%s (-%s)z --%-*sr,r,r,)rr.Ú wrap_textr)rÚheaderZmax_optrr5r6ÚlZ opt_widthZ line_widthZ text_widthZ big_indentÚlinesr7ÚtextZ opt_namesrrrÚ generate_helpsF        zFancyGetopt.generate_helpcCs4|dkrtj}x |j|ƒD]}|j|dƒqWdS)NÚ )r:ÚstdoutrPÚwrite)rrLÚfileÚlinerrrÚ print_helphszFancyGetopt.print_help)N)NN)NN)N)NN)Ú__name__Ú __module__Ú __qualname__rrrrrrr#r$r%r8r>rHrPrVrrrrrs (  M = OrcCst|ƒ}|j|ƒ|j||ƒS)N)rr%r>)ÚoptionsZ negative_optrCrBÚparserrrrÚ fancy_getoptos r\cCsi|]}dt|ƒ“qS)r9)Úord)Ú.0Z_wscharrrrú usr_cCs"|dkr gSt|ƒ|kr|gS|jƒ}|jtƒ}tjd|ƒ}dd„|Dƒ}g}xÎ|�rg}d}xZ|r¸t|dƒ}|||krš|j|dƒ|d=||}q`|r´|dddkr´|d =Pq`W|�r |dkrò|j|dd|…ƒ|d|d…|d<|dddk�r |d=|jdj|ƒƒqPW|S) Nz( +|-+)cSsg|] }|r|‘qSrr)r^Zchrrrú …szwrap_text..rr)r9Úr,r,)r.Ú expandtabsrÚWS_TRANSÚreÚsplitrr=)rOÚwidthZchunksrNZcur_lineZcur_lenrMrrrrKws:      rKcCs |jtƒS)N)rr)r"rrrÚtranslate_longopt­srgc@seZdZgfdd„ZdS)r<cCsx|D]}t||dƒqWdS)N)rA)rrZr"rrrr¸s zOptionDummy.__init__N)rWrXrYrrrrrr<´sr<Ú__main__z¢Tra-la-la, supercalifragilisticexpialidocious. How *do* you spell that odd word, anyways? (Someone ask Mary -- she'll know [or she'll say, "How should I know?"].)é ééé(z width: %drQ)rirjrkrl)r:Ústringrdr>Zdistutils.errorsZ longopt_patÚcompiler3Z neg_alias_rer1Ú maketransrrr\Z whitespacercrKrgr<rWrOÚwÚprintr=rrrrÚ s( T6