ó
iNc           @   sŹ   d  d l  Z  d  d l Z d  d l Z d  d l Z d  d l m Z m Z d  d l m Z y d  d l	 Z	 Wn d  d l
 Z	 n Xd e f d     YZ d e f d     YZ d S(   i˙˙˙˙N(   t
   exceptionst   util(   t   Templatet   TemplateCollectionc           B   s5   e  Z d  Z d   Z d d  Z d   Z d   Z RS(   sA  Represent a collection of :class:`.Template` objects, 
    identifiable via uri.
 
    A :class:`.TemplateCollection` is linked to the usage of
    all template tags that address other templates, such 
    as ``<%include>``, ``<%namespace>``, and ``<%inherit>``.
    The ``file`` attribute of each of those tags refers
    to a string URI that is passed to that :class:`.Template`
    object's :class:`.TemplateCollection` for resolution.
 
    :class:`.TemplateCollection` is an abstract class,
    with the usual default implementation being :class:`.TemplateLookup`.
 
     c         C   s1   y |  j  |  t SWn t j k
 r, t SXd S(   sŇ   Return ``True`` if this :class:`.TemplateLookup` is
        capable of returning a :class:`.Template` object for the
        given URL.

        :param uri: String uri of the template to be resolved.
 
        N(   t   get_templatet   TrueR    t   TemplateLookupExceptiont   False(   t   selft   uri(    (    s/   /usr/lib/python2.7/dist-packages/mako/lookup.pyt   has_template    s
    c         C   s   t     d S(   sÄ  Return a :class:`.Template` object corresponding to the given 
        URL.
 
        The default implementation raises
        :class:`.NotImplementedError`. Implementations should
        raise :class:`.TemplateLookupException` if the given uri
        cannot be resolved.
 
        :param uri: String uri of the template to be resolved.
        :param relativeto: if present, the given URI is assumed to 
         be relative to this uri.
 
        N(   t   NotImplementedError(   R   R	   t
   relativeto(    (    s/   /usr/lib/python2.7/dist-packages/mako/lookup.pyR   .   s    c         C   s   | S(   sT   Convert the given filename to a uri relative to 
           this TemplateCollection.(    (   R   R	   t   filename(    (    s/   /usr/lib/python2.7/dist-packages/mako/lookup.pyt   filename_to_uri>   s    c         C   s   | S(   sź  Adjust the given uri based on the calling filename.
 
        When this method is called from the runtime, the
        'filename' parameter is taken directly to the 'filename'
        attribute of the calling template. Therefore a custom
        TemplateCollection subclass can place any string
        identifier desired in the "filename" parameter of the
        Template objects it constructs and have them come back
        here.
 
        (    (   R   R	   R   (    (    s/   /usr/lib/python2.7/dist-packages/mako/lookup.pyt
   adjust_uriD   s    N(   t   __name__t
   __module__t   __doc__R
   t   NoneR   R   R   (    (    (    s/   /usr/lib/python2.7/dist-packages/mako/lookup.pyR      s
   		t   TemplateLookupc           B   s   e  Z d  Z d d e d e d e e d d d d d e d d d e d d d d  Z d   Z d   Z d   Z	 d   Z
 d   Z d	   Z d
   Z d   Z RS(   sľ	  Represent a collection of templates that locates template source files
    from the local filesystem.
 
    The primary argument is the ``directories`` argument, the list of
    directories to search::
 
        lookup = TemplateLookup(["/path/to/templates"])
        some_template = lookup.get_template("/index.html")
 
    The :class:`.TemplateLookup` can also be given :class:`.Template` objects
    programatically using :meth:`.put_string` or :meth:`.put_template`::
 
        lookup = TemplateLookup()
        lookup.put_string("base.html", '''
            <html><body>${self.next()}</body></html>
        ''')
        lookup.put_string("hello.html", '''
            <%include file='base.html'/>
 
            Hello, world !
        ''')
 
 
    :param directories: A list of directory names which will be 
     searched for a particular template URI. The URI is appended
     to each directory and the filesystem checked.
 
    :param collection_size: Approximate size of the collection used 
     to store templates. If left at its default of -1, the size
     is unbounded, and a plain Python dictionary is used to
     relate URI strings to :class:`.Template` instances.
     Otherwise, a least-recently-used cache object is used which
     will maintain the size of the collection approximately to
     the number given.
 
    :param filesystem_checks: When at its default value of ``True``, 
     each call to :meth:`TemplateLookup.get_template()` will
     compare the filesystem last modified time to the time in
     which an existing :class:`.Template` object was created.
     This allows the :class:`.TemplateLookup` to regenerate a
     new :class:`.Template` whenever the original source has
     been updated. Set this to ``False`` for a very minor
     performance increase.
 
    :param modulename_callable: A callable which, when present, 
     is passed the path of the source file as well as the
     requested URI, and then returns the full path of the
     generated Python module file. This is used to inject
     alternate schemes for Pyhton module location. If left at
     its default of ``None``, the built in system of generation
     based on ``module_directory`` plus ``uri`` is used.
 
    All other keyword parameters available for
    :class:`.Template` are mirrored here. When new
    :class:`.Template` objects are created, the keywords
    established with this :class:`.TemplateLookup` are passed on
    to each new :class:`.Template`.
 
    i˙˙˙˙t   strictc         C   s3  g  t  j | d  D] } t j |  ^ q |  _ | |  _ | |  _ | |  _ | |  _ i | d 6| d 6| d 6| d 6|	 d 6|
 d 6| d 6| d 6| d	 6| p  | d
 6| d 6| d 6| d 6| d 6| d 6| d 6| d 6|  _	 | d k rü i  |  _
 i  |  _ n$ t  j |  |  _
 t  j |  |  _ t j   |  _ d  S(   Nt   format_exceptionst   error_handlert   disable_unicodet   bytestring_passthrought   output_encodingt   encoding_errorst   input_encodingt   module_directoryt
   cache_typet	   cache_dirt	   cache_urlt   cache_enabledt   default_filterst   buffer_filterst   strict_undefinedt   importst   preprocessori˙˙˙˙(    (   R   t   to_listt	   posixpatht   normpatht   directoriesR   t   modulename_callablet   filesystem_checkst   collection_sizet   template_argst   _collectiont
   _uri_cachet   LRUCachet	   threadingt   Lockt   _mutex(   R   R*   R   R,   R-   R   R   R   R   R   R   R   R   R    R!   R+   R"   R#   R$   R%   R   R&   t   d(    (    s/   /usr/lib/python2.7/dist-packages/mako/lookup.pyt   __init__   s<    .					c         C   sŔ   y/ |  j  r# |  j | |  j |  S|  j | SWn t k
 rť t j d d |  } xe |  j D]C } t j t j	 | |   } t
 j j |  r^ |  j | |  Sq^ Wt j d |   n Xd S(   s¤   Return a :class:`.Template` object corresponding to the given 
        URL.
 
        Note the "relativeto" argument is not supported here at the moment.
 
        s   ^\/+t    s   Cant locate template for uri %rN(   R,   t   _checkR/   t   KeyErrort   ret   subR*   R(   R)   t   joint   ost   patht   isfilet   _loadR    t   TopLevelLookupException(   R   R	   t   ut   dirt   srcfile(    (    s/   /usr/lib/python2.7/dist-packages/mako/lookup.pyR   Č   s    	c         C   s   | | f } | |  j  k r& |  j  | S| d d k r | d k	 rk t j t j |  |  } |  j  | <q d | } |  j  | <n | } |  j  | <| S(   s5   adjust the given uri based on the given relative uri.i    t   /N(   R0   R   R(   R<   t   dirname(   R   R	   R   t   keyt   v(    (    s/   /usr/lib/python2.7/dist-packages/mako/lookup.pyR   ß   s    )c         C   sD   y |  j  | SWn. t k
 r? |  j |  } | |  j  | <| SXd S(   sT   Convert the given filename to a uri relative to 
           this TemplateCollection.N(   R0   R9   t   _relativeize(   R   R   t   value(    (    s/   /usr/lib/python2.7/dist-packages/mako/lookup.pyR   đ   s    c         C   sR   t  j |  } x< |  j D]- } | d t |  !| k r | t |  Sq Wd Sd S(   sm   Return the portion of a filename that is 'relative' 
           to the directories in this lookup.
 
        i    N(   R(   R)   R*   t   lenR   (   R   R   RC   (    (    s/   /usr/lib/python2.7/dist-packages/mako/lookup.pyRI   ű   s
    c      
   C   sÖ   |  j  j   z´ y |  j | SWn t k
 r2 n Xym |  j d  k	 rZ |  j | |  } n d  } t d | d t j |  d |  d | |  j	  |  j | <} | SWn |  j j
 | d     n XWd  |  j  j   Xd  S(   NR	   R   t   lookupt   module_filename(   R4   t   acquireR/   R9   R+   R   R   R(   R)   R.   t   popt   release(   R   R   R	   RM   t   template(    (    s/   /usr/lib/python2.7/dist-packages/mako/lookup.pyR@     s*    c         C   sŞ   | j  d  k r | SyY t j | j   } | j j | t j k  rg |  j j | d   |  j	 | j  |  S| SWn7 t
 k
 rĽ |  j j | d   t j d |   n Xd  S(   Ns   Cant locate template for uri %r(   R   R   R=   t   statt   modulet   _modified_timet   ST_MTIMER/   RO   R@   t   OSErrorR    R   (   R   R	   RQ   t   template_stat(    (    s/   /usr/lib/python2.7/dist-packages/mako/lookup.pyR8   &  s    	c         C   s)   t  | d |  d | |  j |  j | <d S(   s   Place a new :class:`.Template` object into this
        :class:`.TemplateLookup`, based on the given string of
        text.
 
        RL   R	   N(   R   R.   R/   (   R   R	   t   text(    (    s/   /usr/lib/python2.7/dist-packages/mako/lookup.pyt
   put_string8  s
    c         C   s   | |  j  | <d S(   s   Place a new :class:`.Template` object into this
        :class:`.TemplateLookup`, based on the given
        :class:`.Template` object.
 
        N(   R/   (   R   R	   RQ   (    (    s/   /usr/lib/python2.7/dist-packages/mako/lookup.pyt   put_templateD  s    N(    (   R   R   R   R   R   R   R6   R   R   R   RI   R@   R8   RY   RZ   (    (    (    s/   /usr/lib/python2.7/dist-packages/mako/lookup.pyR   R   s:   ;%							(   R=   RR   R(   R:   t   makoR    R   t   mako.templateR   R2   t   dummy_threadingt   objectR   R   (    (    (    s/   /usr/lib/python2.7/dist-packages/mako/lookup.pyt   <module>   s   0B