
    Mho#                       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j                  Zd-dZ ej        d          Zd.d/dZd0dZ G d dej                  Zd1d2d%Ze Z! G 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*d3d+Z+dS )4z
    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_TiterableIterable[_T]returnGenerator[_T, None, None]c              #     K   t                      }t          |           D ]}||vr|V  |                    |            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items      J/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/babel/util.pydistinctr      sT       55DX  tJJJHHTNNN     s(   [ \t\f]* \# .* coding[=:][ \t]*([-\w.]+)fp	IO[bytes]
str | Nonec                   |                                  }|                     d           	 |                                 }|                    t          j                  }|r!|t          t          j                  d         }t                              |          }|sy	 ddl	}|
                    |                    d                     |                                 }t                              |          }n# t          t          t          f$ r Y nw xY w|r[|rA|                    d                              d          }|dk    rt          d| d          	 |                     |           dS |r=|                    d                              d          |                     |           S 	 |                     |           dS # |                     |           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)r   posline1has_bommr(   line2magic_comment_encodings           r   parse_encodingr5   5   s    ''))CGGAJJJ ""6?33 	1#fo..//0E#))%00 	99


		%,,y11222 +11%88  .@A   
   		 ^)*):):9)E)E&)W44%&\;Q&\&\&\]]] 	  	771::$$Y// 	 
s7   A2G
 ,C9 
/G
 9DG
 DAG
 3)G
 
G!z'from\s+__future__\s+import\s+\(*(.+)\)*r   encodingstrintc                |   ddl }|                                 }|                     d           d}	 |                                                     |          }t          j        dd|          }t          j        dd|          }t          j        dd|          }t                              |          D ]V}d	 |	                    d
          
                    d          D             }|D ]}t          ||d          }	|	r
||	j        z  } W	 |                     |           n# |                     |           w xY w|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                \    g | ])}|                                                      d           *S )z())strip).0xs     r   
<listcomp>z&parse_future_flags.<locals>.<listcomp>   s,    JJJqQWWYY__T**JJJr   r   ,)
__future__r   r    readr*   resubPYTHON_FUTURE_IMPORT_refinditerr.   splitgetattrcompiler_flag)
r   r6   rA   r/   flagsbodyr2   namesnamefeatures
             r   parse_future_flagsrO   i   sA    
''))CGGAJJJEwwyy)) v+Z>>vndD11vosD11(11$77 	3 	3AJJAGGAJJ4D4DS4I4IJJJE 3 3!*dD99 3W22E3	3 	Ls   CD" "D9patternfilenameboolc                "   ddddddd}|                      d          rdg}| d	d
         } n%|                      d          rdg}| dd
         } ng }t          t          j        d|                     D ]O\  }}|dz  r|                    ||                    &|r'|                    t          j        |                     Pt          j        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"   	enumeraterC   rG   appendescaper'   joinreplaceossep)rP   rQ   symbolsbufidxpartr'   s          r   	pathmatchrf      s2   N  G # e!""+			D	!	! e!""+rxW==>> ( (	T7 	(JJwt}%%%% 	(JJry'''H''')9)9"&#)F)FGGEr   c                  ^     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                f   d}||vr!t                                          |          S g }t          j        | j        |          D ]a}|                    |          r|                    |           -|                    t                                          |                     bd |D             S )z|Splits the text into indivisible chunks while ensuring that file names
        containing spaces are not broken up.
        u   ⁨c                    g | ]}||S  rk   )r=   cs     r   r?   z&TextWrapper._split.<locals>.<listcomp>   s    '''aQ''''r   )super_splitrC   rG   _enclosed_filename_rer"   r\   extend)selftextenclosed_filename_startchunkschunk	__class__s        r   rn   zTextWrapper._split   s     #+"$..77>>$'''Xd8$?? 	5 	5E 788 5e$$$$eggnnU334444''6''''r   )	__name__
__module____qualname__rC   compile
wordsep_rero   rn   __classcell__)rv   s   @r   rh   rh      se        	/ J 'BJ'NOO( ( ( ( ( ( ( ( (r   rh   F   rX   rr   widthinitial_indentsubsequent_indent	list[str]c                    t          j        dt          d           t          |||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.rW   )
stacklevelF)r~   r   r   break_long_words)warningswarnDeprecationWarningrh   wrap)rr   r~   r   r   wrappers        r   wraptextr      s]     M	[	    n,=+02 2 2G <<r   c                  D    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	dS )FixedOffsetTimezonez&Fixed offset in minutes east from UTC.NoffsetfloatrM   r   r   Nonec                V    t          j        |          | _        |d|z  }|| _        d S )N)minutesz
Etc/GMT%+d)datetime	timedelta_offsetzone)rq   r   rM   s      r   __init__zFixedOffsetTimezone.__init__  s1    )&999<&(D			r   r7   c                    | j         S Nr   rq   s    r   __str__zFixedOffsetTimezone.__str__  
    yr   c                (    d| j          d| j         dS )Nz<FixedOffset "z" >)r   r   r   s    r   __repr__zFixedOffsetTimezone.__repr__  s    <	<<T\<<<<r   dtdatetime.datetimedatetime.timedeltac                    | j         S r   )r   rq   r   s     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   r   rM   r   r   r   )r   r7   )r   r   r   r   )r   r   r   r7   )
rw   rx   ry   __doc__r   r   r   r   r   r   rk   r   r   r   r     s        00       = = = =           r   r   ar   bc                    | |k    | |k     z
  S r   rk   )r   r   s     r   _cmpr   '  s    Ea!er   )r   r   r   r   )r   r   r   r   )r   )r   r   r6   r7   r   r8   )rP   r7   rQ   r7   r   rR   )r}   rX   rX   )
rr   r7   r~   r8   r   r7   r   r7   r   r   )r   r   r   r   ),r   rA   r   r#   r   r`   rC   textwrapr   collections.abcr   r   typingr   r   r   babelr	   r
   objectmissingr   r   rz   VERBOSEr&   r5   rE   rO   rf   rh   r   dictodicttzinfor   UTCLOCALTZget_localzone	STDOFFSET	DSTOFFSETDSTDIFFr   r   rk   r   r   <module>r      s    # " " " " "   				 				   / / / / / / / / # # # # # # # # # # " " " " " " " "
&((WT]]   * %"*0"*> > - - - -` %"*.0 0     @> > > >B( ( ( ( ((& ( ( (6    2 	    (/   : i
-'		

~     r   