3

X'ícŠã@sødZddlZddlZddlmZmZddlZddlZddlZddl	Z
ddlmZe
ƒZdd„ZejdejƒZdd	„Zejd
ƒZddd
„Zdd„ZGdd„dejƒZddd„ZejZGdd„deƒZe
jZejZejZej Z ej!Z!ej"Z"ej#Z#dd„Z$dS)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)Ú	localtimeccs4tƒ}x(t|ƒD]}||kr|V|j|ƒqWdS)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Úitem©rú+/tmp/pip-build-gk9425m9/babel/babel/util.pyÚdistincts

r
s([ \t\f]* \# .* coding[=:][ \t]*([-\w.]+)cCsô|jƒ}|jdƒzÐ|jƒ}|jtjƒ}|r>|ttjƒd…}tj|ƒ}|s–yddl	}|j
|jdƒƒWntt
tfk
r‚YnX|jƒ}tj|ƒ}|rÈ|rÄ|jdƒjdƒ}|dkrÄt
dj|ƒƒ‚dS|rÜ|jdƒjdƒSdSWd|j|ƒXdS)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)
    rNzlatin-1ézutf-8zencoding 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ÚposZline1Zhas_bomÚmrZline2Zmagic_comment_encodingrrrÚparse_encoding/s8


r#z'from\s+__future__\s+import\s+\(*(.+)\)*úlatin-1c
CsÂddl}|jƒ}|jdƒd}z’|jƒj|ƒ}tjdd|ƒ}tjdd|ƒ}tjdd|ƒ}xTtj|ƒD]F}d	d
„|j	dƒj
dƒDƒ}x&|D]}t||dƒ}	|	rˆ||	jO}qˆWqdWWd|j|ƒX|S)
zRParse the compiler flags by :mod:`__future__` from the given Python
    code.
    rNzimport\s*\([\r\n]+zimport (z,\s*[\r\n]+z, z\\\s*[\r\n]+ú cSsg|]}|jƒjdƒ‘qS)z())Ústrip)Ú.0Úxrrrú
<listcomp>{sz&parse_future_flags.<locals>.<listcomp>rú,)
Ú
__future__rrÚreadrÚreÚsubÚPYTHON_FUTURE_IMPORT_reÚfinditerrÚsplitÚgetattrÚ
compiler_flag)
r Úencodingr+r!ÚflagsÚbodyr"ÚnamesÚnameZfeaturerrrÚparse_future_flagses"

r9cCsÄdddddddœ}|jdƒr0dg}|d	d
…}n"|jdƒrNdg}|dd
…}ng}xHttjd
|ƒƒD]4\}}|dr„|j||ƒqd|rd|jtj|ƒƒqdWtjdj|ƒd|jt	j
dƒƒ}|d
k	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**ú^rNz./éz	([?*]+/?)Úú$ú/)rÚ	enumerater-r1ÚappendÚescaperÚjoinÚreplaceÚosÚsep)ÚpatternÚfilenameÚsymbolsÚbufÚidxÚpartrrrrÚ	pathmatch…s('

 rNc@seZdZejdƒZdS)ÚTextWrapperz((\s+|(?<=[\w\!\"\'\&\.\,\?])-{2,}(?=\w))N)Ú__name__Ú
__module__Ú__qualname__r-ÚcompileÚ
wordsep_rerrrrrOÆsrOéFr>cCst|||dd}|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)rOÚwrap)ÚtextrVrWrXÚwrapperrrrÚwraptextÍsr]c@sBeZdZdZddd„Zdd„Zdd„Zd	d
„Zdd„Zd
d„Z	dS)ÚFixedOffsetTimezonez&Fixed offset in minutes east from UTC.NcCs&t|d|_|dkrd|}||_dS)N)Úminutesz
Etc/GMT%+d)rÚ_offsetÚzone)ÚselfÚoffsetr8rrrÚ__init__åszFixedOffsetTimezone.__init__cCs|jS)N)ra)rbrrrÚ__str__ëszFixedOffsetTimezone.__str__cCsd|j|jfS)Nz<FixedOffset "%s" %s>)rar`)rbrrrÚ__repr__îszFixedOffsetTimezone.__repr__cCs|jS)N)r`)rbÚdtrrrÚ	utcoffsetñszFixedOffsetTimezone.utcoffsetcCs|jS)N)ra)rbrgrrrÚtznameôszFixedOffsetTimezone.tznamecCstS)N)ÚZERO)rbrgrrrÚdst÷szFixedOffsetTimezone.dst)N)
rPrQrRÚ__doc__rdrerfrhrirkrrrrr^âs
r^cCs||k||kS)Nr)ÚaÚbrrrÚ_cmpsro)r$)rUr>r>)%rlrÚcollectionsÚdatetimerrrFr-ÚtextwrapZpytzZ_pytzZbabelrÚobjectÚmissingr
rSÚVERBOSErr#r/r9rNrOr]ÚOrderedDictZodictr^ÚutcÚUTCZLOCALTZZ
get_localzoneZ	STDOFFSETZ	DSTOFFSETZDSTDIFFrjrorrrrÚ<module>	s:
2
 A