o
    5‘ðiçE  ã                   @  s  d Z ddlmZ ddlZddlZddlZddlZddlmZ ddl	m
Z
 ddlmZmZ dZe d	e› d
�¡Ze de› de› d�¡Ze dd¡ZG dd„ dƒZd#dd„Zdd„ ejD ƒZdd„ Zdd„ ZG dd„ dƒZedkr‹dZd D ]Zed!e› �ƒ ed"  eeeƒ¡ƒ eƒ  qtdS dS )$a6  distutils.fancy_getopt

Wrapper around the standard getopt module that provides the following
additional features:
  * short and long options are tied together
  * options have help strings, so fancy_getopt could potentially
    create a complete usage summary
  * options set attributes of a passed-in object
é    )ÚannotationsN)ÚSequence)ÚAnyé   )ÚDistutilsArgErrorÚDistutilsGetoptErrorz[a-zA-Z](?:[a-zA-Z0-9-]*)ú^ú$z^(z)=!(z)$ú-Ú_c                   @  sŒ   e Zd ZdZd!dd„Zdd„ Zdd„ Zd"d	d
„Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zd"d#dd„Zdd„ Zd!dd„Zd"dd „ZdS )$ÚFancyGetoptaÕ  Wrapper around the standard 'getopt()' module that provides some
    handy extra functionality:
      * short and long options are tied together
      * options have help strings, and help text can be assembled
        from them
      * options set attributes of a passed-in object
      * boolean options can have "negative aliases" -- eg. if
        --quiet is the "negative alias" of --verbose, then "--quiet"
        on the command line sets 'verbose' to false
    Nc                 C  sN   || _ i | _| j r|  ¡  i | _i | _g | _g | _i | _i | _i | _	g | _
d S ©N)Úoption_tableÚoption_indexÚ_build_indexÚaliasÚnegative_aliasÚ
short_optsÚ	long_optsÚ
short2longÚ	attr_nameÚ	takes_argÚoption_order©Úselfr   © r   úa/root/parts/websockify/install/lib/python3.10/site-packages/setuptools/_distutils/fancy_getopt.pyÚ__init__1   s   	
zFancyGetopt.__init__c                 C  s(   | j  ¡  | jD ]	}|| j |d < qd S )Nr   )r   Úclearr   )r   Úoptionr   r   r   r   Y   s   

ÿzFancyGetopt._build_indexc                 C  s   || _ |  ¡  d S r   )r   r   r   r   r   r   Úset_option_table^   s   zFancyGetopt.set_option_tablec                 C  s>   || j v rtd|› d�ƒ‚|||f}| j |¡ || j |< d S )Nz$option conflict: already an option 'ú')r   r   r   Úappend)r   Úlong_optionÚshort_optionÚhelp_stringr   r   r   r   Ú
add_optionb   s   

ÿ
zFancyGetopt.add_optionc                 C  s
   || j v S )zcReturn true if the option table for this parser has an
        option with long name 'long_option'.)r   ©r   r#   r   r   r   Ú
has_optionl   s   
zFancyGetopt.has_optionc                 C  s
   |  t¡S )z’Translate long option name 'long_option' to the form it
        has as an attribute of some object: ie., translate hyphens
        to underscores.©Ú	translateÚlongopt_xlater'   r   r   r   Úget_attr_nameq   ó   
zFancyGetopt.get_attr_namec              	   C  sp   t |tƒsJ ‚| ¡ D ]*\}}|| jvr"td|› d|› d|› d�ƒ‚|| jvr5td|› d|› d|› d�ƒ‚qd S )Nzinvalid z 'z': option 'z' not definedú': aliased option ')Ú
isinstanceÚdictÚitemsr   r   )r   ÚaliasesÚwhatr   Úoptr   r   r   Ú_check_alias_dictw   s   
ÿ
ÿÿûzFancyGetopt._check_alias_dictc                 C  ó   |   |d¡ || _dS )z'Set the aliases for this option parser.r   N)r5   r   )r   r   r   r   r   Úset_aliasesƒ   s   
zFancyGetopt.set_aliasesc                 C  r6   )zÚSet the negative aliases for this option parser.
        'negative_alias' should be a dictionary mapping option names to
        option names, both the key and value must already be defined
        in the option table.znegative aliasN)r5   r   )r   r   r   r   r   Úset_negative_aliasesˆ   s   
