
iNc           @   sC   d  Z  d d l Z d d l Z d d l Z d d  Z d   Z d S(   s  adds autohandler functionality to Mako templates.

requires that the TemplateLookup class is used with templates.

usage:

<%!
    from mako.ext.autohandler import autohandler
%>
<%inherit file="${autohandler(template, context)}"/>


or with custom autohandler filename:

<%!
    from mako.ext.autohandler import autohandler
%>
<%inherit file="${autohandler(template, context, name='somefilename')}"/>

iNt   autohandlerc         C   s,  | j  } |  j j } | j sM y | j t | | f SWqM t k
 rI qM Xn  t j d t	 j
 |   | g } x t |  r d d j |  } | | k r t | |  r | j s | j j t | | f |  S| Sn  t |  d k r Pn  | g | d )qr W| j s$| j j t | | f d   Sd  Sd  S(   Ns   ([^/]+)t   /i   i(   t   lookupt   modulet   _template_urit   filesystem_checkst
   _uri_cacheR    t   KeyErrort   ret   findallt	   posixpatht   dirnamet   lent   joint   _file_existst
   setdefaultt   None(   t   templatet   contextt   nameR   R   t   tokenst   path(    (    s8   /usr/lib/python2.7/dist-packages/mako/ext/autohandler.pyR       s,    		"				c         C   sO   t  j d d |  } x3 |  j D]$ } t j j | d |  r t Sq Wt Sd  S(   Ns   ^/t    R   (   R   t   subt   directoriest   osR   t   existst   Truet   False(   R   R   t   psubt   d(    (    s8   /usr/lib/python2.7/dist-packages/mako/ext/autohandler.pyR   :   s
    (   t   __doc__R
   R   R   R    R   (    (    (    s8   /usr/lib/python2.7/dist-packages/mako/ext/autohandler.pyt   <module>   s   $