
    Xho#                    (   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 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-2025 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      >/var/www/html/myenv/lib/python3.12/site-packages/babel/util.pydistinctr      s:      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$7 	3A45GGAJ4D4DS4IJqQWWY__T*JEJ 3!*dD9W222E3	3 	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                  f     e Zd Z ej                  d      Z ej                  d      Z fdZ xZS )TextWrapperz((\s+|(?<=[\w\!\"\'\&\.\,\?])-{2,}(?=\w))z$(\u2068[^\u2068]+?\u2069(?::-?\d+)?)c                .   d}||vrt         |   |      S g }t        j                  | j                  |      D ]C  }|j                  |      r|j                  |       &|j                  t         |   |             E |D cg c]  }|s|	 c}S c c}w )z|Splits the text into indivisible chunks while ensuring that file names
        containing spaces are not broken up.
        u   ⁨)super_splitr5   r9   _enclosed_filename_rer   rN   extend)selftextenclosed_filename_startchunkschunkc	__class__s         r   r`   zTextWrapper._split   s     #+"$.7>$''XXd88$? 	5E 78e$egnU34		5
 "'aQ'''s   BB)	__name__
__module____qualname__r5   compile
wordsep_rera   r`   __classcell__)ri   s   @r   r]   r]      s6    	/J 'BJJ'NO( (r[   r]   c                z    t        j                  dt        d       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. 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.rI   )
stacklevelF)widthinitial_indentsubsequent_indentbreak_long_words)warningswarnDeprecationWarningr]   wrap)rd   rr   rs   rt   wrappers        r   wraptextr{      sC     MM	[	 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)rc   offsetrB   s      r   __init__zFixedOffsetTimezone.__init__  s*    ))&9<&(D	r[   c                    | j                   S Nr   rc   s    r   __str__zFixedOffsetTimezone.__str__      yyr[   c                <    d| j                    d| j                   dS )Nz<FixedOffset "z" >)r   r   r   s    r   __repr__zFixedOffsetTimezone.__repr__  s    		{"T\\N!<<r[   c                    | j                   S r   )r   rc   dts     r   	utcoffsetzFixedOffsetTimezone.utcoffset  s    ||r[   c                    | j                   S r   r   r   s     r   tznamezFixedOffsetTimezone.tzname  r   r[   c                    t         S r   )ZEROr   s     r   dstzFixedOffsetTimezone.dst  s    r[   r   )r   floatrB   
str | NonereturnNone)r   str)r   datetime.datetimer   zdatetime.timedelta)r   r   r   r   )
rj   rk   rl   __doc__r   r   r   r   r   r    r[   r   r}   r}     s#    0=r[   r}   c                    | |kD  | |k  z
  S r   r   )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   )
rd   r   rr   r   rs   r   rt   r   r   z	list[str])r   r   r   r   ),r   r3   r   r   r   rR   r5   textwraprv   collections.abcr   r   typingr   r   r   babelr	   r
   objectmissingr   r   rm   VERBOSEr   r/   r7   rD   rZ   r]   r{   dictodicttzinfor}   UTCLOCALTZget_localzone	STDOFFSET	DSTOFFSETDSTDIFFr   r   r   r[   r   <module>r      s   #   	 	   / # # "
(T]* %"**0"**> -` %"**.0 @>B((&& (62 	(// : ii
--''		


~~r[   