o
    ^ôj4  ã                   @   sâ  U d Z ddlmZmZ ddlZddlZddlZddlZddlZddl	m
Z
mZ ddlmZ dZeed< dZeed	< d
Zeed< e d¡Zeeje ƒhZee ed< dZe
ed< dZejdB ed< G dd„ deƒZdee e
f dedB fdd„Z!defdd„Z"de fdd„Z#dej$de de
dej%fdd„Z&defdd „Z'd!e d"ee  de(e  fd#d$„Z)d%d&„ Z*		'	d7d(e d)edB d*e d+e dB de f
d,d-„Z+	d8d.ee e
f d/ee  dB dee  fd0d1„Z,d2e de fd3d4„Z-de de fd5d6„Z.dS )9z:Internal helper functions for Abseil Python flags library.é    )ÚIterableÚSequenceN)ÚAnyÚ
NamedTuple)ÚminidoméP   Ú_DEFAULT_HELP_WIDTHé(   Ú_MIN_HELP_WIDTHg      à?Ú _SUGGESTION_ERROR_RATE_THRESHOLDu    [ ---Â„Â†-ÂŸí €-í¿¿ï¿¾ï¿¿]Údisclaim_module_idsÚSPECIAL_FLAGSÚFLAGS_MODULEc                   @   s$   e Zd ZU dZejed< eed< dS )Ú_ModuleObjectAndNamezkModule object and name.

  Fields:
  - module: object, module object.
  - module_name: str, module name.
  ÚmoduleÚmodule_nameN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚtypesÚ
ModuleTypeÚ__annotations__Ústr© r   r   úd/var/www/html/academy/tools/voices/clone/sv-venv/lib/python3.10/site-packages/absl/flags/_helpers.pyr   F   s   
 
r   Úglobals_dictÚreturnc                 C   sJ   z| d }t j| }W n
 ty   Y dS w t||dkr"t jd ƒS |ƒS )aF  Returns the module that defines a global environment, and its name.

  Args:
    globals_dict: A dictionary that should correspond to an environment
      providing the values of the globals.

  Returns:
    _ModuleObjectAndName - pair of module object & module name.
    Returns None if the module could not be identified.
  r   NÚ__main__r   )ÚsysÚmodulesÚKeyErrorr   Úargv)r   Únamer   r   r   r   Úget_module_object_and_nameR   s   ÿÿÿr$   c                  C   sN   t dt ¡ ƒD ]} t | ¡j}t|ƒ}|dur"t|jƒtvr"|  S qt	dƒ‚)a)  Returns the module that's calling into this module.

  We generally use this function to get the name of the module calling a
  DEFINE_foo... function.

  Returns:
    The module object that called into this one.

  Raises:
    AssertionError: Raised when no calling module could be identified.
  é   NzNo module was found)
Úranger   ÚgetrecursionlimitÚ	_getframeÚ	f_globalsr$   Úidr   r   ÚAssertionError)ÚdepthZglobals_for_framer   r   r   r   Ú"get_calling_module_object_and_namej   s   €r-   c                   C   s   t ƒ jS )z?Returns the name of the module that's calling into this module.)r-   r   r   r   r   r   Úget_calling_module€   s   r.   Údocr#   Úvaluec                 C   sD   t |ƒ}t|tƒr| ¡ }t d|¡}|  |¡}| |  |¡¡ |S )aˆ  Returns an XML DOM element with name and text value.

  Args:
    doc: minidom.Document, the DOM document it should create nodes from.
    name: str, the tag of XML element.
    value: object, whose string representation will be used as the value of the
      XML element. Illegal or highly discouraged xml 1.0 characters are
      stripped.

  Returns:
    An instance of minidom.Element.
  Ú )	r   Ú
isinstanceÚboolÚlowerÚ_ILLEGAL_XML_CHARS_REGEXÚsubÚcreateElementÚappendChildÚcreateTextNode)r/   r#   r0   ÚsÚer   r   r   Úcreate_xml_dom_element…   s   