z FancyGetopt.set_negative_aliasesc                 C  sØ  g | _ g | _| j ¡  i | _| jD ]Ø}t|ƒdkr!|\}}}d}nt|ƒdkr.|\}}}}ntd|›�ƒ‚t|t	ƒr@t|ƒdk rHt
d|› d�ƒ‚|du s_t|t	ƒrWt|ƒd	ks_t
d
|› d�ƒ‚|| j|< | j  |¡ |d dkr‚|rv|d }|dd… }d| j|< n$| j |¡}|dur¡| j| rœt
d|› d|› d�ƒ‚|| j d< d| j|< | j |¡}|durÅ| j| | j| krÅt
d|› d|› d�ƒ‚t |¡sÒt
d|› d�ƒ‚|  |¡| j|< |ré| j |¡ || j|d < qdS )z�Populate the various data structures that keep tabs on the
        option table.  Called by 'getopt()' before it can do anything
        worthwhile.
        é   r   é   zinvalid option tuple: é   zinvalid long option 'z"': must be a string of length >= 2Nr   zinvalid short option 'z"': must a single character or Noneéÿÿÿÿú=ú:Tzinvalid negative alias 'r.   z' takes a valueFzinvalid alias 'z%': inconsistent with aliased option 'z/' (one of them takes a value, the other doesn'tzinvalid long option name 'z)' (must be letters, numbers, hyphens only)r   r   r   r   Úrepeatr   ÚlenÚ
ValueErrorr/   Ústrr   r"   r   r   Úgetr   Ú
longopt_reÚmatchr,   r   )r   r   ÚlongÚshortÚhelpr?   Úalias_tor   r   r   Ú_grok_option_table�   sl   



ÿ
ÿ

ÿÿ

ÿÿ


ÿ€¼zFancyGetopt._grok_option_tableÚargsúSequence[str] | Nonec              
   C  s†  |du rt jdd… }|du rtƒ }d}nd}|  ¡  d | j¡}zt ||| j¡\}}W n tjy> } zt	|ƒ‚d}~ww |D ]y\}}t
|ƒdkrY|d dkrY| j|d  }nt
|ƒdkrg|dd… d	ksiJ ‚|dd… }| j |¡}	|	ry|	}| j| s•|d
ks†J dƒ‚| j |¡}	|	r“|	}d}nd}| j| }
|r¬| j |
¡dur¬t||
dƒd }t||
|ƒ | j ||f¡ qA|rÁ||fS |S )a  Parse command-line options in args. Store as attributes on object.

        If 'args' is None or not supplied, uses 'sys.argv[1:]'.  If
        'object' is None or not supplied, creates a new OptionDummy
        object, stores option values there, and returns a tuple (args,
        object).  If 'object' is supplied, it is modified in place and
        'getopt()' just returns 'args'; in both cases, the returned
        'args' is a modified copy of the passed-in 'args' list, which
        is left untouched.
        Nr   TFú r;   r   r
   z--Ú zboolean option can't have value)ÚsysÚargvÚOptionDummyrJ   Újoinr   Úgetoptr   Úerrorr   r@   r   r   rC   r   r   r   r?   ÚgetattrÚsetattrr   r"   )r   rK   ÚobjectÚcreated_objectr   ÚoptsÚmsgr4   Úvalr   Úattrr   r   r   rS   à   sJ   €ÿ 

zFancyGetopt.getoptc                 C  s   | j du r	tdƒ‚| j S )z«Returns the list of (option, value) tuples processed by the
        previous run of 'getopt()'.  Raises RuntimeError if
        'getopt()' hasn't been called yet.
        Nz!'getopt()' hasn't been called yet)r   ÚRuntimeError)r   r   r   r   Úget_option_order  s   
