a
    ÆZEg  ã                   @  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ZddlZddl	m
Z
mZ ddlmZmZmZ ddlmZmZ eƒ ZedƒZdd	d
œdd„Ze dej¡Zdddœdd„Ze d¡Zd,ddddœdd„Zddddœdd„ZG dd„ dejƒZd-ddddd"d#œd$d%„Zej Z!G d&d'„ d'ej"ƒZ#ej$Z$ej%Z%ej&Z&ej'Z'ej(Z(ej)Z)ej*Z*d(d(d)œd*d+„Z+dS ).z®
    babel.util
    ~~~~~~~~~~

    Various utility classes and functions.

    :copyright: (c) 2013-2024 by the Babel Team.
    :license: BSD, see LICENSE for more details.
é    )ÚannotationsN)Ú	GeneratorÚIterable)ÚIOÚAnyÚTypeVar)ÚdatesÚ	localtimeÚ_TzIterable[_T]zGenerator[_T, None, None])ÚiterableÚreturnc                 c  s0   t ƒ }t| ƒD ]}||vr|V  | |¡ qdS )a–  Yield all items in an iterable collection that are distinct.

    Unlike when using sets for a similar effect, the original ordering of the
    items in the collection is preserved by this function.

    >>> print(list(distinct([1, 2, 1, 3, 4, 4])))
    [1, 2, 3, 4]
    >>> print(list(distinct('foobar')))
    ['f', 'o', 'b', 'a', 'r']

    :param iterable: the iterable collection providing the data
    N)ÚsetÚiterÚadd)r   ÚseenÚitem© r   úC/var/www/sistema_ama/venv/lib/python3.9/site-packages/babel/util.pyÚdistinct   s
    r   s(   [ \t\f]* \# .* coding[=:][ \t]*([-\w.]+)z	IO[bytes]ú
str | None)Úfpr   c              
   C  s$  |   ¡ }|  d¡ � zþ|  ¡ }| tj¡}|r@|ttjƒd… }t |¡}|s–zddl	}| 
| d¡¡ W n tttfy‚   Y n0 |  ¡ }t |¡}|rÖ|rÆ| d¡ d¡}|dkrÆtd|› d�ƒ‚W |  |¡ dS |rö| d¡ d¡W |  |¡ S W |  |¡ dS W |  |¡ n|  |¡ 0 dS )a/  Deduce the encoding of a source file from magic comment.

    It does this in the same way as the `Python interpreter`__

    .. __: https://docs.python.org/3.4/reference/lexical_analysis.html#encoding-declarations

    The ``fp`` argument should be a seekable file object.

    (From Jeff Dairiki)
    r   Núlatin-1é   zutf-8zencoding problem: z	 with BOM)ÚtellÚseekÚreadlineÚ
startswithÚcodecsÚBOM_UTF8ÚlenÚPYTHON_MAGIC_COMMENT_reÚmatchÚastÚparseÚdecodeÚImportErrorÚSyntaxErrorÚUnicodeEncodeErrorÚgroup)r   ÚposZline1Zhas_bomÚmr"   Zline2Zmagic_comment_encodingr   r   r   Úparse_encoding5   s@    



ú
ü
þr+   z'from\s+__future__\s+import\s+\(*(.+)\)*r   ÚstrÚint)r   Úencodingr   c           
   	   C  sÄ   ddl }|  ¡ }|  d¡ d}z”|  ¡  |¡}t dd|¡}t dd|¡}t dd|¡}t |¡D ]B}d	d
„ | 	d¡ 
d¡D ƒ}|D ]}t||dƒ}	|	r„||	jO }q„qbW |  |¡ n|  |¡ 0 |S )zRParse the compiler flags by :mod:`__future__` from the given Python
    code.
    r   Nzimport\s*\([\r\n]+zimport (z,\s*[\r\n]+z, z\\\s*[\r\n]+ú c                 S  s   g | ]}|  ¡   d ¡‘qS )z())Ústrip)Ú.0Úxr   r   r   Ú
