ó
ži‚Nc           @   s«  d  d l  Z  e e  d e ƒ p* e  j d! k Z e  j d" k oH e  j d# k  Z e  j j d ƒ Z e  j j d	 ƒ Z	 e rˆ d  d
 l
 m Z n. y d  d
 l m Z Wn d  d
 l m Z n Xd  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z y d  d l Z d  d l Z Wn) e k
 rQd  d l Z d  d l Z n Xe	 s^e rje j Z n	 e j Z d „  Z y d  d l m Z Wn d „  Z n Xe rµd „  Z n	 d „  Z d „  Z d d „ Z! d e" f d „  ƒ  YZ# d e$ f d „  ƒ  YZ% d e" f d „  ƒ  YZ& d e$ f d „  ƒ  YZ' e j( d e j) ƒ Z* d „  Z+ d „  Z, d „  Z- y# d  d l. m/ Z/ m0 Z0 d „  Z1 Wn& e k
 r¦d  d l. Z. d  „  Z1 n Xd S($   iÿÿÿÿNt   py3kwarningi   i    i   i   i   t   javat   win(   t   StringIOc         C   s   | |  _  |  S(   sÈ   Return a function with a given __name__.

    Will assign to __name__ and return the original function if possible on
    the Python implementation, otherwise a new function will be constructed.

    (   t   __name__(   t   fnt   name(    (    s-   /usr/lib/python2.7/dist-packages/mako/util.pyt   function_named&   s    	(   t   partialc            s   ‡ ‡ ‡  f d †  } | S(   Nc             s*   ˆ j  ƒ  } | j | ƒ ˆ ˆ  |  | Ž  S(   N(   t   copyt   update(   t   fargst	   fkeywordst   newkeywords(   t   argst   funct   keywords(    s-   /usr/lib/python2.7/dist-packages/mako/util.pyt   newfunc4   s    (    (   R   R   R   R   (    (   R   R   R   s-   /usr/lib/python2.7/dist-packages/mako/util.pyR   3   s    c         C   s*   y |  j  j SWn t k
 r% |  j SXd  S(   N(   t	   __class__R   t   AttributeError(   t   exc(    (    s-   /usr/lib/python2.7/dist-packages/mako/util.pyt   exception_name;   s    c         C   s
   |  j  j S(   N(   R   R   (   R   (    (    s-   /usr/lib/python2.7/dist-packages/mako/util.pyR   A   s    c         C   s]   d } xP t  j j |  ƒ sX y | d 7} t  j |  d ƒ Wq	 | d k rU ‚  qU q	 Xq	 Wd S(   s,   create and/or verify a filesystem directory.i    i   iý  i   N(   t   ost   patht   existst   makedirs(   t   dirt   tries(    (    s-   /usr/lib/python2.7/dist-packages/mako/util.pyt   verify_directoryD   s    
c         C   s4   |  d  k r | St |  t t f ƒ s, |  g S|  Sd  S(   N(   t   Nonet
   isinstancet   listt   tuple(   t   xt   default(    (    s-   /usr/lib/python2.7/dist-packages/mako/util.pyt   to_listQ   s
    t   memoized_propertyc           B   s#   e  Z d  Z d d „ Z d „  Z RS(   s2   A read-only @property that is only evaluated once.c         C   s+   | |  _  | p | j |  _ | j |  _ d  S(   N(   t   fgett   __doc__R   (   t   selfR%   t   doc(    (    s-   /usr/lib/python2.7/dist-packages/mako/util.pyt   __init__\   s    	c         C   s1   | d  k r |  S|  j | ƒ | j |  j <} | S(   N(   R   R%   t   __dict__R   (   R'   t   objt   clst   result(    (    s-   /usr/lib/python2.7/dist-packages/mako/util.pyt   __get__a   s    N(   R   t
   __module__R&   R   R)   R.   (    (    (    s-   /usr/lib/python2.7/dist-packages/mako/util.pyR$   Z   s   t   SetLikeDictc           B   s   e  Z d  Z d „  Z RS(   s0   a dictionary that has some setlike methods on itc         C   s   t  |    } | j | ƒ | S(   s‰   produce a 'union' of this dict and another (at the key level).
 
        values in the second dict take precedence over that of the first(   R0   R
   (   R'   t   otherR!   (    (    s-   /usr/lib/python2.7/dist-packages/mako/util.pyt   unioni   s    (   R   R/   R&   R2   (    (    (    s-   /usr/lib/python2.7/dist-packages/mako/util.pyR0   g   s   t   FastEncodingBufferc           B   s2   e  Z d  Z d d e d „ Z d „  Z d „  Z RS(   sn   a very rudimentary buffer that is faster than StringIO, 
    but doesn't crash on unicode data like cStringIO.t   strictc         C   sX   t  j ƒ  |  _ | |  _ | r* d |  _ n	 d |  _ | |  _ | |  _ |  j j |  _ d  S(   Nu    t    (	   t   collectionst   dequet   datat   encodingt   delimt   unicodet   errorst   appendt   write(   R'   R9   R<   R;   (    (    s-   /usr/lib/python2.7/dist-packages/mako/util.pyR)   u   s    				c         C   s"   t  j ƒ  |  _ |  j j |  _ d  S(   N(   R6   R7   R8   R=   R>   (   R'   (    (    s-   /usr/lib/python2.7/dist-packages/mako/util.pyt   truncate€   s    c         C   sE   |  j  r. |  j j |  j ƒ j |  j  |  j ƒ S|  j j |  j ƒ Sd  S(   N(   R9   R:   t   joinR8   t   encodeR<   (   R'   (    (    s-   /usr/lib/python2.7/dist-packages/mako/util.pyt   getvalue„   s    	%N(   R   R/   R&   R   t   FalseR)   R?   RB   (    (    (    s-   /usr/lib/python2.7/dist-packages/mako/util.pyR3   q   s   	t   LRUCachec           B   s]   e  Z d  Z d e f d „  ƒ  YZ d d „ Z d „  Z d „  Z d „  Z d „  Z	 d	 „  Z
 RS(
   s&  A dictionary-like object that stores a limited number of items, discarding
    lesser used items periodically.
 
    this is a rewrite of LRUCache from Myghty to use a periodic timestamp-based
    paradigm so that synchronization is not really needed.  the size management 
    is inexact.
    t   _Itemc           B   s   e  Z d  „  Z d „  Z RS(   c         C   s"   | |  _  | |  _ t ƒ  |  _ d  S(   N(   t   keyt   valuet	   time_funct	   timestamp(   R'   RF   RG   (    (    s-   /usr/lib/python2.7/dist-packages/mako/util.pyR)   ”   s    		c         C   s   t  |  j ƒ S(   N(   t   reprRG   (   R'   (    (    s-   /usr/lib/python2.7/dist-packages/mako/util.pyt   __repr__˜   s    (   R   R/   R)   RK   (    (    (    s-   /usr/lib/python2.7/dist-packages/mako/util.pyRE   “   s   	g      à?c         C   s   | |  _  | |  _ d  S(   N(   t   capacityt	   threshold(   R'   RL   RM   (    (    s-   /usr/lib/python2.7/dist-packages/mako/util.pyR)   ›   s    	c         C   s%   t  j |  | ƒ } t ƒ  | _ | j S(   N(   t   dictt   __getitem__RH   RI   RG   (   R'   RF   t   item(    (    s-   /usr/lib/python2.7/dist-packages/mako/util.pyRO   Ÿ   s    c         C   s#   g  t  j |  ƒ D] } | j ^ q S(   N(   RN   t   valuesRG   (   R'   t   i(    (    s-   /usr/lib/python2.7/dist-packages/mako/util.pyRQ   ¤   s    c         C   s&   | |  k r |  | S| |  | <| Sd  S(   N(    (   R'   RF   RG   (    (    s-   /usr/lib/python2.7/dist-packages/mako/util.pyt
   setdefault§   s    
c         C   s]   t  j |  | ƒ } | d  k rF |  j | | ƒ } t  j |  | | ƒ n	 | | _ |  j ƒ  d  S(   N(   RN   t   getR   RE   t   __setitem__RG   t   _manage_size(   R'   RF   RG   RP   (    (    s-   /usr/lib/python2.7/dist-packages/mako/util.pyRU   ®   s    	c         C   s“   xŒ t  |  ƒ |  j |  j |  j k rŽ t t j |  ƒ d t j d ƒ d t ƒ} x8 | |  j D]) } y |  | j	 =Wq^ t
 k
 r† Pq^ Xq^ Wq Wd  S(   NRF   RI   t   reverse(   t   lenRL   RM   t   sortedRN   RQ   t   operatort
   attrgettert   TrueRF   t   KeyError(   R'   t   bytimeRP   (    (    s-   /usr/lib/python2.7/dist-packages/mako/util.pyRV   ·   s    &(   R   R/   R&   t   objectRE   R)   RO   RQ   RS   RU   RV   (    (    (    s-   /usr/lib/python2.7/dist-packages/mako/util.pyRD   Š   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 | j	 d d ƒ ƒ } | sä y) d d l
 } | j | j	 d d ƒ ƒ Wn t t f k
 r¹ qä X|  j ƒ  } t j | j	 d d ƒ ƒ } n  | r | rü t d ‚ n  d S| r| j d ƒ Sd SWd |  j | ƒ Xd S(	   s  Deduce the encoding of a Python source file (binary mode) 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 in binary mode.
    i    t   asciit   ignoreiÿÿÿÿ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_UTF8RX   t   _PYTHON_MAGIC_COMMENT_ret   matcht   decodet   parsert   suitet   ImportErrort   SyntaxErrort   groupR   (   t   fpt   post   line1t   has_bomt   mRl   t   line2(    (    s-   /usr/lib/python2.7/dist-packages/mako/util.pyt   parse_encodingÈ   s2    		c         C   sL   |  j  ƒ  } | j ƒ  d d j g  | D] } d | |  | f ^ q& ƒ d S(   s}   repr() a dictionary with the keys in order.
 
    Used by the lexer unit test to compare parse trees based on strings.
 
    t   {s   , s   %r: %rt   }(   t   keyst   sortR@   (   t   dRz   t   k(    (    s-   /usr/lib/python2.7/dist-packages/mako/util.pyt   sorted_dict_reprõ   s    
c         C   sÓ  t  |  d ƒ r d Sd |  _ t d d d |  j ƒ } t | ƒ |  _ xJ |  j j D]< } | j d k rq | |  _ qP | j d k rP | |  _ qP qP Wt | j	 d	 ƒ |  _
 t | j	 d
 ƒ |  _ t | j	 d ƒ |  _ t | j	 d j d	 ƒ |  _ t | j	 d j d	 j ƒ |  _ t | j	 d j ƒ |  _ t | j	 d j j ƒ |  _ t | j	 d j j j ƒ |  _ t | j	 d j j j ƒ |  _ t | j	 d j j j j ƒ |  _ t | j	 d j j ƒ |  _ t | j	 d j j j ƒ |  _ t | j	 d j j j j ƒ |  _ t | j	 d j j j j j ƒ |  _ t | j	 d j j ƒ |  _ t | j	 d j j j ƒ |  _ t | j	 d j j j j ƒ |  _  t | j	 d j j ƒ |  _! t | j	 d j j" d	 j ƒ |  _# t | j	 d j j j ƒ |  _$ t | j	 d j j j j ƒ |  _% t | j	 d j j j j& j ƒ |  _' t | j	 d j j j j ƒ |  _( t | j	 d j j ƒ |  _! t | j	 d j j" d	 j ƒ |  _# t | j	 d j j) d	 ƒ |  _* t | j	 d j j) d
 ƒ |  _+ t | j	 d j j j) d	 ƒ |  _, t | j	 d j j j) d
 ƒ |  _- t | j	 d j j) d	 ƒ |  _. t | j	 d j j) d
 ƒ |  _/ t | j	 d j j) d ƒ |  _0 t | j	 d j j) d ƒ |  _1 t | j	 d j j) d	 ƒ |  _2 t | j	 d j j) d
 ƒ |  _3 d S(   sd   Attempt to restore the required classes to the _ast module if it
    appears to be missing them
    t   ASTNi   i	   s  def foo(): pass
class Bar(object): pass
if False: pass
baz = 'mako'
1 + 2 - 3 * 4 / 5
6 // 7 % 8 << 9 >> 10
11 & 12 ^ 13 | 14
15 and 16 or 17
-baz + (not +18) - ~17
baz and 'foo' or 'bar'
(mako is baz == baz) is not baz != mako
mako > baz < mako >= baz <= mako
mako in baz not in makos	   <unknown>t   exect   modi    i   i   i   i   i   i   i   i
   i   i   i   (4   t   hasattrt   PyCF_ONLY_ASTt   compilet   typet   Modulet   __mro__R   R   R   t   bodyt   FunctionDeft   ClassDeft   Ift   targetst   Namet   ctxt   StoreRG   t   Strt   opt   Subt   leftt   Addt   rightt   Divt   Multt   RShiftt   LShiftt   Modt   FloorDivt   BitOrt   BitXort   BitAndt   OrRQ   t   Andt   Invertt   Nott   operandt   UAddt   USubt   opst   IsNott   NotEqt   Ist   Eqt   Gtt   Ltt   GtEt   LtEt   Int   NotIn(   t   _astRu   R,   (    (    s-   /usr/lib/python2.7/dist-packages/mako/util.pyt   restore__astÿ   s\    	 ""%"#"%"#  ##     (   t   CO_VARKEYWORDSt
   CO_VARARGSc         C   sŽ   |  j  } | j } | j } t | |  ƒ } d  } | j t @rX | j | } | d } n  d  } | j t @r{ | j | } n  | | | |  j f S(   Ni   (	   t	   func_codet   co_argcountt   co_varnamesR   R   t   co_flagsR´   R³   t   func_defaults(   R   t   cot   nargst   namesR   t   varargst   varkw(    (    s-   /usr/lib/python2.7/dist-packages/mako/util.pyt   inspect_func_argsM  s    			c         C   s   t  j |  ƒ S(   N(   t   inspectt
   getargspec(   R   (    (    s-   /usr/lib/python2.7/dist-packages/mako/util.pyR¿   _  s    (   i   i    (   i   i   (   i   i   (2   t   syst   getattrRC   t   version_infot   py3kt   py24t   platformRf   t   jythont   win32t   ioR   t	   cStringIORg   t   ret   weakrefR   t   timeRZ   R6   t	   threadingt   threadRn   t   dummy_threadingt   dummy_threadt   clockRH   R   t	   functoolsR   R   R   R   R#   R_   R$   RN   R0   R3   RD   R„   t   VERBOSERi   Rw   R~   R²   RÀ   R³   R´   R¿   (    (    (    s-   /usr/lib/python2.7/dist-packages/mako/util.pyt   <module>   s^   !H		
			
:	-	
	L