
'Gc           @   s@  d  Z  d Z d Z d d l Td 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
 d d l Z d d l Z d d l Z d d l Z d Z d Z d Z d	 Z d Z d Z d
 f  d     YZ d f  d     YZ d f  d     YZ d f  d     YZ d e f d     YZ d e f d     YZ d S(   s>   A templating engine for separation of code and HTML.

    The documentation of this templating engine is separated to two parts:
    
        1. Description of the templating language.
           
        2. Documentation of classes and API of this module that provides
           a Python implementation of the templating language.
    
    All the documentation can be found in 'doc' directory of the
    distribution tarball or at the homepage of the engine.
    Latest versions of this module are also available at that website.

    You can use and redistribute this module under conditions of the
    GNU General Public License that can be found either at
    [ http://www.gnu.org/ ] or in file "LICENSE" contained in the
    distribution tarball of this module.

    Copyright (c) 2001 Tomas Styblo, tripie@cpan.org

    @name           htmltmpl
    @version        1.22
    @author-name    Tomas Styblo
    @author-email   tripie@cpan.org
    @website        http://htmltmpl.sourceforge.net/
    @license-name   GNU GPL
    @license-url    http://www.gnu.org/licenses/gpl.html
gQ?s   Tomas Styblo (tripie@cpan.org)i(   t   *Nt   inci   i   i   t   TemplateManagerc           B   sh   e  Z d  Z d d d d d d d  Z d   Z d   Z d   Z d   Z d	   Z d
   Z	 d   Z
 RS(   s{    Class that manages compilation and precompilation of templates.
    
         You should use this class whenever you work with templates
         that are stored in a file. The class can create a compiled
         template and transparently manage its precompilation. It also
         keeps the precompiled templates up-to-date by modification times
         comparisons. 
    i   i   i    c         C   sG   | |  _  | |  _ | |  _ | |  _ | |  _ | |  _ |  j d  d S(   s	   Constructor.
        
            @header
            __init__(include=1, max_include=5, precompile=1, comments=1,
                     gettext=0, debug=0)
            
            @param include Enable or disable included templates.
            This optional parameter can be used to enable or disable
            <em>TMPL_INCLUDE</em> inclusion of templates. Disabling of
            inclusion can improve performance a bit. The inclusion is
            enabled by default.
      
            @param max_include Maximum depth of nested inclusions.
            This optional parameter can be used to specify maximum depth of
            nested <em>TMPL_INCLUDE</em> inclusions. It defaults to 5.
            This setting prevents infinite recursive inclusions.
            
            @param precompile Enable or disable precompilation of templates.
            This optional parameter can be used to enable or disable
            creation and usage of precompiled templates.
      
            A precompiled template is saved to the same directory in
            which the main template file is located. You need write
            permissions to that directory.

            Precompilation provides a significant performance boost because
            it's not necessary to parse the templates over and over again.
            The boost is especially noticeable when templates that include
            other templates are used.
            
            Comparison of modification times of the main template and all
            included templates is used to ensure that the precompiled
            templates are up-to-date. Templates are also recompiled if the
            htmltmpl module is updated.

            The <em>TemplateError</em>exception is raised when the precompiled
            template cannot be saved. Precompilation is enabled by default.
            
            @param comments Enable or disable template comments.
            This optional parameter can be used to enable or disable
            template comments.
            Disabling of the comments can improve performance a bit.
            Comments are enabled by default.
            
            @param gettext Enable or disable gettext support.

            @param debug Enable or disable debugging messages.
            This optional parameter is a flag that can be used to enable
            or disable debugging messages which are printed to the standard
            error output. The debugging messages are disabled by default.
        s	   INIT DONEN(   t   _includet   _max_includet   _precompilet	   _commentst   _gettextt   _debugt   DEB(   t   selft   includet   max_includet
   precompilet   commentst   gettextt   debug(    (    sG   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/htmltmpl.pyt   __init__K   s    7						c         C   s2  d } |  j r|  j |  r y |  j |  } Wn@ t k
 rs } t j d | IJ|  j |  } |  j |  qX| j	 |  j
  |  j |  j |  j |  j f } | j |  r |  j d  | } q|  j d  |  j |  } q.|  j d  |  j |  } |  j |  n |  j d  |  j |  } | S(   s   Preprocess, parse, tokenize and compile the template.
            
            If precompilation is enabled then this method tries to load
            a precompiled form of the template from the same directory
            in which the template source file is located. If it succeeds,
            then it compares modification times stored in the precompiled
            form to modification times of source files of the template,
            including source files of all templates included via the
            <em>TMPL_INCLUDE</em> statements. If any of the modification times
            differs, then the template is recompiled and the precompiled
            form updated.
            
            If precompilation is disabled, then this method parses and
            compiles the template.
            
            @header prepare(file)
            
            @return Compiled template.
            The methods returns an instance of the <em>Template</em> class
            which is a compiled form of the template. This instance can be
            used as input for the <em>TemplateProcessor</em>.
            
            @param file Path to the template file to prepare.
            The method looks for the template file in current directory
            if the parameter is a relative path. All included templates must
            be placed in subdirectory <strong>'inc'</strong> of the 
            directory in which the main template file is located.
        s/   Htmltmpl: bad precompiled template '%s' removeds   PRECOMPILED: UPTODATEs   PRECOMPILED: NOT UPTODATEs   PRECOMPILED: NOT PRECOMPILEDs   PRECOMPILATION DISABLEDN(   t   NoneR   t   is_precompiledt   load_precompiledt   PrecompiledErrort   syst   stderrt   compilet   save_precompiledR   R   R   R   R   R   t   is_uptodateR	   t   update(   R
   t   filet   compiledt   precompiledt   templatet   compile_params(    (    sG   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/htmltmpl.pyt   prepare   s0    	
	c         C   s?   |  j  d  |  j | j    } |  j r; |  j |  n  | S(   s   Update (recompile) a compiled template.
        
            This method recompiles a template compiled from a file.
            If precompilation is enabled then the precompiled form saved on
            disk is also updated.
            
            @header update(template)
            
            @return Recompiled template.
            It's ensured that the returned template is up-to-date.
            
            @param template A compiled template.
            This parameter should be an instance of the <em>Template</em>
            class, created either by the <em>TemplateManager</em> or by the
            <em>TemplateCompiler</em>. The instance must represent a template
            compiled from a file on disk.
        t   UPDATE(   R	   R   R   R   R   (   R
   R   t   updated(    (    sG   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/htmltmpl.pyR      s
    	c         C   s   |  j  r t j | IJn  d S(   sY    Print debugging message to stderr if debugging is enabled. 
            @hidden
        N(   R   R   R   (   R
   t   str(    (    sG   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/htmltmpl.pyR	      s    	 c         C   s.   t  |  j |  j |  j |  j |  j  j |  S(   s3    Compile the template.
            @hidden
        (   t   TemplateCompilerR   R   R   R   R   R   (   R
   R   (    (    sG   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/htmltmpl.pyR      s    c         C   s(   | d } t  j j |  r  d Sd Sd S(   s    Return true if the template is already precompiled on the disk.
            This method doesn't check whether the compiled template is
            uptodate.
            @hidden
        t   ci   i    N(   t   ost   patht   isfile(   R
   R   t   filename(    (    sG   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/htmltmpl.pyR      s    
c         C   s  | d } |  j  d  z d } d } y5 t | d  } t j | t j  t j |  } Wn` t k
 r \ } } t	 d | | | f  n6 t j
 k
 r d } t |  n d }   n X| SWd | r t j |  | j   n  | rt j j |  rt j |  n  Xd S(   s    Load precompiled template from disk.

            Remove the precompiled template file and recompile it
            if the file contains corrupted or unpicklable data.
            
            @hidden
        R&   s   LOADING PRECOMPILEDi    t   rbs3   IO error in load precompiled template '%s': (%d) %si   N(   R	   R   t   opent   portalockert   lockt   LOCK_SHt   cPicklet   loadt   IOErrort   TemplateErrort   UnpicklingErrorR   t   unlockt   closeR'   R(   R)   t   remove(   R
   R   R*   t
   remove_badR   t   errnot   errstr(    (    sG   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/htmltmpl.pyR      s0    
c         C   s  | j    d } t j j t j j |   } t j | t j  sS t d |  n  z d } d	 } yd t	 | d  } t
 j | t
 j  d } d } |  j r t j | | |  n t j | | |  Wnr t k
 r \ } }	 d } t d | | |	 f  nK t j k
 r+}
 d } t d | |
 f  n d }   n X|  j d  Wd	 | rlt
 j |  | j   n  | rt j j |  rt j |  n  Xd	 S(
   s   Save compiled template to disk in precompiled form.
            
            Associated metadata is also saved. It includes: filename of the
            main template file, modification time of the main template file,
            modification times of all included templates and version of the
            htmltmpl module which compiled the template.
            
            The method removes a file which is saved only partially because
            of some error.
            
            @hidden
        R&   sC   Cannot save precompiled templates to '%s': write permission denied.i    t   wbi   s8   IO error while saving precompiled template '%s': (%d) %ss9   Pickling error while saving precompiled template '%s': %ss   SAVING PRECOMPILEDN(   R   R'   R(   t   dirnamet   abspatht   accesst   W_OKR3   R   R,   R-   R.   t   LOCK_EXR   R0   t   dumpR2   t   PicklingErrorR	   R5   R6   R)   R7   (   R
   R   R*   t   template_dirR8   R   t   BINARYt   READABLER9   R:   t   error(    (    sG   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/htmltmpl.pyR      sB    
	(   t   __name__t
   __module__t   __doc__R   R!   R   R	   R   R   R   R   (    (    (    sG   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/htmltmpl.pyR   A   s   ?	:					%t   TemplateProcessorc           B   sw   e  Z d  Z d d d d d  Z d   Z d d  Z d d  Z d   Z d d  Z	 d	   Z
 d
 d  Z d   Z RS(   s    Fill the template with data and process it.

        This class provides actual processing of a compiled template.
        Use it to set template variables and loops and then obtain
        result of the processing.
    i   i    c         C   sC   | |  _  | |  _ | |  _ | |  _ i  |  _ d |  _ d |  _ d S(   s   Constructor.

            @header __init__(html_escape=1, magic_vars=1, global_vars=0,
                             debug=0)

            @param html_escape Enable or disable HTML escaping of variables.
            This optional parameter is a flag that can be used to enable or
            disable automatic HTML escaping of variables.
            All variables are by default automatically HTML escaped. 
            The escaping process substitutes HTML brackets, ampersands and
            double quotes with appropriate HTML entities.
            
            @param magic_vars Enable or disable loop magic variables.
            This parameter can be used to enable or disable
            "magic" context variables, that are automatically defined inside
            loops. Magic variables are enabled by default.

            Refer to the language specification for description of these
            magic variables.
      
            @param global_vars Globally activate global lookup of variables.
            This optional parameter is a flag that can be used to specify
            whether variables which cannot be found in the current scope
            should be automatically looked up in enclosing scopes.

            Automatic global lookup is disabled by default. Global lookup
            can be overriden on a per-variable basis by the
            <strong>GLOBAL</strong> parameter of a <strong>TMPL_VAR</strong>
            statement.

            @param debug Enable or disable debugging messages.
        i   i    N(   t   _html_escapet   _magic_varst   _global_varsR   t   _varst   _current_partt   _current_pos(   R
   t   html_escapet
   magic_varst   global_varsR   (    (    sG   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/htmltmpl.pyR   d  s    !						c         C   s   |  j  |  r. | j   sr t d |  qr nD t |  t k re | | j   k rr t d |  qr n t d |  | |  j | <|  j d t |   d S(   s   Associate a value with top-level template variable or loop.

            A template identifier can represent either an ordinary variable
            (string) or a loop.

            To assign a value to a string identifier pass a scalar
            as the 'value' parameter. This scalar will be automatically
            converted to string.

            To assign a value to a loop identifier pass a list of mappings as
            the 'value' parameter. The engine iterates over this list and
            assigns values from the mappings to variables in a template loop
            block if a key in the mapping corresponds to a name of a variable
            in the loop block. The number of mappings contained in this list
            is equal to number of times the loop block is repeated in the
            output.
      
            @header set(var, value)
            @return No return value.

            @param var Name of template variable or loop.
            @param value The value to associate.
            
        s   Invalid variable name '%s'.s   Invalid loop name '%s'.sB   Value of toplevel variable '%s' must be either a scalar or a list.s   VALUE SET: N(	   t   is_ordinary_vart   islowerR3   t   typet   ListTypet
   capitalizeRN   R	   R$   (   R
   t   vart   value(    (    sG   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/htmltmpl.pyt   set  s    c         C   s9   d |  _  d |  _ | s( |  j j   n  |  j d  d S(   s   Reset the template data.

            This method resets the data contained in the template processor
            instance. The template processor instance can be used to process
            any number of templates, but this method must be called after
            a template is processed to reuse the instance,

            @header reset(keep_data=0)
            @return No return value.

            @param keep_data Do not reset the template data.
            Use this flag if you do not want the template data to be erased.
            This way you can reuse the data contained in the instance of
            the <em>TemplateProcessor</em>.
        i   i    t   RESETN(   RO   RP   RN   t   clearR	   (   R
   t	   keep_data(    (    sG   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/htmltmpl.pyt   reset  s
    		c      
   C   s  |  j  d  |  j r/ t j |  j t j  n  | d2 k rb | d k sV | |  j k  rb t d  n  d } g  } d } d } g  } g  } g  }	 g  }
 | j	   } t
 |  } d } |  j } x3| | k r Pn  | r d } | t 7} q n  | | } | j d  s| j d  r| d k r| | t } | s<t d	  n  | | t } | | t } d } | | k rt |  j | | | |
 |   } | |  j | |  7} |  j  d
 t |   qq| d k r| | t } | st d  n  d } |  j | | | |
  } | sd } n  |
 j |  |	 j |  | j d  | j |  | d k r~| j |  |  j  d t |   q| j |  |  j  d | | f  q| d k rN| | t } | st d  n  | | t } d } |  j | | | |
 |  r'| j |  |  j  d t |   q| j |  |  j  d t |   q| d k r| | t } | szt d  n  | | t } d } |  j | | | |
 |  r| j |  |  j  d t |   q| j |  |  j  d t |   q| d k rd } | st d  n  |
 d d k r>| d c d 7<n  | d |
 d k r| j   | j   |	 j   |
 j   | j   |  j  d  q|	 d } |  j  d  q| d k rd } | st d  n  | j   |  j  d  q| d k r*d } | st d   n  | j   |  j  d!  q| d" k rd } | sNt d#  n  | d | k rx| | d <|  j  d$  q| d | k r| | d <|  j  d%  qt d&  q| d' k r%| r | |  j k r |  j  d(  |  j d 7_ | d t |  _ Pqd } |  j  d)  |  j d 7_ q| d* k rcd } | | t } | d+ | 7} |  j  d,  q| d- k rd } | | k r| | t } | t j |  7} |  j  d. |  qqt d/ |  n | | k r| | 7} n  | d 7} q | rt d0  n  | rt d1  n  | S(3   sD   Process a compiled template. Return the result as string.

            This method actually processes a template and returns
            the result.

            @header process(template, part=None)
            @return Result of the processing as string.

            @param template A compiled template.
            Value of this parameter must be an instance of the
            <em>Template</em> class created either by the
            <em>TemplateManager</em> or by the <em>TemplateCompiler</em>.

            @param part The part of a multipart template to process.
            This parameter can be used only together with a multipart
            template. It specifies the number of the part to process.
            It must be greater than zero, because the parts are numbered
            from one.

            The parts must be processed in the right order. You
            cannot process a part which precedes an already processed part.

            If this parameter is not specified, then the whole template
            is processed, or all remaining parts are processed.
        s
   APP INPUT:i    s   process() - invalid part numberi   t    s   <TMPL_s   </TMPL_s	   <TMPL_VARs   No identifier in <TMPL_VAR>.s   VAR: s
   <TMPL_LOOPs   No identifier in <TMPL_LOOP>.s   LOOP: DISABLE: s   LOOP: FIRST PASS: %s TOTAL: %ds   <TMPL_IFs   No identifier in <TMPL_IF>.s   IF: ENABLE: s   IF: DISABLE: s   <TMPL_UNLESSs   No identifier in <TMPL_UNLESS>.s   UNLESS: DISABLE: s   UNLESS: ENABLE: s   </TMPL_LOOPs   Unmatched </TMPL_LOOP>.is	   LOOP: ENDs   LOOP: NEXT PASSs	   </TMPL_IFs   Unmatched </TMPL_IF>.s   IF: ENDs   </TMPL_UNLESSs   Unmatched </TMPL_UNLESS>.s   UNLESS: ENDs
   <TMPL_ELSEs   Unmatched <TMPL_ELSE>.s   ELSE: ENABLEs   ELSE: DISABLEs   BUG: ELSE: INVALID FLAGs   <TMPL_BOUNDARYs   BOUNDARY ONs   BOUNDARY OFFs   <TMPL_INCLUDEs  
                        <br />
                        <p>
                        <strong>HTMLTMPL WARNING:</strong><br />
                        Cannot include template: <strong>%s</strong>
                        </p>
                        <br />
                    s   CANNOT INCLUDE WARNINGs   <TMPL_GETTEXTs	   GETTEXT: s   Invalid statement %s>.s   Missing </TMPL_LOOP>.s$   Missing </TMPL_IF> or </TMPL_UNLESS>N(   R	   R   t   pprintRN   R   R   R   RO   R3   t   tokenst   lenRP   t   PARAMS_NUMBERt
   startswitht
   PARAM_NAMEt   PARAM_ESCAPEt   PARAM_GLOBALR$   t
   find_valuet   escapet   appendt   popt   PARAM_GETTEXT_STRINGR   (   R
   R   t   partt   skip_paramst   output_controlt   ENABLE_OUTPUTt   DISABLE_OUTPUTt	   loop_namet	   loop_passt
   loop_startt
   loop_totalRb   t
   len_tokenst   outt   it   tokenRY   Rj   t   globalpRZ   t	   passtotalR*   t   text(    (    sG   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/htmltmpl.pyt   process  s,   	 '	 

	 		 









  c         C   s   |  j  r t j | IJn  d S(   sX    Print debugging message to stderr if debugging is enabled.
            @hidden
        N(   R   R   R   (   R
   R$   (    (    sG   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/htmltmpl.pyR	     s    	 c   	      C   s  |  j  r9 | j d  r9 | r9 |  j | | d | d  S|  j } g  } x t t |   D] } |  j rv | d k s | d k r | j |  r |  j | |  r | j	 | |  n  | j | |  r | | | r | | | | | } q[ d Sq[ W| j |  r8t
 | |  t k r-t | |  S| | SnI | ri|  j rS| d k s_| d k ri| j   S| d j   r}d Sd Sd S(   s   Search the self._vars data structure to find variable var
            located in currently processed pass of a loop which
            is currently being processed. If the variable is an ordinary
            variable, then return it.
            
            If the variable is an identificator of a loop, then 
            return the total number of times this loop will
            be executed.
            
            Return an empty string, if the variable is not
            found at all.

            @hidden
        t   __it   0t   1R`   i    N(   RL   Re   t	   magic_varRN   t   rangeRc   RM   t   has_keyRT   Rk   RV   RW   Rl   t   isupper(	   R
   RY   Rs   Rt   Rv   t   global_overridet   scopet   globalsRy   (    (    sG   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/htmltmpl.pyRi     s.    	!
c         C   s  |  j  d | | | f  | d k r= | d k r6 d Sd Sna| d k rd | | d k r] d Sd Sn:| d k r | d k r | | d k r d Sd Sn| d k r | d S| d k r | S| d	 k r | d d
 d k r d Sd Sn | j d  r| d k r| | d k ry t | d  } Wn t k
 rAt d  qX| sTt d  q| d | d k r|  j  d t |   d Sd Sqd Sn t d |  d S(   s    Resolve and return value of a magic variable.
            Raise an exception if the magic variable is not recognized.

            @hidden
        s    MAGIC: '%s', PASS: %d, TOTAL: %dt	   __FIRST__i    i   t   __LAST__t	   __INNER__t   __PASS__t   __PASSTOTAL__t   __ODD__i   t	   __EVERY__i	   s/   Magic variable __EVERY__x: Invalid pass number.s6   Magic variable __EVERY__x: Pass number cannot be zero.s   MAGIC: EVERY: s   Invalid magic variable '%s'.N(   R	   Re   t   intt
   ValueErrorR3   R$   (   R
   RY   Rt   Rv   t   every(    (    sG   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/htmltmpl.pyR     sH    	R`   c         C   s|   d } |  j  r3 | d k r3 | d k r3 | d k sK | d k sK | d k r[ t j | |  S| d k rt t j |  S| Sd S(   sY    Escape a string either by HTML escaping or by URL escaping.
            @hidden
        i   t   NONER   t   URLt   HTMLR   N(   RK   t   cgiRj   t   urllibt
   quote_plus(   R
   R$   t   overridet   ESCAPE_QUOTES(    (    sG   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/htmltmpl.pyRj   J  s    !$c         C   sT   t  |  t k sH t  |  t k sH t  |  t k sH t  |  t k rL d Sd Sd S(   sW    Return true if var is a scalar. (not a reference to loop)
            @hidden
        i   i    N(   RV   t
   StringTypet   IntTypet   LongTypet	   FloatType(   R
   RY   (    (    sG   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/htmltmpl.pyRT   W  s    $$N(   RG   RH   RI   R   R[   R_   R   R~   R	   Ri   R   Rj   RT   (    (    (    sG   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/htmltmpl.pyRJ   \  s   0	)	<	=R%   c           B   s   e  Z d  Z d d d d d d  Z d   Z d   Z d   Z d   Z d	   Z d
   Z	 d   Z
 d   Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   s   Preprocess, parse, tokenize and compile the template.

        This class parses the template and produces a 'compiled' form
        of it. This compiled form is an instance of the <em>Template</em>
        class. The compiled form is used as input for the TemplateProcessor
        which uses it to actually process the template.

        This class should be used direcly only when you need to compile
        a template from a string. If your template is in a file, then you
        should use the <em>TemplateManager</em> class which provides
        a higher level interface to this class and also can save the
        compiled template to disk in a precompiled form.
    i   i   i    c         C   sC   | |  _  | |  _ | |  _ | |  _ | |  _ g  |  _ d |  _ d S(   s   Constructor.

        @header __init__(include=1, max_include=5, comments=1, gettext=0,
                         debug=0)

        @param include Enable or disable included templates.
        @param max_include Maximum depth of nested inclusions.
        @param comments Enable or disable template comments.
        @param gettext Enable or disable gettext support.
        @param debug Enable or disable debugging messages.
        i    N(   R   R   R   R   R   t   _include_filest   _include_level(   R
   R   R   R   R   R   (    (    sG   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/htmltmpl.pyR   u  s    						c         C   s   |  j  d |  t j j t j j |  t  |  _ |  j |  j |   } |  j	 |  j
 |  j |  j f } t t | |  j | | |  j  S(   s   Compile template from a file.

            @header compile(file)
            @return Compiled template.
            The return value is an instance of the <em>Template</em>
            class.

            @param file Filename of the template.
            See the <em>prepare()</em> method of the <em>TemplateManager</em>
            class for exaplanation of this parameter.
        s   COMPILING FROM FILE: (   R	   R'   R(   t   joinR<   t   INCLUDE_DIRt   _include_patht   parset   readR   R   R   R   t   Templatet   __version__R   R   (   R
   R   Rb   R    (    (    sG   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/htmltmpl.pyR     s    $c         C   s_   |  j  d  d |  _ |  j |  } |  j |  j |  j |  j f } t t d d | | |  j	  S(   s   Compile template from a string.

            This method compiles a template from a string. The
            template cannot include any templates.
            <strong>TMPL_INCLUDE</strong> statements are turned into warnings.

            @header compile_string(data)
            @return Compiled template.
            The return value is an instance of the <em>Template</em>
            class.

            @param data String containing the template data.        
        s   COMPILING FROM STRINGi    N(
   R	   R   R   R   R   R   R   R   R   R   (   R
   t   dataRb   R    (    (    sG   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/htmltmpl.pyt   compile_string  s    	c         C   s   |  j  r t j | IJn  d S(   sX    Print debugging message to stderr if debugging is enabled.
            @hidden
        N(   R   R   R   (   R
   R$   (    (    sG   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/htmltmpl.pyR	     s    	 c         C   s   |  j  d |  z_ d } y t | d  } | j   } Wn/ t k
 rj \ } } t d | | | f  n X| SWd | r | j   n  Xd S(   sq    Read content of file and return it. Raise an error if a problem
            occurs.
            @hidden
        s	   READING: t   rs-   IO error while reading template '%s': (%d) %sN(   R	   R   R,   R   R2   R3   R6   (   R
   R*   t   fR   R9   R:   (    (    sG   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/htmltmpl.pyR     s     c         C   sa   |  j  r( |  j d  |  j |  } n  |  j |  } |  j r] |  j d  |  j |  n  | S(   s    Parse the template. This method is recursively called from
            within the include_templates() method.

            @return List of processing tokens.
            @hidden
        s   PREPROCESS: COMMENTSs   PREPROCESS: INCLUDES(   R   R	   t   remove_commentst   tokenizeR   t   include_templates(   R
   t   template_dataRb   (    (    sG   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/htmltmpl.pyR     s    		c         C   s   d } t  j | d |  S(   sE    Remove comments from the template data.
            @hidden
        s   ### .*R`   (   t   ret   sub(   R
   R   t   pattern(    (    sG   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/htmltmpl.pyR     s    c   
      C   sr  d } d } d } x8| t  |  k r+ Pn  | rG d } | t 7} q n  | | } | d k r@| | t } | s} t d  n  |  j d 7_ |  j |  j k r d } |  j d |  q@d } t j j	 |  j
 |  } |  j j |  |  j |  } |  j |  }	 |	 | | | t d +| t  |	  } |  j d |  q n  | d 7} q |  j d k rn|  j d 8_ n  | S(   s    Process TMPL_INCLUDE statements. Use the include_level counter
            to prevent infinite recursion. Record paths to all included
            templates to self._include_files.
            @hidden
        i    R`   s   <TMPL_INCLUDEs   No filename in <TMPL_INCLUDE>.i   s   INCLUDE: LIMIT REACHED: s
   INCLUDED: (   Rc   Rd   Rf   R3   R   R   R	   R'   R(   R   R   R   Rk   R   R   (
   R
   Rb   Ry   Rx   Ro   Rz   R*   t   include_filet   include_datat   include_tokens(    (    sG   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/htmltmpl.pyR     s@     

 c         C   sT  |  j  d  d t j } t j | t j t j B } | j |  } g  } x| D] } | j d  s | j d  s | j d  s | j d  r|  j	 |  } t j d |  } | j
 |  j |   | j
 |  j |   | j
 |  j d |   | j
 |  j d	 |   qR |  j r?|  j  d
  |  j | |  qR | j
 |  qR W| S(   s   Split the template into tokens separated by template statements.
            The statements itself and associated parameters are also
            separately  included in the resulting list of tokens.
            Return list of the tokens.

            @hidden
        s   TOKENIZING TEMPLATEs  
            (?:^[ \t]+)?               # eat spaces, tabs (opt.)
            (<
             (?:!--[ ])?               # comment start + space (opt.)
             /?TMPL_[A-Z]+             # closing slash / (opt.) + statement
             [ a-zA-Z0-9""/.=:_\\-]*   # this spans also comments ending (--)
             >)
            [%s]?                      # eat trailing newline (opt.)
        s   <TMPL_s   </TMPL_s
   <!-- TMPL_s   <!-- /TMPL_s   \s+t   ESCAPEt   GLOBALs   PARSING GETTEXT STRINGS(   R	   R'   t   linesepR   R   t   VERBOSEt	   MULTILINEt   splitRe   t   strip_bracketsRk   t   find_directivet	   find_namet
   find_paramR   t   gettext_tokens(   R
   R   R   t   rcR   Rb   t	   statementt   params(    (    sG   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/htmltmpl.pyR   "  s*    	c         C   s  d } d } d } d } x| t  |  k r1 Pn  | | d k r d } | | d d k ru | d 7} | d 7} q q| | d d k s | | d d k r d } q| d 7} n;| | d k rE| | d d k rE| r| r d } | d 7} qB| d 7} q| rd } | d 7} q| j |  d } d } | d 7} q n | | d k r| | d d k r| r| rd } | d 7} q|  j | |  d } d } | d 7} q q| rd } | d 7} q| d 7} n d } | | | 7} | d 7} q | r| j |  n  d S(	   sq    Find gettext strings and return appropriate array of
            processing tokens.
            @hidden
        i    R`   s   \i   i   t   [t   ]N(   Rc   Rk   t   add_gettext_token(   R
   Rb   R$   t   escapedt   gt_modeRy   t   buf(    (    sG   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/htmltmpl.pyR   N  sb     

(	$
$
c         C   sI   |  j  d |  | j d  | j |  | j d  | j d  d S(   s\    Append a gettext token and gettext string to the tokens array.
            @hidden
        s   GETTEXT PARSER: TOKEN: s   <TMPL_GETTEXTN(   R	   Rk   R   (   R
   Rb   R$   (    (    sG   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/htmltmpl.pyR     s
    c         C   s8   | j  d  s | j  d  r) | d d !S| d d !Sd S(   s    Strip HTML brackets (with optional HTML comments) from the
            beggining and from the end of a statement.
            @hidden
        s
   <!-- TMPL_s   <!-- /TMPL_i   ii   iN(   Re   (   R
   R   (    (    sG   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/htmltmpl.pyR     s    c         C   s*   | d } | d =|  j  d |  d | S(   sU    Extract processing directive (TMPL_*) from a statement.
            @hidden
        i    s   TOKENIZER: DIRECTIVE: t   <(   R	   (   R
   R   t	   directive(    (    sG   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/htmltmpl.pyR     s    
c         C   sc   t  |  d k r6 d | d k r6 | d } | d =n |  j d |  } |  j d t |   | S(   s    Extract identifier from a statement. The identifier can be
            specified both implicitely or explicitely as a 'NAME' parameter.
            @hidden
        i    t   =t   NAMEs   TOKENIZER: NAME: (   Rc   R   R	   R$   (   R
   R   t   name(    (    sG   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/htmltmpl.pyR     s    "

c         C   s   x | D] } | j  d  \ } } | s0 | r< t d  n  | | k r | d d k rh | d d !} n | } |  j d | | f  | Sq W|  j d |  d	 Sd	 S(
   sJ    Extract value of parameter from a statement.
            @hidden
        R   s   Syntax error in template.i    t   "i   is   TOKENIZER: PARAM: '%s' => '%s's%   TOKENIZER: PARAM: '%s' => NOT DEFINEDN(   R   R3   R	   R   (   R
   t   paramR   t   pairR   RZ   t	   ret_value(    (    sG   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/htmltmpl.pyR     s    (   RG   RH   RI   R   R   R   R	   R   R   R   R   R   R   R   R   R   R   R   (    (    (    sG   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/htmltmpl.pyR%   f  s"   							2	,	@	
				R   c           B   s\   e  Z d  Z d d  Z d
 d  Z d   Z d   Z d   Z d   Z	 d   Z
 d	   Z RS(   s%   This class represents a compiled template.

        This class provides storage and methods for the compiled template
        and associated metadata. It's serialized by pickle if we need to
        save the compiled template to disk in a precompiled form.

        You should never instantiate this class directly. Always use the
        <em>TemplateManager</em> or <em>TemplateCompiler</em> classes to
        create the instances of this class.

        The only method which you can directly use is the <em>is_uptodate</em>
        method.
    i    c         C   s   | |  _  | |  _ | |  _ | |  _ | |  _ d |  _ i  |  _ | sV |  j d  d St	 j
 j |  r t	 j
 j |  |  _ n t d |  xI | D]A } t	 j
 j |  r t	 j
 j |  |  j | <q t d |  q W|  j d  d S(   s*    Constructor.
            @hidden
        s#   TEMPLATE WAS COMPILED FROM A STRINGNs#   Template: file does not exist: '%s's   NEW TEMPLATE CREATED(   t   _versiont   _filet   _tokenst   _compile_paramsR   R   t   _mtimet   _include_mtimesR	   R'   R(   R)   t   getmtimeR3   (   R
   t   versionR   t   include_filesRb   R    R   t   inc_file(    (    sG   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/htmltmpl.pyR     s&    							c         C   s&  |  j  s |  j d  d S|  j t k r: |  j d  d S| d k rf | |  j k rf |  j d  d St j j |  j   o |  j	 t j j
 |  j   k s |  j d |  j   d Sxn |  j j   D]L } t j j |  o |  j | t j j
 |  k s |  j d |  d Sq W|  j d  d Sd S(	   s   Check whether the compiled template is uptodate.

            Return true if this compiled template is uptodate.
            Return false, if the template source file was changed on the
            disk since it was compiled.
            Works by comparison of modification times.
            Also takes modification times of all included templates
            into account.

            @header is_uptodate(compile_params=None)
            @return True if the template is uptodate, false otherwise.

            @param compile_params Only for internal use.
            Do not use this optional parameter. It's intended only for
            internal use by the <em>TemplateManager</em>.
        s   TEMPLATE COMPILED FROM A STRINGi    s   TEMPLATE: VERSION NOT UPTODATEs&   TEMPLATE: DIFFERENT COMPILATION PARAMSs   TEMPLATE: NOT UPTODATE: s   TEMPLATE: UPTODATEi   N(   R   R	   R   R   R   R   R'   R(   R)   R   R   R   t   keys(   R
   R    R   (    (    sG   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/htmltmpl.pyR     s*    	
c         C   s   |  j  S(   s:    Get tokens of this template.
            @hidden
        (   R   (   R
   (    (    sG   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/htmltmpl.pyRb   7  s    c         C   s   |  j  S(   sM    Get filename of the main file of this template.
            @hidden
        (   R   (   R
   (    (    sG   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/htmltmpl.pyR   =  s    c         C   s   | |  _  d S(   s2    Get debugging state.
            @hidden
        N(   R   (   R
   R   (    (    sG   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/htmltmpl.pyR   C  s    c         C   s   t  j  |  j  } | d =| S(   s    Used by pickle when the class is serialized.
            Remove the 'debug' attribute before serialization.
            @hidden
        R   (   t   copyt   __dict__(   R
   t   dict(    (    sG   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/htmltmpl.pyt   __getstate__M  s    c         C   s   d | d <| |  _  d S(   ss    Used by pickle when the class is unserialized.
            Add the 'debug' attribute.
            @hidden
        i    R   N(   R   (   R
   R   (    (    sG   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/htmltmpl.pyt   __setstate__V  s    
c         C   s   |  j  r t j | IJn  d S(   s@    Print debugging message to stderr.
            @hidden
        N(   R   R   R   (   R
   R$   (    (    sG   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/htmltmpl.pyR	   _  s    	 N(   RG   RH   RI   R   R   R   Rb   R   R   R   R   R	   (    (    (    sG   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/htmltmpl.pyR     s    2			
				R3   c           B   s   e  Z d  Z d   Z RS(   s   Fatal exception. Raised on runtime or template syntax errors.

        This exception is raised when a runtime error occurs or when a syntax
        error in the template is found. It has one parameter which always
        is a string containing a description of the error.

        All potential IOError exceptions are handled by the module and are
        converted to TemplateError exceptions. That means you should catch the
        TemplateError exception if there is a possibility that for example
        the template file will not be accesssible.

        The exception can be raised by constructors or by any method of any
        class.
        
        The instance is no longer usable when this exception is raised. 
    c         C   s   t  j |  d |  d S(   s*    Constructor.
            @hidden
        s   Htmltmpl error: N(   t	   ExceptionR   (   R
   RF   (    (    sG   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/htmltmpl.pyR   |  s    (   RG   RH   RI   R   (    (    (    sG   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/htmltmpl.pyR3   j  s   R   c           B   s   e  Z d  Z d   Z RS(   s@    This exception is _PRIVATE_ and non fatal.
        @hidden
    c         C   s   t  j |  |  d S(   s*    Constructor.
            @hidden
        N(   R   R   (   R
   R   (    (    sG   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/htmltmpl.pyR     s    (   RG   RH   RI   R   (    (    (    sG   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/htmltmpl.pyR     s   (   RI   R   t
   __author__t   typesR   R'   t   os.pathRa   R   R   R   R   R0   R   R-   R   Rd   Rf   Rg   Rh   Rm   R   RJ   R%   R   R   R3   R   (    (    (    sG   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/htmltmpl.pyt   <module>   s<   
    p