
    ƪb                        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j2                  Z G d de      Ze
j8                  Zej<                  Zej>                  Zej@                  Z ejB                  Z!ejD                  Z"ejF                  Z#d Z$y)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              #   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      ,/usr/lib/python3/dist-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                  |      }|rT|r?|j                  d      j                  d      }|dk7  rt        dj!                  |            	 | 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: {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GGAJ"""6??3#foo./0E#))%09		%,,y12 +11%8)*):):9)E&)W4%8??245 5  	 771:$$Y/ 	 
/  .@A 
 . 	s7   A$F $E- ,A(F '!F -FF FF 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#   encodingr.   r$   flagsbodyr'   xnamesnamefeatures              r   parse_future_flagsr?   e   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z   |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   	enumerater0   r4   appendescaper   joinreplaceossep)patternfilenamesymbolsbufidxpartr   s          r   	pathmatchrU      s    N G #e!"+			D	!e!"+rxxW=> (	T7JJwt}%JJryy'	(
 HHRWWS\C')9)9"&&#)FGE    c                   0    e Zd Z ej                  d      Zy)TextWrapperz((\s+|(?<=[\w\!\"\'\&\.\,\?])-{2,}(?=\w))N)__name__
__module____qualname__r0   compile
wordsep_re rV   r   rX   rX      s    	/JrV   rX   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)rX   wrap)textr`   ra   rb   wrappers        r   wraptextrg      s)     n,=+02G <<rV   c                   6    e Zd ZdZd	dZd Zd Zd Zd Zd Z	y)
FixedOffsetTimezonez&Fixed offset in minutes east from UTC.Nc                 B    t        |      | _        |d|z  }|| _        y )N)minutesz
Etc/GMT%+d)r   _offsetzone)selfoffsetr=   s      r   __init__zFixedOffsetTimezone.__init__   s$     0<&(D	rV   c                     | j                   S Nrm   rn   s    r   __str__zFixedOffsetTimezone.__str__       yyrV   c                 <    d| j                   d| j                  dS )Nz<FixedOffset "z" >)rm   rl   rt   s    r   __repr__zFixedOffsetTimezone.__repr__   s    *.))T\\BBrV   c                     | j                   S rr   )rl   rn   dts     r   	utcoffsetzFixedOffsetTimezone.utcoffset   s    ||rV   c                     | j                   S rr   rs   r{   s     r   tznamezFixedOffsetTimezone.tzname   rv   rV   c                     t         S rr   )ZEROr{   s     r   dstzFixedOffsetTimezone.dst   s    rV   rr   )
rY   rZ   r[   __doc__rp   ru   ry   r}   r   r   r^   rV   r   ri   ri      s$    0CrV   ri   c                     | |kD  | |k  z
  S rr   r^   )abs     r   _cmpr     s    Ea!erV   )r   )F   rE   rE   )%r   r   collectionsdatetimer   r   rM   r0   textwrappytz_pytzbabelr   objectmissingr   r\   VERBOSEr   r*   r2   r?   rU   rX   rg   OrderedDictodictri   utcUTCLOCALTZget_localzone	STDOFFSET	DSTOFFSETDSTDIFFr   r   r^   rV   r   <module>r      s      & 	 	   
(( %"**0"**> /d %"**.0 @>B(&& $ 	& 6 ii


''		


~~rV   