
    3sg                    <   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Z ej.                  d	ej0                        Zdd
Z ej.                  d      ZdddZddZ G d dej<                        ZdddZej@                  Z! G d dejD                        Z#ejH                  Z$ejJ                  Z%ejL                  Z&ejN                  Z'ejP                  Z(ejR                  Z)ejT                  Z*ddZ+y)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_Tc              #  t   K   t               }t        |       D ]  }||vs| |j                  |        yw)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)iterableseenitems      *lib/python3.12/site-packages/babel/util.pydistinctr      s5      5DXtJHHTN s   88s(   [ \t\f]* \# .* coding[=:][ \t]*([-\w.]+)c                $   | j                         }| j                  d       	 | j                         }|j                  t        j
                        }|r|t        t        j
                        d }t        j                  |      }|sJ	 ddl	}|j                  |j                  d             | j                         }t        j                  |      }|rI|r4|j                  d      j                  d      }|dk7  rt        d| d      	 | j                  |       y|r1|j                  d      j                  d      | j                  |       S 	 | j                  |       y# t        t        t        f$ r Y w xY w# | j                  |       w xY 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)fpposline1has_bommr!   line2magic_comment_encodings           r   parse_encodingr/   5   sW    '')CGGAJ ""6??3#foo./0E#))%09		%,,y12 +11%8)*):):9)E&)W4%(:;Q:RR[&\]] 	 771:$$Y/ 	 
+  .@A 
 * 	s7   A$E< $E" ,AE< !E< "E96E< 8E99E< <Fz'from\s+__future__\s+import\s+\(*(.+)\)*c                   ddl }| j                         }| j                  d       d}	 | j                         j	                  |      }t        j                  dd|      }t        j                  dd|      }t        j                  dd|      }t        j                  |      D ]r  }|j                  d	      j                  d
      D cg c]!  }|j                         j                  d      # }}|D ]!  }	t        ||	d      }
|
s||
j                  z  }# t 	 | j                  |       |S c c}w # | j                  |       w xY 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]+ r   ,z())
__future__r   r   readr#   resubPYTHON_FUTURE_IMPORT_refinditerr'   splitstripgetattrcompiler_flag)r(   encodingr3   r)   flagsbodyr,   xnamesnamefeatures              r   parse_future_flagsrD   i   s    
'')CGGAJEwwy) vv+Z>vvndD1vvosD1(11$7A45GGAJ4D4DS4IJ4IqQWWY__T*4IEJ!*dD9W222E  8 	L K 	s$   BD0 &D+-D0 D0 +D0 0Ec                   ddddddd}| j                  d      r	dg}| d	d
 } n| j                  d      r	dg}| dd
 } ng }t        t        j                  d|             D ]F  \  }}|dz  r|j	                  ||           |s#|j	                  t        j
                  |             H t        j                  dj                  |       d|j                  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   	enumerater5   r9   appendescaper    joinreplaceossep)patternfilenamesymbolsbufidxpartr    s          r   	pathmatchrZ      s    N G #e!"+			D	!e!"+rxxW=>	T7JJwt}%JJryy'	 ?
 HH~Q')9)9"&&#)FGE    c                  0    e Zd Z ej                  d      Zy)TextWrapperz((\s+|(?<=[\w\!\"\'\&\.\,\?])-{2,}(?=\w))N)__name__
__module____qualname__r5   compile
wordsep_re r[   r   r]   r]      s    	/Jr[   r]   c                B    t        |||d      }|j                  |       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)widthinitial_indentsubsequent_indentbreak_long_words)r]   wrap)textre   rf   rg   wrappers        r   wraptextrl      s)     n,=+02G <<r[   c                  B    e Zd ZdZd	d
dZddZddZddZddZddZ	y)FixedOffsetTimezonez&Fixed offset in minutes east from UTC.Nc                V    t        j                  |      | _        |d|z  }|| _        y )N)minutesz
Etc/GMT%+d)datetime	timedelta_offsetzone)selfoffsetrB   s      r   __init__zFixedOffsetTimezone.__init__   s*    ))&9<&(D	r[   c                    | j                   S Nrt   ru   s    r   __str__zFixedOffsetTimezone.__str__       yyr[   c                <    d| j                    d| j                   dS )Nz<FixedOffset "z" >)rt   rs   r{   s    r   __repr__zFixedOffsetTimezone.__repr__   s    		{"T\\N!<<r[   c                    | j                   S ry   )rs   ru   dts     r   	utcoffsetzFixedOffsetTimezone.utcoffset   s    ||r[   c                    | j                   S ry   rz   r   s     r   tznamezFixedOffsetTimezone.tzname   r}   r[   c                    t         S ry   )ZEROr   s     r   dstzFixedOffsetTimezone.dst   s    r[   ry   )rv   floatrB   
str | NonereturnNone)r   str)r   datetime.datetimer   zdatetime.timedelta)r   r   r   r   )
r^   r_   r`   __doc__rw   r|   r   r   r   r   rc   r[   r   rn   rn      s#    0=r[   rn   c                    | |kD  | |k  z
  S ry   rc   )abs     r   _cmpr     s    Ea!er[   )r   zIterable[_T]r   zGenerator[_T, None, None])r(   	IO[bytes]r   r   )r   )r(   r   r=   r   r   int)rT   r   rU   r   r   bool)F   rJ   rJ   )
rj   r   re   r   rf   r   rg   r   r   z	list[str])r   r   r   r   ),r   r3   r   r   collectionsrq   rR   r5   textwrapcollections.abcr   r   typingr   r   r   babelr	   r
   objectmissingr   r   ra   VERBOSEr   r/   r7   rD   rZ   r]   rl   OrderedDictodicttzinforn   UTCLOCALTZget_localzone	STDOFFSET	DSTOFFSETDSTDIFFr   r   rc   r[   r   <module>r      s   #    	 	  / # # "
(T]* %"**0"**> -` %"**.0 @>B(&& $ 	(// : ii
--''		


~~r[   