o
    mi$                     @  s8  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d3ddZejdejdZd4ddZedZd5d6ddZd7dd ZG d!d" d"ejZ	#	$	$d8d9d*d+Ze 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:d1d2Z+dS );z
babel.util
~~~~~~~~~~

Various utility classes and functions.

:copyright: (c) 2013-2026 by the Babel Team.
:license: BSD, see LICENSE for more details.
    )annotationsN)	GeneratorIterable)IOAnyTypeVar)dates	localtime_TiterableIterable[_T]returnGenerator[_T, None, None]c                 c  s2    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   D/home/kim/smarthome/.venv/lib/python3.10/site-packages/babel/util.pydistinct   s   
r   s(   [ \t\f]* \# .* coding[=:][ \t]*([-\w.]+))flagsfp	IO[bytes]
str | Nonec              
   C  s  |   }| d zx|  }|tj}|r|ttjd }t|}|sJzddl	}|
|d W n tttfy@   Y n
w |  }t|}|rj|rb|dd}|dkrbtd| dW | | dS |rz|ddW | | S W | | dS | | w )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   posline1Zhas_bommr&   line2Zmagic_comment_encodingr   r   r   parse_encoding8   s:   


r1   z'from\s+__future__\s+import\s+\(*(.+)\)*r   encodingstrintc           
   	   C  s   ddl }|  }| d d}zK|  |}tdd|}tdd|}tdd|}t|D ]!}d	d
 |	d
dD }|D ]}t||d}	|	rQ||	jO }qBq1W | | |S | | w )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>   s    z&parse_future_flags.<locals>.<listcomp>r   ,)
__future__r   r   readr(   resubPYTHON_FUTURE_IMPORT_refinditerr,   splitgetattrcompiler_flag)
r   r2   r;   r-   r   bodyr/   namesnamefeaturer   r   r   parse_future_flagsl   s*   


rH   patternfilenameboolc                 C  s   ddddddd}|  drdg}| d	d
 } n|  dr'dg}| dd
 } ng }ttd| D ]\}}|d rA|||  q1|rK|t| q1t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    	enumerater=   rA   appendescaper%   joinreplaceossep)rI   rJ   symbolsbufidxpartr%   r   r   r   	pathmatch   s,   '
	
"r^   c                      s0   e Zd ZedZedZ fddZ  ZS )TextWrapperz((\s+|(?<=[\w\!\"\'\&\.\,\?])-{2,}(?=\w))z$(\u2068[^\u2068]+?\u2069(?::-?\d+)?)c                   sf   d}||vrt  |S g }t| j|D ]}||r"|| q|t  | qdd |D S )z|Splits the text into indivisible chunks while ensuring that file names
        containing spaces are not broken up.
        u   ⁨c                 S  s   g | ]}|r|qS r   r   )r7   cr   r   r   r9      s    z&TextWrapper._split.<locals>.<listcomp>)super_splitr=   rA   _enclosed_filename_rer    rT   extend)selftextZenclosed_filename_startchunkschunk	__class__r   r   rb      s   
zTextWrapper._split)	__name__
__module____qualname__r=   compile
wordsep_rerc   rb   __classcell__r   r   ri   r   r_      s    
r_   F   rP   rf   widthinitial_indentsubsequent_indent	list[str]c                 C  s&   t jdtdd 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. It also
    does not wrap PO file locations containing spaces.

    :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
    z`babel.util.wraptext` is deprecated and will be removed in a future version of Babel. If you need this functionality, use the `babel.util.TextWrapper` class directly.rO   
stacklevelF)rr   rs   rt   break_long_words)warningswarnDeprecationWarningr_   wrap)rf   rr   rs   rt   r   r   r   wraptext   s   r}   c                   @  sN   e Zd ZdZddd	d
ZdddZdddZdddZdddZdddZ	dS )FixedOffsetTimezonezw
    Fixed offset in minutes east from UTC.

    DEPRECATED: Use the standard library `datetime.timezone` instead.
    NoffsetfloatrF   r   r   Nonec                 C  s8   t jdtdd tj|d| _|d u rd| }|| _d S )Nz`FixedOffsetTimezone` is deprecated and will be removed in a future version of Babel. Use the standard library `datetime.timezone` class.rO   rv   )minutesz
Etc/GMT%+d)ry   rz   r{   datetime	timedelta_offsetzone)re   r   rF   r   r   r   __init__  s   
zFixedOffsetTimezone.__init__r3   c                 C     | j S Nr   re   r   r   r   __str__!     zFixedOffsetTimezone.__str__c                 C  s   d| j  d| j dS )Nz<FixedOffset "z" >)r   r   r   r   r   r   __repr__$  s   zFixedOffsetTimezone.__repr__dtdatetime.datetimedatetime.timedeltac                 C  r   r   )r   re   r   r   r   r   	utcoffset'  r   zFixedOffsetTimezone.utcoffsetc                 C  r   r   r   r   r   r   r   tzname*  r   zFixedOffsetTimezone.tznamec                 C  s   t S r   )ZEROr   r   r   r   dst-  s   zFixedOffsetTimezone.dstr   )r   r   rF   r   r   r   )r   r3   )r   r   r   r   )r   r   r   r3   )
rk   rl   rm   __doc__r   r   r   r   r   r   r   r   r   r   r~     s    



r~   ar   bc                 C  s   | |k| |k  S r   r   )r   r   r   r   r   _cmp=  s   r   )r   r   r   r   )r   r   r   r   )r   )r   r   r2   r3   r   r4   )rI   r3   rJ   r3   r   rK   )rq   rP   rP   )
rf   r3   rr   r4   rs   r3   rt   r3   r   ru   )r   r   r   r   ),r   r;   r   r!   r   rX   r=   textwrapry   collections.abcr   r   typingr   r   r   Zbabelr   r	   objectmissingr
   r   rn   VERBOSEr$   r1   r?   rH   r^   r_   r}   dictZodicttzinfor~   UTCZLOCALTZZget_localzoneZ	STDOFFSETZ	DSTOFFSETZDSTDIFFr   r   r   r   r   r   <module>   sJ    



1
!A (