zFancyGetopt.get_option_orderc                 C  sŒ  d}| j D ]&}|d }|d }t|ƒ}|d dkr|d }|dur%|d }||kr+|}q|d d d }d}|| }	d	| }
|rD|g}nd
g}| j D ]y}|dd… \}}}t||	ƒ}|d dkrf|dd… }|du r‹|r~| d|d|› �›d|d › �¡ n5| d|d|› �›�¡ n(|› d|› d�}|r§| d|d|› �›d|d › �¡ n| d|d|› �›�¡ |dd… D ]	}| |
| ¡ q¹qJ|S )zŒGenerate help text (a list of strings, one per suggested line of
        output) from the option table for this FancyGetopt object.
        r   r   r<   r=   Né   r;   éN   rM   zOption summary:r9   z  --ú<z  z (-ú))r   r@   Ú	wrap_textr"   )r   ÚheaderÚmax_optr   rF   rG   ÚellÚ	opt_widthÚ
line_widthÚ
text_widthÚ
big_indentÚlinesrH   ÚtextÚ	opt_namesr   r   r   Úgenerate_help'  sH   
€

$$ÿzFancyGetopt.generate_helpc                 C  s0   |d u rt j}|  |¡D ]	}| |d ¡ qd S )NÚ
)rO   Ústdoutrn   Úwrite)r   rd   ÚfileÚliner   r   r   Ú
print_helpu  s
   ÿzFancyGetopt.print_helpr   )NN©rK   rL   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r    r&   r(   r,   r5   r7   r8   rJ   rS   r^   rn   rt   r   r   r   r   r   %   s     
(

P=

Nr   rK   rL   c                 C  s   t | ƒ}| |¡ | ||¡S r   )r   r8   rS   )ÚoptionsÚnegative_optrW   rK   Úparserr   r   r   Úfancy_getopt|  s   
r}   c                 C  s   i | ]}t |ƒd “qS )rM   )Úord)Ú.0Ú_wscharr   r   r   Ú
<dictcomp>‚  s    r�   c                 C  s  | du rg S t | ƒ|kr| gS |  ¡ } |  t¡} t d| ¡}dd„ |D ƒ}g }|rŠg }d}|rZt |d ƒ}|| |krJ| |d ¡ |d= || }n|rW|d d dkrW|d= n|s/|r€|dkru| |d d|… ¡ |d |d… |d< |d d dkr€|d= | d |¡¡ |s)|S )	z¶wrap_text(text : string, width : int) -> [string]

    Split 'text' into multiple lines of no more than 'width' characters
    each, and return the list of strings that results.
    Nz( +|-+)c                 S  s   g | ]}|r|‘qS r   r   )r   Úchr   r   r   Ú
<listcomp>“  s    zwrap_text.<locals>.<listcomp>r   r<   rM   rN   )r@   Ú
expandtabsr*   ÚWS_TRANSÚreÚsplitr"   rR   )rl   ÚwidthÚchunksrk   Úcur_lineÚcur_lenrf   r   r   r   rc   …  s>   

öà"rc   c                 C  s
   |   t¡S )zXConvert a long option name to a valid Python identifier by
    changing "-" to "_".
    r)   )r4   r   r   r   Útranslate_longopt»  r-   rŒ   c                   @  s   e Zd ZdZg fddd„ZdS )rQ   z_Dummy class just used as a place to hold command-line option
    values as instance attributes.rz   úSequence[Any]c                 C  s   |D ]}t | |dƒ qdS )zkCreate a new OptionDummy instance.  The attributes listed in
        'options' will be initialized to None.N)rV   )r   rz   r4   r   r   r   r   Æ  s   ÿzOptionDummy.__init__N)rz   r�   )rv   rw   rx   ry   r   r   r   r   r   rQ   Â  s    rQ   Ú__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: ro   ru   )!ry   Ú
__future__r   rS   r†   ÚstringrO   Úcollections.abcr   Útypingr   Úerrorsr   r   Úlongopt_patÚcompilerD   Úneg_alias_rerB   Ú	maketransr+   r   r}   Ú
whitespacer…   rc   rŒ   rQ   rv   rl   ÚwÚprintrR   r   r   r   r   Ú<module>   s:    
  
Y6ö