ó
µ”ù\c           @   sk  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	 m
 Z
 m 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 d e j f d „  ƒ  YZ d d d d „ Z e j Z d e f d „  ƒ  YZ e j Z  e j! Z! e j" Z" e j# Z# e j$ Z$ e j% Z% e j& Z& d S(   s®   
    babel.util
    ~~~~~~~~~~

    Various utility classes and functions.

    :copyright: (c) 2013-2019 by the Babel Team.
    :license: BSD, see LICENSE for more details.
iÿÿÿÿN(   t	   timedeltat   tzinfo(   t   izipt   imap(   t	   localtimec         c   sE   t  ƒ  } x5 t |  ƒ D]' } | | k r | V| j | ƒ q q Wd S(   s–  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(   t   sett   itert   add(   t   iterablet   seent   item(    (    s)   lib/python2.7/site-packages/babel/util.pyt   distinct   s
    	s(   [ \t\f]* \# .* coding[=:][ \t]*([-\w.]+)c         C   sQ  |  j  ƒ  } |  j d ƒ z#|  j ƒ  } | j t j ƒ } | rV | t t j ƒ } n  t j | ƒ } | sÌ y& d d l	 } | j
 | j d ƒ ƒ Wn t t t f k
 r­ qÌ X|  j ƒ  } t j | ƒ } n  | r| r| j d ƒ j d ƒ } | d k rt d j | ƒ ƒ ‚ qn  d S| r7| j d ƒ j d ƒ Sd SWd |  j | ƒ Xd S(   s/  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)
    i    iÿÿÿÿNs   latin-1i   s   utf-8s   encoding problem: {0} with BOM(   t   tellt   seekt   readlinet
   startswitht   codecst   BOM_UTF8t   lent   PYTHON_MAGIC_COMMENT_ret   matcht   parsert   suitet   decodet   ImportErrort   SyntaxErrort   UnicodeEncodeErrort   groupt   formatt   None(   t   fpt   post   line1t   has_bomt   mR   t   line2t   magic_comment_encoding(    (    s)   lib/python2.7/site-packages/babel/util.pyt   parse_encoding1   s8    s'   from\s+__future__\s+import\s+\(*(.+)\)*s   latin-1c         C   s%  d d l  } |  j ƒ  } |  j d ƒ d } zå |  j ƒ  j | ƒ } t j d d | ƒ } t j d d | ƒ } t j d d	 | ƒ } xŠ t j | ƒ D]y } g  | j	 d
 ƒ j
 d ƒ D] } | j ƒ  j d ƒ ^ q± } x6 | D]. }	 t | |	 d ƒ }
 |
 rÙ | |
 j O} qÙ qÙ Wq’ WWd |  j | ƒ X| S(   sR   Parse the compiler flags by :mod:`__future__` from the given Python
    code.
    iÿÿÿÿNi    s   import\s*\([\r\n]+s   import (s   ,\s*[\r\n]+s   , s   \\\s*[\r\n]+t    i   t   ,s   ()(   t
   __future__R   R   t   readR   t   ret   subt   PYTHON_FUTURE_IMPORT_ret   finditerR   t   splitt   stript   getattrR   t   compiler_flag(   R   t   encodingR(   R   t   flagst   bodyR"   t   xt   namest   namet   feature(    (    s)   lib/python2.7/site-packages/babel/util.pyt   parse_future_flagsg   s"    :c         C   s  i d d 6d d 6d d 6d d 6d	 d
 6d d 6} |  j  d ƒ rU d g } |  d }  n+ |  j  d ƒ rz d g } |  d }  n g  } xc t t j d |  ƒ ƒ D]I \ } } | d rÃ | j | | ƒ q™ | r™ | j t j | ƒ ƒ q™ q™ Wt j d j | ƒ d | j t	 j
 d ƒ ƒ } | d k	 S(   sø  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
    s   [^/]t   ?s   [^/]/s   ?/s   [^/]+t   *s   [^/]+/s   */s	   (?:.+/)*?s   **/s   (?:.+/)*?[^/]+s   **t   ^i   s   ./i   s	   ([?*]+/?)t    t   $t   /N(   R   t	   enumerateR*   R.   t   appendt   escapeR   t   joint   replacet   ost   sepR   (   t   patternt   filenamet   symbolst   buft   idxt   partR   (    (    s)   lib/python2.7/site-packages/babel/util.pyt	   pathmatch‡   s*    &
		%
.t   TextWrapperc           B   s   e  Z e j d  ƒ Z RS(   s(   (\s+|(?<=[\w\!\"\'\&\.\,\?])-{2,}(?=\w))(   t   __name__t
   __module__R*   t   compilet
   wordsep_re(    (    (    s)   lib/python2.7/site-packages/babel/util.pyRN   È   s   iF   R=   c      	   C   s.   t  d | d | d | d t ƒ } | j |  ƒ S(   sØ  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
    t   widtht   initial_indentt   subsequent_indentt   break_long_words(   RN   t   Falset   wrap(   t   textRS   RT   RU   t   wrapper(    (    s)   lib/python2.7/site-packages/babel/util.pyt   wraptextÏ   s    	t   FixedOffsetTimezonec           B   sG   e  Z d  Z d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z	 RS(   s&   Fixed offset in minutes east from UTC.c         C   s8   t  d | ƒ |  _ | d  k r+ d | } n  | |  _ d  S(   Nt   minutess
   Etc/GMT%+d(   R    t   _offsetR   t   zone(   t   selft   offsetR7   (    (    s)   lib/python2.7/site-packages/babel/util.pyt   __init__ç   s    c         C   s   |  j  S(   N(   R_   (   R`   (    (    s)   lib/python2.7/site-packages/babel/util.pyt   __str__í   s    c         C   s   d |  j  |  j f S(   Ns   <FixedOffset "%s" %s>(   R_   R^   (   R`   (    (    s)   lib/python2.7/site-packages/babel/util.pyt   __repr__ð   s    c         C   s   |  j  S(   N(   R^   (   R`   t   dt(    (    s)   lib/python2.7/site-packages/babel/util.pyt	   utcoffsetó   s    c         C   s   |  j  S(   N(   R_   (   R`   Re   (    (    s)   lib/python2.7/site-packages/babel/util.pyt   tznameö   s    c         C   s   t  S(   N(   t   ZERO(   R`   Re   (    (    s)   lib/python2.7/site-packages/babel/util.pyt   dstù   s    N(
   RO   RP   t   __doc__R   Rb   Rc   Rd   Rf   Rg   Ri   (    (    (    s)   lib/python2.7/site-packages/babel/util.pyR\   ä   s   				('   Rj   R   t   collectionst   datetimeR    R   RE   R*   t   textwrapt   babel._compatR   R   t   pytzt   _pytzt   babelR   t   objectt   missingR   RQ   t   VERBOSER   R%   R,   R9   RM   RN   R[   t   OrderedDictt   odictR\   t   utct   UTCt   LOCALTZt   get_localzonet	   STDOFFSETt	   DSTOFFSETt   DSTDIFFRh   (    (    (    s)   lib/python2.7/site-packages/babel/util.pyt   <module>
   s:   			2	 	A							