ó
™‚Mc           @   s™  d  Z  d d l Z d d l m Z m Z d d l Z d d l Z y
 e Z Wn! e k
 rm d d l	 m
 Z n Xd d l Z d d l Z d d l m Z m Z e ƒ  Z d d d d	 d
 d d g Z d Z d „  Z e j d e j ƒ Z d „  Z d „  Z d e j f d „  ƒ  YZ d d d d „ Z d
 e f d „  ƒ  YZ y e j j Z Wn e  k
 rfd d „ Z n Xy d d l! m" Z" m# Z# Wn e$ k
 rd „  Z# n Xy d j% d d d „ Z% Wn  e  k
 rÚd d d „ Z% n Xe d ƒ Z' d e f d  „  ƒ  YZ( y d d! l) m* Z* Wn  e$ k
 r3e( d d ƒ Z* n Xe d" e j+ ƒ Z, e j- rfe d" e j. ƒ Z/ n e, Z/ e/ e, Z0 d# e f d$ „  ƒ  YZ1 e1 ƒ  Z2 d S(%   s&   Various utility classes and functions.iÿÿÿÿN(   t	   timedeltat   tzinfo(   t   Set(   t   izipt   imapt   distinctt	   pathmatcht   relpatht   wraptextt   odictt   UTCt   LOCALTZs   restructuredtext enc         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
    :return: the distinct items in the collection
    :rtype: ``iterator``
    N(   t   sett   itert   add(   t   iterablet   seent   item(    (    s.   /usr/lib/python2.7/site-packages/babel/util.pyR   "   s
    	s(   [ \t\f]* \# .* coding[=:][ \t]*([-\w.]+)c         C   s  |  j  ƒ  } |  j d ƒ zÞ |  j ƒ  } | j t j ƒ } | rV | t t j ƒ } n  t j | ƒ } | sÀ y d d l	 } | j
 | ƒ Wn t t f k
 r¡ qÀ X|  j ƒ  } t j | ƒ } n  | rß | rÛ t d ƒ ‚ n  d S| rò | 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`__

    .. __: http://docs.python.org/ref/encodings.html

    The ``fp`` argument should be a seekable file object.

    (From Jeff Dairiki)
    i    iÿÿÿÿNs\   python refuses to compile code with both a UTF8 byte-order-mark and a magic encoding commentt   utf_8i   (   t   tellt   seekt   readlinet
   startswitht   codecst   BOM_UTF8t   lent   PYTHON_MAGIC_COMMENT_ret   matcht   parsert   suitet   ImportErrort   SyntaxErrort   groupt   None(   t   fpt   post   line1t   has_bomt   mR   t   line2(    (    s.   /usr/lib/python2.7/site-packages/babel/util.pyt   parse_encoding:   s2    c         C   sÔ   i d d 6d d 6d d 6d d 6d	 d
 6d d 6} g  } xc t  t j d |  ƒ ƒ D]I \ } } | d ry | j | | ƒ qO | rO | j t j | ƒ ƒ qO qO 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('**/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
    :return: `True` if the path name matches the pattern, `False` otherwise
    :rtype: `bool`
    s   [^/]t   ?s   [^/]/s   ?/s   [^/]+t   *s   [^/]+/s   */s	   (?:.+/)*?s   **/s   (?:.+/)*?[^/]+s   **s	   ([?*]+/?)i   t    t   $t   /N(   t	   enumeratet   ret   splitt   appendt   escapeR   t   joint   replacet   ost   sepR!   (   t   patternt   filenamet   symbolst   buft   idxt   partR   (    (    s.   /usr/lib/python2.7/site-packages/babel/util.pyR   i   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.   /usr/lib/python2.7/site-packages/babel/util.pyR=   ™   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
    :return: a list of lines
    :rtype: `list`
    t   widtht   initial_indentt   subsequent_indentt   break_long_words(   R=   t   Falset   wrap(   t   textRB   RC   RD   t   wrapper(    (    s.   /usr/lib/python2.7/site-packages/babel/util.pyR       s    	c           B   s¤   e  Z d  Z d d „ Z d „  Z d „  Z d „  Z e Z d „  Z	 d „  Z
 d „  Z d „  Z d	 „  Z e d
 „ Z d „  Z d d „ Z d „  Z d „  Z d „  Z RS(   so   Ordered dict implementation.
    
    :see: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/107747
    c         C   s,   t  j |  | p i  ƒ t  j |  ƒ |  _ d  S(   N(   t   dictt   __init__t   keyst   _keys(   t   selft   data(    (    s.   /usr/lib/python2.7/site-packages/babel/util.pyRK   ¸   s    c         C   s$   t  j |  | ƒ |  j j | ƒ d  S(   N(   RJ   t   __delitem__RM   t   remove(   RN   t   key(    (    s.   /usr/lib/python2.7/site-packages/babel/util.pyRP   ¼   s    c         C   s9   t  j |  | | ƒ | |  j k r5 |  j j | ƒ n  d  S(   N(   RJ   t   __setitem__RM   R1   (   RN   RR   R   (    (    s.   /usr/lib/python2.7/site-packages/babel/util.pyRS   À   s    c         C   s   t  |  j ƒ S(   N(   R   RM   (   RN   (    (    s.   /usr/lib/python2.7/site-packages/babel/util.pyt   __iter__Å   s    c         C   s   t  j |  ƒ g  |  _ d  S(   N(   RJ   t   clearRM   (   RN   (    (    s.   /usr/lib/python2.7/site-packages/babel/util.pyRU   É   s    c         C   s   t  ƒ  } | j |  ƒ | S(   N(   R	   t   update(   RN   t   d(    (    s.   /usr/lib/python2.7/site-packages/babel/util.pyt   copyÍ   s    	c         C   s   t  |  j |  j ƒ  ƒ S(   N(   t   zipRM   t   values(   RN   (    (    s.   /usr/lib/python2.7/site-packages/babel/util.pyt   itemsÒ   s    c         C   s   t  |  j |  j ƒ  ƒ S(   N(   R   RM   t
   itervalues(   RN   (    (    s.   /usr/lib/python2.7/site-packages/babel/util.pyt	   iteritemsÕ   s    c         C   s   |  j  S(   N(   RM   (   RN   (    (    s.   /usr/lib/python2.7/site-packages/babel/util.pyRL   Ø   s    c         C   sO   | t  k r t j |  | ƒ S| |  k r, | S|  j j | ƒ t j |  | | ƒ S(   N(   t   missingRJ   t   popRM   RQ   (   RN   RR   t   default(    (    s.   /usr/lib/python2.7/site-packages/babel/util.pyR_   Û   s    c         C   s   |  j  j | ƒ t j | ƒ S(   N(   RM   RQ   RJ   t   popitem(   RN   RR   (    (    s.   /usr/lib/python2.7/site-packages/babel/util.pyRa   ã   s    c         C   s9   t  j |  | | ƒ | |  j k r5 |  j j | ƒ n  d  S(   N(   RJ   t
   setdefaultRM   R1   (   RN   RR   t   failobj(    (    s.   /usr/lib/python2.7/site-packages/babel/util.pyRb   ç   s    c         C   s+   x$ | j  ƒ  D] \ } } | |  | <q Wd  S(   N(   R[   (   RN   RJ   RR   t   val(    (    s.   /usr/lib/python2.7/site-packages/babel/util.pyRV   ì   s    c         C   s   t  |  j |  j ƒ S(   N(   t   mapt   getRM   (   RN   (    (    s.   /usr/lib/python2.7/site-packages/babel/util.pyRZ   ð   s    c         C   s   t  |  j |  j ƒ S(   N(   R   Rf   RM   (   RN   (    (    s.   /usr/lib/python2.7/site-packages/babel/util.pyR\   ó   s    N(   R>   R?   t   __doc__R!   RK   RP   RS   RT   t   iterkeysRU   RX   R[   R]   RL   R^   R_   Ra   Rb   RV   RZ   R\   (    (    (    s.   /usr/lib/python2.7/site-packages/babel/util.pyR	   ³   s"   											t   .c         C   s   t  j j | ƒ j t  j ƒ } t  j j |  ƒ j t  j ƒ } t t  j j | | g ƒ ƒ } t  j j g t | ƒ | | | } t  j j | Œ  S(   s‰  Compute the relative path to one path from another.
        
        >>> relpath('foo/bar.txt', '').replace(os.sep, '/')
        'foo/bar.txt'
        >>> relpath('foo/bar.txt', 'foo').replace(os.sep, '/')
        'bar.txt'
        >>> relpath('foo/bar.txt', 'baz').replace(os.sep, '/')
        '../foo/bar.txt'
        
        :return: the relative path
        :rtype: `basestring`
        (	   R5   t   patht   abspathR0   R6   R   t   commonprefixt   pardirR3   (   Rj   t   startt
   start_listt	   path_listt   it   rel_list(    (    s.   /usr/lib/python2.7/site-packages/babel/util.pyR   ú   s
    %(   t
   attrgettert
   itemgetterc            s   ‡  f d †  } | S(   Nc            s   |  ˆ  S(   N(    (   t   obj(   t   name(    s.   /usr/lib/python2.7/site-packages/babel/util.pyt   _getitem  s    (    (   Rv   Rw   (    (   Rv   s.   /usr/lib/python2.7/site-packages/babel/util.pyRt     s    c         C   s   |  j  | | ƒ S(   N(   t   rsplit(   t   a_stringR6   t   maxsplit(    (    s.   /usr/lib/python2.7/site-packages/babel/util.pyRx     s    c         C   si   |  j  | ƒ } | d  k s- t | ƒ | k r1 | St | ƒ | } | j | |  ƒ } | | } | g | S(   N(   R0   R!   R   R3   (   Ry   R6   Rz   t   partst   maxsplit_indext   non_splitted_partt   splitted(    (    s.   /usr/lib/python2.7/site-packages/babel/util.pyRx     s    
i    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(   RN   t   offsetRv   (    (    s.   /usr/lib/python2.7/site-packages/babel/util.pyRK   ,  s    c         C   s   |  j  S(   N(   R‚   (   RN   (    (    s.   /usr/lib/python2.7/site-packages/babel/util.pyt   __str__2  s    c         C   s   d |  j  |  j f S(   Ns   <FixedOffset "%s" %s>(   R‚   R   (   RN   (    (    s.   /usr/lib/python2.7/site-packages/babel/util.pyt   __repr__5  s    c         C   s   |  j  S(   N(   R   (   RN   t   dt(    (    s.   /usr/lib/python2.7/site-packages/babel/util.pyt	   utcoffset8  s    c         C   s   |  j  S(   N(   R‚   (   RN   R†   (    (    s.   /usr/lib/python2.7/site-packages/babel/util.pyt   tzname;  s    c         C   s   t  S(   N(   t   ZERO(   RN   R†   (    (    s.   /usr/lib/python2.7/site-packages/babel/util.pyt   dst>  s    N(
   R>   R?   Rg   R!   RK   R„   R…   R‡   Rˆ   RŠ   (    (    (    s.   /usr/lib/python2.7/site-packages/babel/util.pyR   )  s   				(   R
   t   secondst   LocalTimezonec           B   s,   e  Z d  „  Z d „  Z d „  Z d „  Z RS(   c         C   s   |  j  | ƒ r t St Sd  S(   N(   t   _isdstt	   DSTOFFSETt	   STDOFFSET(   RN   R†   (    (    s.   /usr/lib/python2.7/site-packages/babel/util.pyR‡   V  s    c         C   s   |  j  | ƒ r t St Sd  S(   N(   R   t   DSTDIFFR‰   (   RN   R†   (    (    s.   /usr/lib/python2.7/site-packages/babel/util.pyRŠ   \  s    c         C   s   t  j |  j | ƒ S(   N(   t   timeRˆ   R   (   RN   R†   (    (    s.   /usr/lib/python2.7/site-packages/babel/util.pyRˆ   b  s    c      	   C   sd   | j  | j | j | j | j | j | j ƒ  d d f	 } t j | ƒ } t j	 | ƒ } | j
 d k S(   Ni    iÿÿÿÿ(   t   yeart   montht   dayt   hourt   minutet   secondt   weekdayR‘   t   mktimet	   localtimet   tm_isdst(   RN   R†   t   ttt   stamp(    (    s.   /usr/lib/python2.7/site-packages/babel/util.pyR   e  s    (   R>   R?   R‡   RŠ   Rˆ   R   (    (    (    s.   /usr/lib/python2.7/site-packages/babel/util.pyRŒ   T  s   			(3   Rg   R   t   datetimeR    R   R5   R/   R   t	   NameErrort   setsR   t   textwrapR‘   t	   itertoolsR   R   t   objectR^   t   __all__t   __docformat__R   R@   t   VERBOSER   R(   R   R=   R   RJ   R	   Rj   R   t   AttributeErrort   operatorRs   Rt   R   Rx   R!   R‰   R   t   pytzR
   t   timezoneR   t   daylightt   altzoneRŽ   R   RŒ   R   (    (    (    s.   /usr/lib/python2.7/site-packages/babel/util.pyt   <module>   sf   
				/	0D		
	