ó
TÓ´>c           @   sx   d  Z  d d l Z d d l Z d d l Z d d l Z d Z d Z d d
 d „  ƒ  YZ d e f d „  ƒ  YZ d	 „  Z	 d S(   s`  A class library for the generation of HTML documents.

Each HTML tag type has a supporting class which is responsible for
emitting itself as valid HTML formatted text. An attempt is made to
provide classes for newer HTML 3.2 and proposed tag elements.  The
definitive reference for HTML tag elements can be found at
[W3C].  Also, I used the HTML book by Musciano and
Kennedy from [O Reilly] (2nd. Ed.) as the guiding reference.

The Document classes are container objects which act as a focal point
to populate all the contents of a particular web page. It also can
enforce consistent document formating according to the guidelines from
the [Yale Web Style Manual].

Features include customization of document template graphics / colors
through use of resource files, minimizing the need for modifying or
subclassing from the module source code. Support for tables, frames,
forms (persistent and otherwise) and client-side imagemaps are included.

A newer implementation for the Table support is now included,
TableLite().  In support of this there are new tag classes TD, TH, TR
and Caption.  These class instances can be assembled in any way to
populate the TableLite container object. 

.. [W3C] http://www.W3.org/TR/REC-html32.html
.. [O Reilly] http://www.oreilly.com/catalog/html3/index.html
.. [Yale Web Style Manual] http://info.med.yale.edu/caim/manual/contents.html
iÿÿÿÿNs*   Robin Friedrich   friedrich@pythonpros.coms   2.2.2t   StringTemplatec           B   s_   e  Z d  Z d	 d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d	 d „ Z
 d	 d „ Z RS(
   s  Generate documents based on a template and a substitution mapping.

    Must use Python 1.5 or newer. Uses re and the get method on dictionaries.

    Usage:
       T = TemplateDocument('Xfile')
       T.substitutions = {'month': ObjectY, 'town': 'Scarborough'}
       T.write('Maine.html')

    A dictionary, or object that behaves like a dictionary, is assigned to the
    *substitutions* attribute which has symbols as keys to objects. Upon every
    occurance of these symbols surrounded by braces {} in the source template,
    the corresponding value is converted to a string and substituted in the output.

    For example, source text which looks like:
     I lost my heart at {town} Fair.
    becomes:
     I lost my heart at Scarborough Fair.

    Symbols in braces which do not correspond to a key in the dictionary remain
    unchanged.

    An optional third argument to the class is a list or two strings to be
    used as the delimiters instead of { } braces. They must be of the same
    length; for example ['##+', '##'] is invalid.
    c         K   s¼   d d g |  _  |  j j | ƒ t |  j  ƒ d k rC t d ƒ ‚ n  t |  j  d ƒ |  _ t t j |  j  ƒ } | d d | d |  _	 t j
 |  j	 ƒ |  _ | p¥ i  |  _ |  j | ƒ d  S(   Nt   {t   }i   s,   delimiter argument must be a pair of stringsi    s   [\w_]+i   (   t
   delimiterst   __dict__t   updatet   lent
   ValueErrort   delimiter_widtht   mapt   ret   escapet	   subpatstrt   compilet   subpatt   substitutionst   set_template(   t   selft   templateR   t   kwR   (    (    sK   /home/sdcc-builder/build/sdcc-build/orig/sdcc/support/regression/HTMLgen.pyt   __init__U   s    c         C   s   | |  _  d  S(   N(   t   source(   R   R   (    (    sK   /home/sdcc-builder/build/sdcc-build/orig/sdcc/support/regression/HTMLgen.pyR   a   s    c         C   s   |  j  j ƒ  S(   N(   R   t   keys(   R   (    (    sK   /home/sdcc-builder/build/sdcc-build/orig/sdcc/support/regression/HTMLgen.pyR   d   s    c         C   s   | |  j  | <d  S(   N(   R   (   R   t   namet   value(    (    sK   /home/sdcc-builder/build/sdcc-build/orig/sdcc/support/regression/HTMLgen.pyt   __setitem__g   s    c         C   s   |  j  | S(   N(   R   (   R   R   (    (    sK   /home/sdcc-builder/build/sdcc-build/orig/sdcc/support/regression/HTMLgen.pyt   __getitem__j   s    c         C   s   |  j  |  j ƒ S(   N(   t   _subR   (   R   (    (    sK   /home/sdcc-builder/build/sdcc-build/orig/sdcc/support/regression/HTMLgen.pyt   __str__m   s    c   
   	   C   s÷   | p |  j  } |  j } d } g  } |  j j | | ƒ } xª | rÕ | j ƒ  \ } }	 | j | | | | !ƒ | j t | j | | | | | |	 | !| | | | |	 !ƒ ƒ ƒ | |	 } |  j j | | ƒ } q= W| j | | ƒ t j	 | d ƒ S(   sœ   Perform source text substitutions.

        *source* string containing template source text
        *subs* mapping of symbols to replacement values
        i    t    (
   R   R   R   t   searcht   spant   appendt   strt   gett   stringt   join(
   R   R   t   subsR   t   dwt   it   outputt   matchedt   at   b(    (    sK   /home/sdcc-builder/build/sdcc-build/orig/sdcc/support/regression/HTMLgen.pyR   p   s    		6
c         C   sº   | r” t  j j | ƒ re t |  ƒ } t | | ƒ r‘ t | d ƒ } | j t |  ƒ ƒ | j ƒ  q‘ q¶ t | d ƒ } | j t |  ƒ ƒ | j ƒ  n" d d l } | j	 j t |  ƒ ƒ d S(   s  Emit the Document HTML to a file or standard output.
        
        Will not overwrite file is it exists and is textually the same.
        In Unix you can use environment variables in filenames.
        Will print to stdout if no argument given.
        t   wiÿÿÿÿN(
   t   ost   patht   existsR!   t   compare_s2ft   opent   writet   closet   syst   stdout(   R   t   filenamet   st   fR4   (    (    sK   /home/sdcc-builder/build/sdcc-build/orig/sdcc/support/regression/HTMLgen.pyR2   ‡   s    N(   t   __name__t
   __module__t   __doc__t   NoneR   R   R   R   R   R   R   R2   (    (    (    sK   /home/sdcc-builder/build/sdcc-build/orig/sdcc/support/regression/HTMLgen.pyR    :   s   					t   TemplateDocumentc           B   s   e  Z d  Z d „  Z RS(   s  Generate documents based on a template and a substitution mapping.

    Must use Python 1.5 or newer. Uses re and the get method on dictionaries.

    Usage:
       T = TemplateDocument('Xfile')
       T.substitutions = {'month': ObjectY, 'town': 'Scarborough'}
       T.write('Maine.html')

    A dictionary, or object that behaves like a dictionary, is assigned to the
    *substitutions* attribute which has symbols as keys to objects. Upon every
    occurance of these symbols surrounded by braces {} in the source template,
    the corresponding value is converted to a string and substituted in the output.

    For example, source text which looks like:
     I lost my heart at {town} Fair.
    becomes:
     I lost my heart at Scarborough Fair.

    Symbols in braces which do not correspond to a key in the dictionary remain
    unchanged.

    An optional third argument to the class is a list or two strings to be
    used as the delimiters instead of { } braces. They must be of the same
    length; for example ['##+', '##'] is invalid.
    c         C   s)   t  | ƒ } | j ƒ  |  _ | j ƒ  d  S(   N(   R1   t   readR   R3   (   R   R   R8   (    (    sK   /home/sdcc-builder/build/sdcc-build/orig/sdcc/support/regression/HTMLgen.pyR   ¸   s    (   R9   R:   R;   R   (    (    (    sK   /home/sdcc-builder/build/sdcc-build/orig/sdcc/support/regression/HTMLgen.pyR=      s   c         C   s§   d } d } t  | ƒ } z} xv y |  | | | !} | | } Wn t k
 rV d } n X| j | ƒ } | rx | rx d St | | ƒ } | r | Sq Wd | j ƒ  Xd S(   sA   Helper to compare a string to a file, return 0 if they are equal.i    i    R   N(   R1   t
   IndexErrorR>   t   cmpR3   (   R7   t   f2t   BUFSIZER'   t   fp2t   b1t   b2t   c(    (    sK   /home/sdcc-builder/build/sdcc-build/orig/sdcc/support/regression/HTMLgen.pyR0   ½   s"    
  (    (
   R;   R#   R
   t   timeR-   t
   __author__t   __version__R    R=   R0   (    (    (    sK   /home/sdcc-builder/build/sdcc-build/orig/sdcc/support/regression/HTMLgen.pyt   <module>/   s   0c 