r<   c                  C   s   t jtdfd�} | jS )zAReturns the integer width of help lines that is used in TextWrap.r%   )Úfallback)ÚshutilÚget_terminal_sizer   Úcolumns)Úsizer   r   r   Úget_help_width¡   s   rB   ÚattemptÚlongopt_listc           	         sŠ   t ˆ ƒdks|s
g S dd„ |D ƒ}‡ fdd„|D ƒ}| ¡  |d \}}|tt ˆ ƒ kr.g S g }|D ]\}}||kr@| |¡ q2 |S |S )z4Returns helpful similar matches for an invalid flag.é   c                 S   s   g | ]	}|  d ¡d ‘qS )ú=r   )Úsplit)Ú.0Úvr   r   r   Ú
<listcomp>¯   s    z(get_flag_suggestions.<locals>.<listcomp>c                    s&   g | ]}t ˆ |d tˆ ƒ… ƒ|f‘qS )r   )Ú_damerau_levenshteinÚlen)rH   Úoption©rC   r   r   rJ   ³   s    ÿÿr   )rL   Úsortr   Úappend)	rC   rD   Zoption_namesÚ	distancesZleast_errorsÚ_ZsuggestionsÚerrorsr#   r   rN   r   Úget_flag_suggestions§   s    
þrT   c                    s   i ‰‡ ‡fdd„‰ ˆ | |ƒS )z6Returns Damerau-Levenshtein edit distance from a to b.c                    sü   | |fˆv rˆ| |f S | st |ƒ}nc|st | ƒ}n\tˆ | dd… |ƒd ˆ | |dd… ƒd ˆ | dd… |dd… ƒ| d |d k ƒ}t | ƒdkrvt |ƒdkrv| d |d krv| d |d krvˆ | dd… |dd… ƒd }||krv|}|ˆ| |f< |S )z5Recursively defined string distance with memoization.r%   Nr   rE   )rL   Úmin)ÚxÚyÚdÚt©ÚdistanceÚmemor   r   r[   Ì   s"   

(ý8z&_damerau_levenshtein.<locals>.distancer   )ÚaÚbr   rZ   r   rK   È   s   
rK   r1   ÚtextÚlengthÚindentÚfirstline_indentc                 C   sÂ   |du rt ƒ }|du rd}|du r|}t|ƒ|krtdƒ‚t|ƒ|kr'tdƒ‚|  d¡} g }tj|||d�}tj|||d�}dd„ |  ¡ D ƒD ]}|rT| | |¡¡ n| 	d¡ |}qGd	 
|¡S )
a:  Wraps a given text to a maximum line length and returns it.

  It turns lines that only contain whitespace into empty lines, keeps new lines,
  and expands tabs using 4 spaces.

  Args:
    text: Text to wrap.
    length: Maximum length of a line, includes indentation. If this is `None`
      then use `get_help_width()`.
    indent: Indent for all but first line.
    firstline_indent: Indent for first line. If `None`, fall back to `indent`.

  Returns:
    The wrapped text.

  Raises:
    ValueError: Raised if indent or firstline_indent not shorter than length.
  Nr1   zLength of indent exceeds lengthz*Length of first line indent exceeds lengthé   )ÚwidthÚinitial_indentÚsubsequent_indentc                 s   s   � | ]}|  ¡ V  qd S ©N)Ústrip)rH   Úpr   r   r   Ú	<genexpr>  ó   € ztext_wrap.<locals>.<genexpr>Ú
)rB   rL   Ú
ValueErrorÚ
expandtabsÚtextwrapÚTextWrapperÚ
splitlinesÚextendÚwraprP   Újoin)r_   r`   ra   rb   ÚresultÚwrapperZsubsequent_wrapperÚ	paragraphr   r   r   Ú	text_wrapæ   s0   
ÿÿ

rx   Úflag_mapÚmulti_flagsc              	   c   sî   � |   ¡ D ]o\}}|du rd|› �V  qt|tƒr)|r"d|› �V  qd|› �V  qt|ttfƒr:d|› d|› �V  qz(|rP||v rP|D ]}d|› d|› �V  qCnd|› dd dd„ |D ƒ¡› �V  W q tyt   d|› d|› �V  Y qw dS )a2  Convert a dict of values into process call parameters.

  This method is used to convert a dictionary into a sequence of parameters
  for a binary that parses arguments using this module.

  Args:
    flag_map: dict, a mapping where the keys are flag names (strings).
        values are treated according to their type:

        * If value is ``None``, then only the name is emitted.
        * If value is ``True``, then only the name is emitted.
        * If value is ``False``, then only the name prepended with 'no' is
          emitted.
        * If value is a string then ``--name=value`` is emitted.
        * If value is a collection, this will emit
          ``--name=value1,value2,value3``, unless the flag name is in
          ``multi_flags``, in which case this will emit
          ``--name=value1 --name=value2 --name=value3``.
        * Everything else is converted to string an passed as such.

    multi_flags: set, names (strings) of flags that should be treated as
      multi-flags.

  Yields:
    sequence of string suitable for a subprocess execution.
  Nz--z--norF   ú,c                 s   s   � | ]}t |ƒV  qd S rg   )r   )rH   Úitemr   r   r   rj   W  rk   z$flag_dict_to_args.<locals>.<genexpr>)Úitemsr2   r3   Úbytesr   rt   Ú	TypeError)ry   rz   Úkeyr0   r|   r   r   r   Úflag_dict_to_args&  s*   €
ÿ"€þír�   Ú	docstringc                 C   sÚ   | sdS d}|   ¡  ¡ }|}|dd… D ]}| ¡ }|r't|t|ƒt|ƒ ƒ}q|d  ¡ g}||k rG|dd… D ]}| ||d…  ¡ ¡ q9|rW|d sW| ¡  |rW|d rM|rh|d sh| d¡ |rh|d r]d 	|¡S )a  Removes indentation from triple-quoted strings.

  This is the function specified in PEP 257 to handle docstrings:
  https://www.python.org/dev/peps/pep-0257/.

  Args:
    docstring: str, a python docstring.

  Returns:
    str, docstring with indentation removed.
  r1   i    r%   Nr   éÿÿÿÿrl   )
rn   rq   ÚlstriprU   rL   rh   rP   ÚrstripÚpoprt   )r‚   Ú
max_indentÚlinesra   ÚlineÚstrippedZtrimmedr   r   r   Útrim_docstring]  s*   €ÿ
ÿ
r‹   c                 C   sB   |   ¡ } t dtj¡}| d| ¡} t| ƒ} tjdd| tjd�} | S )z0Takes a __doc__ string and reformats it as help.z^[ 	]+$r1   z(?<=\S)\n(?=\S)ú )Úflags)rh   ÚreÚcompileÚMr6   r‹   )r/   Zwhitespace_only_liner   r   r   Údoc_to_help‡  s   r‘   )Nr1   Nrg   )/r   Úcollections.abcr   r   rŽ   r>   r   ro   r   Útypingr   r   Úxml.domr   r   Úintr   r
   r   Úfloatr�   r5   r*   r    r   r   Úsetr   r   r   r   Údictr   r$   r-   r.   ÚDocumentÚElementr<   rB   ÚlistrT   rK   rx   r�   r‹   r‘   r   r   r   r   Ú<module>   sˆ   ÿ
ÿ
þÿÿÿ
þÿÿ
þ! üÿþýü
ûAÿ
ÿ
ÿ
þ7*