<listcomp>   ó    z&parse_future_flags.<locals>.<listcomp>r   ú,)Ú
__future__r   r   Úreadr$   ÚreÚsubÚPYTHON_FUTURE_IMPORT_reÚfinditerr(   ÚsplitÚgetattrÚcompiler_flag)
r   r.   r6   r)   ÚflagsÚbodyr*   ÚnamesÚnameÚfeaturer   r   r   Úparse_future_flagsi   s"    
rD   Úbool)ÚpatternÚfilenamer   c                 C  sÂ   dddddddœ}|   d¡r0dg}| d	d
… } n"|   d¡rNdg}| dd
… } ng }tt d| ¡ƒD ]4\}}|d r‚| || ¡ qb|rb| t |¡¡ qbt d |¡› d�| t	j
d¡¡}|d
uS )aø  Extended pathname pattern matching.

    This function is similar to what is provided by the ``fnmatch`` module in
    the Python standard library, but:

     * can match complete (relative or absolute) path names, and not just file
       names, and
     * also supports a convenience pattern ("**") to match files at any
       directory level.

    Examples:

    >>> pathmatch('**.py', 'bar.py')
    True
    >>> pathmatch('**.py', 'foo/bar/baz.py')
    True
    >>> pathmatch('**.py', 'templates/index.html')
    False

    >>> pathmatch('./foo/**.py', 'foo/bar/baz.py')
    True
    >>> pathmatch('./foo/**.py', 'bar/baz.py')
    False

    >>> pathmatch('^foo/**.py', 'foo/bar/baz.py')
    True
    >>> pathmatch('^foo/**.py', 'bar/baz.py')
    False

    >>> pathmatch('**/templates/*.html', 'templates/index.html')
    True
    >>> pathmatch('**/templates/*.html', 'templates/foo/bar.html')
    False

    :param pattern: the glob pattern
    :param filename: the path name of the file to match against
    z[^/]z[^/]/z[^/]+z[^/]+/z	(?:.+/)*?z(?:.+/)*?[^/]+)ú?z?/Ú*z*/z**/z**ú^r   Nz./é   z	([?*]+/?)Ú ú$ú/)r   Ú	enumerater8   r<   ÚappendÚescaper!   ÚjoinÚreplaceÚosÚsep)rF   rG   ÚsymbolsÚbufÚidxÚpartr!   r   r   r   Ú	pathmatch‰   s*    'ú	

"rZ   c                   @  s   e Zd Ze d¡ZdS )ÚTextWrapperz((\s+|(?<=[\w\!\"\'\&\.\,\?])-{2,}(?=\w))N)Ú__name__Ú
__module__Ú__qualname__r8   ÚcompileÚ
wordsep_rer   r   r   r   r[   Ê   s   ÿr[   éF   rL   z	list[str])ÚtextÚwidthÚinitial_indentÚsubsequent_indentr   c                 C  s   t |||dd�}| | ¡S )aØ  Simple wrapper around the ``textwrap.wrap`` function in the standard
    library. This version does not wrap lines on hyphens in words.

    :param text: the text to wrap
    :param width: the maximum line width
    :param initial_indent: string that will be prepended to the first line of
                           wrapped output
    :param subsequent_indent: string that will be prepended to all lines save
                              the first of wrapped output
    F)rc   rd   re   Úbreak_long_words)r[   Úwrap)rb   rc   rd   re   Úwrapperr   r   r   ÚwraptextÑ   s
    þri   c                   @  sp   e Zd ZdZdddddœdd„Zd	d
œdd„Zd	d
œdd„Zdddœdd„Zdd	dœdd„Zdddœdd„Z	dS )ÚFixedOffsetTimezonez&Fixed offset in minutes east from UTC.NÚfloatr   ÚNone)ÚoffsetrB   r   c                 C  s(   t j|d�| _|d u rd| }|| _d S )N)Úminutesz
Etc/GMT%+d)ÚdatetimeÚ	timedeltaÚ_offsetÚzone)Úselfrm   rB   r   r   r   Ú__init__é   s    zFixedOffsetTimezone.__init__r,   )r   c                 C  s   | j S ©N©rr   ©rs   r   r   r   Ú__str__ð   s    zFixedOffsetTimezone.__str__c                 C  s   d| j › d| j› d�S )Nz<FixedOffset "z" ú>)rr   rq   rw   r   r   r   Ú__repr__ó   s    zFixedOffsetTimezone.__repr__zdatetime.datetimezdatetime.timedelta)Údtr   c                 C  s   | j S ru   )rq   ©rs   r{   r   r   r   Ú	utcoffsetö   s    zFixedOffsetTimezone.utcoffsetc                 C  s   | j S ru   rv   r|   r   r   r   Útznameù   s    zFixedOffsetTimezone.tznamec                 C  s   t S ru   )ÚZEROr|   r   r   r   Údstü   s    zFixedOffsetTimezone.dst)N)
r\   r]   r^   Ú__doc__rt   rx   rz   r}   r~   r€   r   r   r   r   rj   æ   s   rj   r   ©ÚaÚbc                 C  s   | |k| |k  S ru   r   r‚   r   r   r   Ú_cmp  s    r…   )r   )ra   rL   rL   ),r�   r6   r   r   Úcollectionsro   rT   r8   ÚtextwrapÚcollections.abcr   r   Útypingr   r   r   Zbabelr   r	   ÚobjectÚmissingr
   r   r_   ÚVERBOSEr    r+   r:   rD   rZ   r[   ri   ÚOrderedDictZodictÚtzinforj   ÚUTCZLOCALTZZget_localzoneZ	STDOFFSETZ	DSTOFFSETZDSTDIFFr   r…   r   r   r   r   Ú<module>   sD   	ÿ0ÿ A