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