ƪbdZddlZddlZddlmZmZddlZddlZddlZddl Z ddl m Z e ZdZej dej"ZdZej dZdd Zd ZGd d ej.Zdd Zej2ZGddeZe j8Ze j<Ze j>Ze j@Z e jBZ!e jDZ"e jFZ#dZ$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) timedeltatzinfo) localtimec#tKt}t|D]}||vs||j|yw)aYield 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)setiteradd)iterableseenitems ,/usr/lib/python3/dist-packages/babel/util.pydistinctrs: 5DX t J HHTNs88s([ \t\f]* \# .* coding[=:][ \t]*([-\w.]+)c:|j}|jd |j}|jtj }|r|t tj d}tj|}|sJ ddl }|j|jd|j}tj|}|rT|r?|jdjd}|dk7rtdj!| |j|y|r1|jdjd|j|S |j|y#tttf$rYwxYw#|j|wxYw)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) rNlatin-1zutf-8zencoding problem: {0} with BOM)tellseekreadline startswithcodecsBOM_UTF8lenPYTHON_MAGIC_COMMENT_rematchastparsedecode ImportError SyntaxErrorUnicodeEncodeErrorgroupformat)fpposline1has_bommrline2magic_comment_encodings r parse_encodingr*/s_ '')CGGAJ" ""6??3 #foo./0E # ) )% 0 9 %,,y12 +11%8 )*):):9)E&)W4%8??2455  771:$$Y/    / .@A    .  s7A$F$E-,A(F'!F-FFFFFz'from\s+__future__\s+import\s+\(*(.+)\)*cddl}|j}|jdd} |jj |}t j dd|}t j dd|}t j dd|}tj|D]r}|jd jd Dcgc]!}|jjd #}}|D]!} t|| d} | s|| jz}#t |j||Scc}w#|j|wxYw) 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]+ r,z()) __future__rrreadrresubPYTHON_FUTURE_IMPORT_refinditerr!splitstripgetattr compiler_flag) r#encodingr.r$flagsbodyr'xnamesnamefeatures r parse_future_flagsr?es '')CGGAJ Ewwy) vv+Z>vvndD1vvosD1(11$7 3A45GGAJ4D4DS4IJqQWWY__T*JEJ 3!*dD9W222E 3 3  LK  s$BD0&D+-D0D0+D00Ecddddddd}|jdr dg}|d d }n|jd r dg}|d d }ng}ttjd |D]F\}}|d zr|j || |s#|j tj |Htj dj|dz|jtjd}|d uS)aExtended 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 enumerater0r4appendescaperjoinreplaceossep)patternfilenamesymbolsbufidxpartrs r pathmatchrUsN  G#e!"+   D !e!"+rxx W=>( T 7 JJwt} %  JJryy ' ( HHRWWS\C')9)9"&&#)F GE  c0eZdZejdZy) TextWrapperz((\s+|(?<=[\w\!\"\'\&\.\,\?])-{2,}(?=\w))N)__name__ __module__ __qualname__r0compile wordsep_rerVr rXrXs /JrVrXcBt|||d}|j|S)aSimple 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)widthinitial_indentsubsequent_indentbreak_long_words)rXwrap)textr`rarbwrappers r wraptextrgs)n,=+02G << rVc6eZdZdZd dZdZdZdZdZdZ y) FixedOffsetTimezonez&Fixed offset in minutes east from UTC.NcBt||_|d|z}||_y)N)minutesz Etc/GMT%+d)r_offsetzone)selfoffsetr=s r __init__zFixedOffsetTimezone.__init__s$ 0 <&(D rVc|jSNrmrns r __str__zFixedOffsetTimezone.__str__ yyrVc<d|jd|jdS)Nz)rmrlrts r __repr__zFixedOffsetTimezone.__repr__s*.))T\\BBrVc|jSrr)rlrndts r utcoffsetzFixedOffsetTimezone.utcoffsets ||rVc|jSrrrsr{s r tznamezFixedOffsetTimezone.tznamervrVctSrr)ZEROr{s r dstzFixedOffsetTimezone.dsts rVrr) rYrZr[__doc__rpruryr}rrr^rVr riris$0 CrVric||kD||kz Srrr^)abs r _cmprs Ea!e rV)r)FrErE)%rr collectionsdatetimerrrMr0textwrappytz_pytzbabelrobjectmissingrr\VERBOSErr*r2r?rUrXrg OrderedDictodictriutcUTCLOCALTZ get_localzone STDOFFSET DSTOFFSETDSTDIFFrrr^rVr rs&  ((%"**0"**>/d%"**.0@>B(&&$ &6 ii   ''         ~~rV