ó
Ñ7ec           @   s(  d  d l  Z  d  d l Z d  d l m Z d  d l m Z d  d l m Z d  d l m	 Z	 d  d l
 m Z d  d l m Z d d	 l m Z m Z m Z d d
 l m Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d „  Z d „  Z d S(   iÿÿÿÿN(   t   import_module(   t   six(   t   RemovedInDjango20Warning(   t   conditional_escape(   t
   getargspec(   t   is_iterablei   (   t   Nodet   Templatet   token_kwargs(   t   TemplateSyntaxErrort   InvalidTemplateLibraryc           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    sA   /usr/local/lib/python2.7/dist-packages/django/template/library.pyR
      s   t   Libraryc           B   s}   e  Z d  Z d „  Z d	 d	 d „ Z d „  Z d	 d	 d „ Z d „  Z d	 d	 d	 d „ Z	 d	 d	 d	 d „ Z
 d	 d	 d	 d „ Z RS(
   s  
    A class for registering template tags and filters. Compiled filter and
    template tag functions are stored in the filters and tags attributes.
    The filter, simple_tag, and inclusion_tag methods provide a convenient
    way to register callables as tags.
    c         C   s   i  |  _  i  |  _ d  S(   N(   t   filterst   tags(   t   self(    (    sA   /usr/local/lib/python2.7/dist-packages/django/template/library.pyt   __init__   s    	c            s¬   ˆ  d  k r | d  k r ˆ j Sˆ  d  k	 ri | d  k ri t ˆ  ƒ rP ˆ j ˆ  ƒ S‡  ‡ f d †  } | Sn? ˆ  d  k	 r’ | d  k	 r’ | ˆ j ˆ  <| St d ˆ  | f ƒ ‚ d  S(   Nc            s   ˆ j  ˆ  |  ƒ S(   N(   t   tag(   t   func(   t   nameR   (    sA   /usr/local/lib/python2.7/dist-packages/django/template/library.pyt   dec(   s    s.   Unsupported arguments to Library.tag: (%r, %r)(   t   Nonet   tag_functiont   callableR   t
   ValueError(   R   R   t   compile_functionR   (    (   R   R   sA   /usr/local/lib/python2.7/dist-packages/django/template/library.pyR      s    c         C   s    | |  j  t | d | ƒ j <| S(   Nt   _decorated_function(   R   t   getattrR   (   R   R   (    (    sA   /usr/local/lib/python2.7/dist-packages/django/template/library.pyR   5   s    c            s)  ˆ d k r. | d k r. ‡  ‡ f d †  } | Sˆ d k	 r~ | d k r~ t ˆ ƒ rb ˆ j ˆ ˆ   S‡  ‡ ‡ f d †  } | Sn§ ˆ d k	 r| d k	 r| ˆ j ˆ <x\ d	 D]T } | ˆ  k rª ˆ  | } t | | | ƒ t | d ƒ rþ t | j | | ƒ qþ qª qª Wˆ | _ | St d ˆ | f ƒ ‚ d S(
   s™   
        Register a callable as a template filter. Example:

        @register.filter
        def lower(value):
            return value.lower()
        c            s   ˆ j  |  ˆ   S(   N(   t   filter_function(   R   (   t   flagsR   (    sA   /usr/local/lib/python2.7/dist-packages/django/template/library.pyR   C   s    c            s   ˆ j  ˆ |  ˆ   S(   N(   t   filter(   R   (   R   R   R   (    sA   /usr/local/lib/python2.7/dist-packages/django/template/library.pyR   L   s    t   expects_localtimet   is_safet   needs_autoescapeR   s1   Unsupported arguments to Library.filter: (%r, %r)N(   R    R!   R"   (	   R   R   R   R   t   setattrt   hasattrR   t   _filter_nameR   (   R   R   t   filter_funcR   R   t   attrt   value(    (   R   R   R   sA   /usr/local/lib/python2.7/dist-packages/django/template/library.pyR   9   s*    
	c         K   s(   t  | d | ƒ j } |  j | | |  S(   NR   (   R   R   R   (   R   R   R   R   (    (    sA   /usr/local/lib/python2.7/dist-packages/django/template/library.pyR   c   s    c            sK   ‡  ‡ ‡ f d †  } | d k r% | St | ƒ r; | | ƒ St d ƒ ‚ d S(   s§   
        Register a callable as a compiled template tag. Example:

        @register.simple_tag
        def hello(*args, **kwargs):
            return 'world'
        c            sw   t  ˆ ƒ \ ‰ ‰ ‰ ‰  ˆ p0 t ˆ d ˆ ƒ j ‰ t j ˆ ƒ ‡  ‡ ‡ ‡ ‡ ‡ ‡ f d †  ƒ } ˆ j ˆ | ƒ ˆ S(   NR   c      	      sŒ   | j  ƒ  d } d  } t | ƒ d k rO | d d k rO | d } | d  } n  t |  | ˆ ˆ ˆ ˆ  ˆ ˆ ƒ \ } } t ˆ ˆ | | | ƒ S(   Ni   i   iþÿÿÿt   asiÿÿÿÿ(   t   split_contentsR   t   lent
   parse_bitst
   SimpleNode(   t   parsert   tokent   bitst
   target_vart   argst   kwargs(   t   defaultsR   t   function_namet   paramst   takes_contextt   varargst   varkw(    sA   /usr/local/lib/python2.7/dist-packages/django/template/library.pyt   compile_funcs   s    "
(   R   R   R   t	   functoolst   wrapsR   (   R   R:   (   R   R   R7   (   R4   R   R5   R6   R8   R9   sA   /usr/local/lib/python2.7/dist-packages/django/template/library.pyR   o   s
    0s(   Invalid arguments provided to simple_tagN(   R   R   R   (   R   R   R7   R   R   (    (   R   R   R7   sA   /usr/local/lib/python2.7/dist-packages/django/template/library.pyt
   simple_tagg   s    
c         C   s)   t  j d t d d ƒ|  j | | | ƒ S(   Ns8   assignment_tag() is deprecated. Use simple_tag() insteadt
   stackleveli   (   t   warningst   warnR   R=   (   R   R   R7   R   (    (    sA   /usr/local/lib/python2.7/dist-packages/django/template/library.pyt   assignment_tag‹   s
    c            s   ‡  ‡ ‡ ‡ f d †  } | S(   sß   
        Register a callable as an inclusion tag:

        @register.inclusion_tag('results.html')
        def show_results(poll):
            choices = poll.choice_set.all()
            return {'choices': choices}
        c      	      sz   t  ˆ ƒ \ ‰ ‰ ‰ ‰  ˆ p0 t ˆ d ˆ ƒ j ‰ t j ˆ ƒ ‡  ‡ ‡ ‡ ‡ ‡	 ‡ ‡ f d †  ƒ } ˆ j ˆ | ƒ ˆ S(   NR   c      	      sM   | j  ƒ  d } t |  | ˆ ˆ ˆ ˆ  ˆ ˆ ƒ \ } } t ˆ ˆ | | ˆ ƒ S(   Ni   (   R*   R,   t   InclusionNode(   R.   R/   R0   R2   R3   (   R4   t   filenameR   R5   R6   R7   R8   R9   (    sA   /usr/local/lib/python2.7/dist-packages/django/template/library.pyR:       s    (   R   R   R   R;   R<   R   (   R   R:   (   RC   R   R   R7   (   R4   R   R5   R6   R8   R9   sA   /usr/local/lib/python2.7/dist-packages/django/template/library.pyR   œ   s
    3
(    (   R   RC   R   R7   R   R   (    (   RC   R   R   R7   sA   /usr/local/lib/python2.7/dist-packages/django/template/library.pyt   inclusion_tag“   s    	N(   R   R   t   __doc__R   R   R   R   R   R   R=   RA   RD   (    (    (    sA   /usr/local/lib/python2.7/dist-packages/django/template/library.pyR      s   		*	$t   TagHelperNodec           B   s    e  Z d  Z d „  Z d „  Z RS(   s¬   
    Base class for tag helper nodes such as SimpleNode and InclusionNode.
    Manages the positional and keyword arguments to be passed to the decorated
    function.
    c         C   s(   | |  _  | |  _ | |  _ | |  _ d  S(   N(   R   R7   R2   R3   (   R   R   R7   R2   R3   (    (    sA   /usr/local/lib/python2.7/dist-packages/django/template/library.pyR   µ   s    			c            sg   g  |  j  D] } | j ˆ  ƒ ^ q
 } |  j r> ˆ  g | } n  ‡  f d †  |  j j ƒ  Dƒ } | | f S(   Nc            s(   i  |  ] \ } } | j  ˆ  ƒ | “ q S(    (   t   resolve(   t   .0t   kt   v(   t   context(    sA   /usr/local/lib/python2.7/dist-packages/django/template/library.pys
   <dictcomp>¿   s   	 (   R2   RG   R7   R3   t   items(   R   RK   t   vart   resolved_argst   resolved_kwargs(    (   RK   sA   /usr/local/lib/python2.7/dist-packages/django/template/library.pyt   get_resolved_arguments»   s
    %	(   R   R   RE   R   RP   (    (    (    sA   /usr/local/lib/python2.7/dist-packages/django/template/library.pyRF   ¯   s   	R-   c           B   s   e  Z d  „  Z d „  Z RS(   c         C   s,   t  t |  ƒ j | | | | ƒ | |  _ d  S(   N(   t   superR-   R   R1   (   R   R   R7   R2   R3   R1   (    (    sA   /usr/local/lib/python2.7/dist-packages/django/template/library.pyR   Å   s    c         C   sc   |  j  | ƒ \ } } |  j | | Ž  } |  j d  k	 rG | | |  j <d S| j r_ t | ƒ } n  | S(   Nt    (   RP   R   R1   R   t
   autoescapeR   (   R   RK   RN   RO   t   output(    (    sA   /usr/local/lib/python2.7/dist-packages/django/template/library.pyt   renderÉ   s    	(   R   R   R   RU   (    (    (    sA   /usr/local/lib/python2.7/dist-packages/django/template/library.pyR-   Ã   s   	RB   c           B   s   e  Z d  „  Z d „  Z RS(   c         C   s,   t  t |  ƒ j | | | | ƒ | |  _ d  S(   N(   RQ   RB   R   RC   (   R   R   R7   R2   R3   RC   (    (    sA   /usr/local/lib/python2.7/dist-packages/django/template/library.pyR   Ö   s    c         C   s<  |  j  | ƒ \ } } |  j | | Ž  } | j j |  ƒ } | d k rø t |  j t ƒ rc |  j } n… t t |  j d d ƒ t ƒ r |  j j	 } nX t |  j t
 j ƒ rÐ t |  j ƒ rÐ | j	 j j |  j ƒ } n | j	 j j |  j ƒ } | | j |  <n  | j | ƒ } | j d ƒ } | d k	 r/| | d <n  | j | ƒ S(   s°   
        Render the specified template and context. Cache the template object
        in render_context to avoid reparsing and loading when used in a for
        loop.
        t   templatet
   csrf_tokenN(   RP   R   t   render_contextt   getR   t
   isinstanceRC   R   R   RV   R   t   string_typesR   t   enginet   select_templatet   get_templatet   newRU   (   R   RK   RN   RO   t   _dictt   tt   new_contextRW   (    (    sA   /usr/local/lib/python2.7/dist-packages/django/template/library.pyRU   Ú   s"    %(   R   R   R   RU   (    (    (    sA   /usr/local/lib/python2.7/dist-packages/django/template/library.pyRB   Ô   s   	c         C   sÝ  | r6 | d d k r# | d } q6 t  d | ƒ ‚ n  g  } i  }	 t | ƒ }
 x0| D](} t | g |  ƒ } | r
| j ƒ  \ } } | | k r¶ | d k r¶ t  d | | f ƒ ‚ q}| |	 k rÛ t  d | | f ƒ ‚ q}| |	 t | ƒ <| |
 k r}|
 j | ƒ q}qU |	 r#t  d | ƒ ‚ qU | j |  j | ƒ ƒ y |
 j	 d ƒ WqU t
 k
 r|| d k r}t  d | ƒ ‚ q}qU XqU W| d k	 r¡|
 t | ƒ  }
 n  |
 rÓt  d	 | d
 j d „  |
 Dƒ ƒ f ƒ ‚ n  | |	 f S(   s°   
    Parse bits for template tag helpers simple_tag and inclusion_tag, in
    particular by detecting syntax errors and by extracting positional and
    keyword arguments.
    i    RK   i   sW   '%s' is decorated with takes_context=True so it must have a first argument of 'context's.   '%s' received unexpected keyword argument '%s's7   '%s' received multiple values for keyword argument '%s'sH   '%s' received some positional argument(s) after some keyword argument(s)s+   '%s' received too many positional argumentss5   '%s' did not receive value(s) for the argument(s): %ss   , c         s   s   |  ] } d  | Vq d S(   s   '%s'N(    (   RH   t   p(    (    sA   /usr/local/lib/python2.7/dist-packages/django/template/library.pys	   <genexpr>8  s    N(   R	   t   listR   t   popitemR   t   strt   removet   appendt   compile_filtert   popt
   IndexErrorR+   t   join(   R.   R0   R6   R8   R9   R4   R7   R   R2   R3   t   unhandled_paramst   bitt   kwargt   paramR(   (    (    sA   /usr/local/lib/python2.7/dist-packages/django/template/library.pyR,   ø   sV    &c         C   so   y t  |  ƒ } Wn) t k
 r; } t d |  | f ƒ ‚ n Xy | j SWn! t k
 rj t d |  ƒ ‚ n Xd S(   s;   
    Load a Library object from a template tag module.
    sS   Invalid template library specified. ImportError raised when trying to load '%s': %ss4   Module  %s does not have a variable named 'register'N(   R    t   ImportErrorR
   t   registert   AttributeError(   R   t   modulet   e(    (    sA   /usr/local/lib/python2.7/dist-packages/django/template/library.pyt   import_library<  s    (   R;   R?   t	   importlibR    t   django.utilsR   t   django.utils.deprecationR   t   django.utils.htmlR   t   django.utils.inspectR   t   django.utils.itercompatR   t   baseR   R   R   t
   exceptionsR	   t	   ExceptionR
   t   objectR   RF   R-   RB   R,   Rv   (    (    (    sA   /usr/local/lib/python2.7/dist-packages/django/template/library.pyt   <module>   s    œ$	D