ó
ú2ec           @   s  d  Z  d d l Z d d g Z d Z e d Z e d Z e d Z e d Z e d	 Z e d
 Z	 i e	 d 6e d 6e d 6e d 6e d 6e d 6e d 6Z
 e e
 j ƒ  ƒ Z e j d d „  d e ƒ e d „ Z e j d ƒ Z d „  Z d „  Z e d k rd d l Z e j ƒ  n  d S(   s  
DateInterval.py

Convert interval strings (in the form of 1w2d, etc) to
seconds, and back again.  Is not exactly about months or
years (leap years in particular).

Accepts (y)ear, (b)month, (w)eek, (d)ay, (h)our, (m)inute, (s)econd.

Exports only timeEncode and timeDecode functions.
iÿÿÿÿNt   interval_decodet   interval_encodei   i<   i   i   i   im  t   yt   bt   wt   dt   ht   mt   st   keyc         C   s   |  d S(   Ni   (    (   t   x(    (    sA   /usr/local/lib/python2.7/dist-packages/paste/util/dateinterval.pyt   <lambda>"   t    t   reversec         C   s¡   d } |  } t  |  ƒ }  xL t D]D \ } } |  | k r t |  | ƒ \ } }  | d | | f 7} q q W| d k  r€ d | } n | sŠ d S| r d | } n  | S(   sµ   Encodes a number of seconds (representing a time interval)
    into a form like 1h2d3s.

    >>> interval_encode(10)
    '10s'
    >>> interval_encode(493939)
    '5d17h12m19s'
    R   s   %i%si    t   -t   0t   +(   t   abst   timeOrderedt   divmod(   t   secondst   include_signR   t   origt   chart   amountt   i(    (    sA   /usr/local/lib/python2.7/dist-packages/paste/util/dateinterval.pyR   %   s    	s   [0-9]+[a-zA-Z]c         C   sÄ   d } d } |  j  ƒ  }  |  j d ƒ r: |  d }  d } n |  j d ƒ rV |  d }  n  xg t |  t ƒ D]V } | j d ƒ d j ƒ  } | t k r— qf n  | t | j d ƒ d  ƒ t | 7} qf W| S(   sä   Decodes a number in the format 1h4d3m (1 hour, 3 days, 3 minutes)
    into a number of seconds

    >>> interval_decode('40s')
    40
    >>> interval_decode('10000s')
    10000
    >>> interval_decode('3d1w45s')
    864045
    i    i   R   iÿÿÿÿR   (   t   stript
   startswitht
   allMatchest   _timeREt   groupt   lowert
   timeValuest   int(   R   t   timet   signt   matchR   (    (    sA   /usr/local/lib/python2.7/dist-packages/paste/util/dateinterval.pyR    >   s    
	)c         C   s`   d } t  |  ƒ } g  } | j |  | ƒ } x/ | r[ | j | ƒ | j |  | j ƒ  ƒ } q- W| S(   s1   Return a list of matches for regex in source
    i    (   t   lent   searcht   appendt   end(   t   sourcet   regext   posR(   t   rvR$   (    (    sA   /usr/local/lib/python2.7/dist-packages/paste/util/dateinterval.pyR   Z   s    	t   __main__(   t   __doc__t   ret   __all__t   secondt   minutet   hourt   dayt   weekt   montht   yearR    t   listt   itemsR   t   sortt   Truet   FalseR   t   compileR   R    R   t   __name__t   doctestt   testmod(    (    (    sA   /usr/local/lib/python2.7/dist-packages/paste/util/dateinterval.pyt   <module>   s4   






		