
    Qc                        d Z ddlZddlZddlmZmZ ddlZddlZddlZddl	Z
ddlmZ  e            Zd Z ej        dej                  Zd Z ej        d          Zdd
Zd Z G d dej                  ZddZej        Z G d de          Ze
j        Zej        Zej        Zej         Z ej!        Z!ej"        Z"ej#        Z#d Z$dS )z
    babel.util
    ~~~~~~~~~~

    Various utility classes and functions.

    :copyright: (c) 2013-2022 by the Babel Team.
    :license: BSD, see LICENSE for more details.
    N)	timedeltatzinfo)	localtimec              #      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)iterableseenitems      *lib/python3.11/site-packages/babel/util.pydistinctr      sV       55DX  t 	JJJHHTNNN     s(   [ \t\f]* \# .* coding[=:][ \t]*([-\w.]+)c                    |                                  }|                     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|rj|rP|                    d                              d          }|dk    r"t          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: {0} with BOM)tellseekreadline
startswithcodecsBOM_UTF8lenPYTHON_MAGIC_COMMENT_rematchastparsedecodeImportErrorSyntaxErrorUnicodeEncodeErrorgroupformat)fpposline1has_bommr   line2magic_comment_encodings           r   parse_encodingr+   /   s    ''))CGGAJJJ"""6?33 	1#fo..//0E#))%00 	99


		%,,y11222 +11%88  .@A   
   	 5)*):):9)E)E&)W4 5%8??24 45 5 5  	  	771::$$Y// 	 
s7   A2G ,C9 
/G 9DG DAG )G G0z'from\s+__future__\s+import\s+\(*(.+)\)*r   c                 |   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$   encodingr4   r%   flagsbodyr(   namesnamefeatures
             r   parse_future_flagsrC   e   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c                 "   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z   |                    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   	enumerater6   r:   appendescaper   joinreplaceossep)patternfilenamesymbolsbufidxpartr   s          r   	pathmatchrY      s.   N  G # e!""+			D	!	! e!""+rxW==>> ( (	T7 	(JJwt}%%%% 	(JJry'''HRWWS\\C')9)9"&#)F)FGGEr   c                   .    e Zd Z ej        d          ZdS )TextWrapperz((\s+|(?<=[\w\!\"\'\&\.\,\?])-{2,}(?=\w))N)__name__
__module____qualname__r6   compile
wordsep_re r   r   r[   r[      s&        	/ JJJr   r[   F   rI   c                 R    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.

    :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)textrd   re   rf   wrappers        r   wraptextrk      s6     n,=+02 2 2G <<r   c                   8    e Zd ZdZd	dZd Zd Zd Zd Zd Z	dS )
FixedOffsetTimezonez&Fixed offset in minutes east from UTC.Nc                 L    t          |          | _        |d|z  }|| _        d S )N)minutesz
Etc/GMT%+d)r   _offsetzone)selfoffsetrA   s      r   __init__zFixedOffsetTimezone.__init__   s1     000 	)&(D			r   c                     | j         S Nrq   rr   s    r   __str__zFixedOffsetTimezone.__str__   
    yr   c                 (    d| j         d| j        dS )Nz<FixedOffset "z" >)rq   rp   rx   s    r   __repr__zFixedOffsetTimezone.__repr__   s     *.)))T\\\BBr   c                     | j         S rv   )rp   rr   dts     r   	utcoffsetzFixedOffsetTimezone.utcoffset   s
    |r   c                     | j         S rv   rw   r   s     r   tznamezFixedOffsetTimezone.tzname   rz   r   c                     t           S rv   )ZEROr   s     r   dstzFixedOffsetTimezone.dst   s    r   rv   )
r\   r]   r^   __doc__rt   ry   r}   r   r   r   ra   r   r   rm   rm      s|        00     C C C        r   rm   c                     | |k    | |k     z
  S rv   ra   )abs     r   _cmpr     s    Ea!er   )r   )rb   rI   rI   )%r   r   collectionsdatetimer   r   rQ   r6   textwrappytz_pytzbabelr   objectmissingr   r_   VERBOSEr   r+   r8   rC   rY   r[   rk   OrderedDictodictrm   utcUTCLOCALTZget_localzone	STDOFFSET	DSTOFFSETDSTDIFFr   r   ra   r   r   <module>r      s         & & & & & & & & 				 				           
&((  ( %"*0"*> > / / /d %"*.0 0    @> > >B    (&      $ 	    &   6 i

'		

~    r   