
Je|Mc           @   s  d  Z  d d g Z d Z d Z d Z d Z d Z d Z d	 Z d
 Z	 d
 Z
 e Z d
 Z d
 Z e Z d Z d d k Z d d k Z d d k Z d d k Z y d d k Z Wn e j
 o e Z n Xd   Z y) d d k Z d d k l Z d   Z Wn e j
 o e Z n Xy# d d k l Z d   Z e Z WnN e j
 oB y d d k Z d   Z  e  Z Wn e j
 o e Z n Xn Xd d  Z! h  d d <d d <d d <d d <d d <Z" h  d  d! <d" d# <d$ e" d% <d& e" d' <d( e" d) <d* e" d+ <d, e" d- <d. e" d/ <d0 d1 <d2 e" d3 <Z# d4   Z$ d5   Z% d6 e i& f d7     YZ' d8 e' f d9     YZ( d: f  d;     YZ) d<   Z* e+ d= j o e* d> d? d GHn d S(@   s   This is Textile
A Humane Web Text Generator

TODO:
* Make it work with Python 2.1.
* Make it work with Python 1.5.2? Or that's too optimistic?

---
To get an overview of all PyTextile's features, simply
type 'tell me about textile.' in a single line.
s0   Roberto A. F. De Almeida (roberto@dealmeida.net)s$   Mark Pilgrim (f8dy@diveintomark.org)s   2.0.10s
   2004/10/06s  
Copyright (c) 2004, Roberto A. F. De Almeida, http://dealmeida.net/
Copyright (c) 2003, Mark Pilgrim, http://diveintomark.org/
All rights reserved.

Original PHP version:
Version 1.0
21 Feb, 2003

Copyright (c) 2003, Dean Allen, www.textism.com
All rights reserved.

Parts of the documentation and some of the regular expressions are (c) Brad
Choate, http://bradchoate.com/. Thanks, Brad!
s  
Redistribution and use in source and binary forms, with or without 
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, 
  this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
  this list of conditions and the following disclaimer in the documentation
  and/or other materials provided with the distribution.

* Neither the name Textile nor the names of its contributors may be used to
  endorse or promote products derived from this software without specific
  prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
s  
1.0 - 2003/03/19 - MAP - initial release
1.01 - 2003/03/19 - MAP - don't strip whitespace within <pre> tags;
  map high-bit ASCII to HTML numeric entities
1.02 - 2003/03/19 - MAP - changed hyperlink qtag expression to only
  match valid URL characters (per RFC 2396); fixed preg_replace to
  not match across line breaks (solves lots of problems with
  mistakenly matching overlapping inline markup); fixed whitespace
  stripping to only strip whitespace from beginning and end of lines,
  not immediately before and after HTML tags.
1.03 - 2003/03/20 - MAP - changed hyperlink qtag again to more
  closely match original Textile (fixes problems with links
  immediately followed by punctuation -- somewhere Dean is
  grinning right now); handle curly apostrophe with "ve"
  contraction; clean up empty titles at end.
1.04 - 2003/03/23 - MAP - lstrip input to deal with extra spaces at
  beginning of first line; tweaked list loop to handle consecutive lists
1.1 - 2003/06/06 - MAP - created initial test suite for links and images,
  and fixed a bunch of related bugs to pass them
1.11 - 2003/07/20 - CL - don't demoronise unicode strings; handle
  "they're" properly
1.12 - 2003/07/23 - GW - print debug messages to stderr; handle bq(cite).
1.13 - 2003/07/23 - MAP - wrap bq. text in <p>...</p>
2 - 2004/03/26 - RAFA - rewritten from (almost) scratch to include
  all features from Textile 2 and a little bit more.
2.0.1 - 2004/04/02 - RAFA - Fixed validating function that uses uTidyLib.
2.0.2 - 2004/04/02 - RAFA - Fixed problem with caps letters in URLs.
2.0.3 - 2004/04/19 - RAFA - Multiple classes are allowed, thanks to Dave
  Anderson. The "lang" attribute is now removed from <code>, to be valid
  XHTML. Fixed <span class="caps">UCAS</span> problem.
2.0.4 - 2004/05/20 - RAFA, CLB - Added inline formatting to table cells.
  Curt Bergmann fixed a bug with the colspan formatting. Added Amazon
  Associated id.
2.0.5 - 2004/06/01 - CL - Applied patch from Chris Lawrence to (1) fix
  that Amazon associates ID was being added to all search URIs, (2)
  customize the Amazon site used with the AMAZON variable, and (3) added
  an "isbn" URI type that links directly to an Amazon product by ISBN or
  Amazon ASIN.
2.0.6 - 2004/06/02 - RAFA - Fixed CAPS problem, again. I hope this is
  the last time.
2.0.7 - 2004/06/04 - RAFA, MW - Fixed bullet macro, thanks to Adam
  Messinger. Added patch from Michal Wallace changing {}.pop() for
  compatibility with Python 2.2.x.
2.0.8 - 2004/06/25 - RAFA - Strip tags when adding the content from a
  footnote to the reference link. Escaped '<' and '>' in the self-
  generated documentation.
2.0.9 - 2004/10/04 - RAFA - In images, if ALT is not defined, add an
  empty attribute. Added "LaTeX" style open/close quotes. Fixed a bug 
  where the acronym definition was being formatted with inline rules. 
  Handle "broken" lines correctly, removing the <br /> from inside
  split HTML tags.
2.0.10 - 2004/10/06 - RAFA, LO - Escape all non-escaped ampersands.
  Applied "trivial patch" from Ludvig Omholt to remove newline right
  after the <pre> tag.
s   latin-1t   asciii    s   www.amazon.comiNc         C   s   |  i  d |  oH |  i d | d  d }  |  i  d  o |  i d d  d }  q\ n |  i  d |  o |  i d | d  d }  n |  i   i d d  }  |  S(   s   Extracts text from inside a tag.

    This function extracts the text from inside a given tag.
    It's useful to get the text between <body></body> or
    <pre></pre> when using the validators or the colorizer.
    s   <%si   t   >s   </%si    s   
s   
(   t   countt   splitt   stript   replace(   t   textt   tag(    (    sb   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/textile.pyt   _in_tag   s    (   t   StringIOc         C   sb   t  d d |   }  t |   } t   } t i | |  t | i   d  }  |  i d d  }  |  S(   s   Colorizer Python code.

        This function wraps a text string in a StringIO,
        and passes it to the htmlizer function from
        Twisted.
        s    \\\ns    \\
t   pres%   <span class="py-src-newline">
</span>s%   <span class="py-src-newline"></span>
(   t   preg_replaceR	   t   htmlizert   filterR   t   getvalueR   (   t   codet   code_int   code_out(    (    sb   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/textile.pyt   _color   s    	(   t   Tidyc         C   s:   t  i |  d d d d d d \ } } }  } t |  d  S(   s]   mxTidy's XHTML validator.

        This function is a wrapper to mxTidy's validator.
        t   output_xhtmli   t   numeric_entitiest   wrapi    t   body(   R   t   tidyR   (   R   t   nerrorst	   nwarningst	   errortext(    (    sb   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/textile.pyt   _tidy1   s    -c      
   C   s:   t  i |  d d d d d d d d }  t t |   d  S(   si   uTidyLib's XHTML validator.

            This function is a wrapper to uTidyLib's validator.
            R   i   t   add_xml_decli    t   indentt	   tidy_markR   (   R   t   parseStringR   t   str(   R   (    (    sb   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/textile.pyt   _tidy2   s    'i   c         C   s"   t  | j o t i |  IJn d S(   s   Outputs debug information to sys.stderr.

    This function outputs debug information if DEBUGLEVEL is
    higher than a given treshold.
    N(   t
   DEBUGLEVELt   syst   stderr(   t   st   level(    (    sb   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/textile.pyt   _debug  s     s   (?:(?:<>|[<>=])                 # Either '<>', '<', '>' or '='
                    (?![^\s]*(?:<>|[<>=])))         # Look-ahead to ensure it happens once
                 t   alignsP   (?:[\(\)]+)                     # Any number of '(' and/or ')'
                 t   paddings  (                               #
                        (?:\(\#[\w]+\))             # (#id)
                        |                           #
                        (?:\((?:[\w]+(?:\s[\w]+)*)  #
                            (?:\#[\w]+)?\))         # (class1 class2 ... classn#id) or (class1 class2 ... classn)
                    )                               #
                    (?![^\s]*(?:\([\w#]+\)))        # must happen once
                 t   classids   (?:\[[\w-]+\])                  # [lang]
                    (?![^\s]*(?:\[.*?\]))           # must happen once
                 t   langs   (?:{[^\}]+})                    # {style}
                    (?![^\s]*(?:{.*?}))             # must happen once
                 t   styles/   [\!"#\$%&'()\*\+,\-\./:;<=>\?@\[\\\]\^_`{\|}\~]t   punctsp  (?=[a-zA-Z0-9./#])                         # Must start correctly
                 (?:                                        # Match the leading part (proto://hostname, or just hostname)
                     (?:ftp|https?|telnet|nntp)             #     protocol
                     ://                                    #     ://
                     (?:                                    #     Optional 'username:password@'
                         \w+                                #         username
                         (?::\w+)?                          #         optional :password
                         @                                  #         @
                     )?                                     # 
                     [-\w]+(?:\.\w[-\w]*)+                  #     hostname (sub.example.com)
                 |                                          #
                     (?:mailto:)?                           #     Optional mailto:
                     [-\+\w]+                               #     username
                     \@                                     #     at
                     [-\w]+(?:\.\w[-\w]*)+                  #     hostname
                 |                                          #
                     (?:[a-z0-9](?:[-a-z0-9]*[a-z0-9])?\.)+ #     domain without protocol
                     (?:com\b                               #     TLD
                     |  edu\b                               #
                     |  biz\b                               #
                     |  gov\b                               #
                     |  in(?:t|fo)\b                        #     .int or .info
                     |  mil\b                               #
                     |  net\b                               #
                     |  org\b                               #
                     |  museum\b                            #
                     |  aero\b                              #
                     |  coop\b                              #
                     |  name\b                              #
                     |  pro\b                               #
                     |  [a-z][a-z]\b                        #     two-letter country codes
                     )                                      #
                 )?                                         #
                 (?::\d+)?                                  # Optional port number
                 (?:                                        # Rest of the URL, optional
                     /?                                     #     Start with '/'
                     [^.!,?;:"'<>()\[\]{}\s\x7F-\xFF]*      #     Can't start with these
                     (?:                                    #
                         [.!,?;:]+                          #     One or more of these
                         [^.!,?;:"'<>()\[\]{}\s\x7F-\xFF]+  #     Can't finish with these
                         #'"                                #     # or ' or "
                     )*                                     #
                 )?                                         #
              t   urls$  (?P<parameters>                            # 
                     (?: %(align)s                          # alignment
                     |   %(classid)s                        # class and/or id
                     |   %(padding)s                        # padding tags
                     |   %(lang)s                           # [lang]
                     |   %(style)s                          # {style}
                     )+                                     #
                 )?                                         #
              t   battrsM  (?P<olparameters>                         # 
                      (?: %(align)s                         # alignment
                      | ((?:\(\#[\w]+\))                    # (#id)
                          |                                 #
                          (?:\((?:[\w]+(?:\s[\w]+)*)        #
                            (?:\#[\w]+)?\))                 # (class1 class2 ... classn#id) or (class1 class2 ... classn)
                      )                                     #
                      |   %(padding)s                       # padding tags
                      |   %(lang)s                          # [lang]
                      |   %(style)s                         # {style}
                      )+                                    #
                  )?                                        #
              t   olattrs#  (?P<liparameters>                         # 
                      (?: %(align)s                         # alignment
                      |   %(classid)s                       # class and/or id
                      |   %(padding)s                       # padding tags
                      |   %(lang)s                          # [lang]
                      |   %(style)s                         # {style}
                      )+                                    #
                  )?                                        #
              t   liattrs  (?P<parameters>                            #
                     (?: %(classid)s                        # class and/or id
                     |   %(lang)s                           # [lang]
                     |   %(style)s                          # {style}
                     )+                                     #
                 )?                                         #
              t   qattrs  (?P<parameters>                            # Links attributes
                     (?: %(align)s                          # alignment
                     |   %(classid)s                        # class and/or id
                     |   %(lang)s                           # [lang]
                     |   %(style)s                          # {style}
                     )+                                     #
                 )?                                         #
              t   lattrsk  (?P<parameters>                            #
                     (?:                                    #
                     (?: [<>]+                              # horizontal alignment tags
                         (?![^\s]*(?:[<>])))                #     (must happen once)
                     |                                      # 
                     (?: [\-\^~]+                           # vertical alignment tags
                         (?![^\s]*(?:[\-\^~])))             #     (must happen once)
                     | %(classid)s                          # class and/or id
                     | %(padding)s                          # padding tags
                     | %(style)s                            # {style}
                     )+                                     #
                 )?                                         #
              t   iattrsT  (?:                                       #
                      (?:([\d]+%?)x([\d]+%?))               # 20x10
                      |                                     #
                      (?:                                   # or
                          (?:([\d]+)%?w\s([\d]+)%?h)        #     10h 20w
                          |                                 #     or
                          (?:([\d]+)%?h\s([\d]+)%?w)        #     20w 10h 
                      )                                     #
                  )?                                        #
               t   resizes  (?P<parameters>                            #
                     (?:                                    #
                     (?: [\^~]                              # vertical alignment
                         (?![^\s]*(?:[\^~])))               #     (must happen once)
                     |   %(align)s                          # alignment
                     |   %(lang)s                           # [lang]
                     |   %(style)s                          # {style}
                     |   %(classid)s                        # class and/or id
                     |   %(padding)s                        # padding
                     |   _                                  # is this a header row/cell?
                     |   \\\d+                              # colspan
                     |   /\d+                               # rowspan
                     )+                                     #
                 )?                                         #
              t   tattrc            s8     f d   } t  i |   } t |   | i | |  S(   s   Alternative re.sub that handles empty groups.

    This acts like re.sub, except it replaces empty groups with ''
    instead of raising an exception.
    c            sh   d }   } t  |  i    xE |  i   D]7 } | p
 d } n | i d | |  } | d 7} q) W| S(   Ni   t    s   \%s(   R(   t   groupsR   (   t   matchobjt   countert   rct	   matchitem(   t   replacement(    sb   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/textile.pyt   replacement_func  s     
(   t   ret   compileR(   t   sub(   t   patternR>   R   R?   t   p(    (   R>   sb   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/textile.pyR     s    
c         C   s   t  i d |  p t |  | |  Sng g  } xP t  i d |  D]< } t  i d |  p t |  | |  } n | i |  q@ Wd i |  Sd S(   sT   Replacement outside HTML tags.

    Does a preg_replace only outside HTML tags.
    s   <.*>s   (<.*?>)s   <.*?>R8   N(   R@   t   searchR   R   t   matcht   appendt   join(   RC   R>   R   t   linest   line(    (    sb   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/textile.pyt   html_replace  s     t   _BaseHTMLProcessorc           B   s   e  Z d  d d d d d d d d d	 d
 d d g 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(   t   areat   baset   basefontt   brt   colt   framet   hrt   imgt   inputt   isindext   linkt   metat   paramc         C   s   t  i i |   d  S(   N(   t   sgmllibt
   SGMLParsert   __init__(   t   self(    (    sb   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/textile.pyR\     s    c         C   s   g  |  _  t i i |   d  S(   N(   t   piecesRZ   R[   t   reset(   R]   (    (    sb   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/textile.pyR_     s    	c      	   C   s   g  } | D]7 \ } } | | i    t i i d   |  i   f q ~ } g  } | D]3 \ } } | | | d j o | i    p | f qV ~ } | S(   Nc         S   s   t  t |  i   d    S(   i    (   t   unichrt   intR9   (   t   m(    (    sb   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/textile.pyt   <lambda>  s    t   relt   type(   s   rels   type(   t   lowerRZ   t   charrefRB   R   (   R]   t   attrst   _[1]t   kt   vt   _[2](    (    sb   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/textile.pyt   normalize_attrs  s    KGc         C   s   d i  g  } | D] \ } } | d | | f q ~  } | |  i j o |  i i d t    n |  i i d t    d  S(   NR8   s    %s="%s"s   <%(tag)s%(strattrs)s />s   <%(tag)s%(strattrs)s>(   RH   t   elements_no_end_tagR^   RG   t   locals(   R]   R   Rh   Ri   t   keyt   valuet   strattrs(    (    sb   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/textile.pyt   unknown_starttag  s    :c         C   s/   | |  i  j o |  i i d t    n d  S(   Ns
   </%(tag)s>(   Rn   R^   RG   Ro   (   R]   R   (    (    sb   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/textile.pyt   unknown_endtag  s    c         C   s   |  i  i d t    d  S(   Ns
   &#%(ref)s;(   R^   RG   Ro   (   R]   t   ref(    (    sb   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/textile.pyt   handle_charref  s    c         C   s   |  i  i d t    d  S(   Ns	   &%(ref)s;(   R^   RG   Ro   (   R]   Ru   (    (    sb   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/textile.pyt   handle_entityref   s    c         C   s   |  i  i |  d  S(   N(   R^   RG   (   R]   R   (    (    sb   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/textile.pyt   handle_data%  s    c         C   s   |  i  i d t    d  S(   Ns   <!--%(text)s-->(   R^   RG   Ro   (   R]   R   (    (    sb   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/textile.pyt   handle_comment+  s    c         C   s   |  i  i d t    d  S(   Ns   <?%(text)s>(   R^   RG   Ro   (   R]   R   (    (    sb   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/textile.pyt	   handle_pi0  s    c         C   s   |  i  i d t    d  S(   Ns   <!%(text)s>(   R^   RG   Ro   (   R]   R   (    (    sb   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/textile.pyt   handle_decl5  s    c         C   s   d i  |  i  S(   s(   Return processed HTML as a single stringR8   (   RH   R^   (   R]   (    (    sb   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/textile.pyt   output<  s    (   t   __name__t
   __module__Rn   R\   R_   Rm   Rs   Rt   Rv   Rw   Rx   Ry   Rz   R{   R|   (    (    (    sb   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/textile.pyRL     s   				
							t   _HTMLSanitizerc        G   B   s8  e  Z d  d d d d d d d d d	 d
 d d d d d d d d d d d d d d d d d d d d d d  d! d" d# d$ d% d& d' d( d) d* d+ d, d- d. d/ d0 d1 d2 d3 d4 d5 d6 d7 d8 d9 d: d; d< d= d> d? d@ dA dB dC dD dE dF gG Z d dG dH dI dJ dK dL dM dN dO dP dQ dR dS dT d dU dV dW dX dY dZ d[ d\ d d] d^ d_ d` da db dc dd de df dg d' dh di dj dk dl dm dn do dp dq dr ds dt du dv dw dx dy dz d{ d| d6 d} d~ d d d d d d d d d d gG Z d d g Z d d d d d d g Z d d g Z e e Z e e Z d   Z d   Z d   Z	 d   Z
 d   Z d   Z RS(   t   at   abbrt   acronymt   addressRM   t   bt   bigt
   blockquoteRP   t   buttont   captiont   centert   citeR   RQ   t   colgroupt   ddt   delt   dfnt   dirt   divt   dlt   dtt   emt   fieldsett   fontt   formt   h1t   h2t   h3t   h4t   h5t   h6RS   t   iRT   RU   t   inst   kbdt   labelt   legendt   lit   mapt   menut   olt   optgroupt   optionRD   R
   t   qR&   t   sampt   selectt   smallt   spant   striket   strongRB   t   supt   tablet   tbodyt   tdt   textareat   tfoott   tht   theadt   trt   ttt   ut   ult   vart   accepts   accept-charsett	   accesskeyt   actionR)   t   altt   axist   bordert   cellpaddingt   cellspacingt   chart   charofft   charsett   checkedt   classt   cleart   colst   colspant   colort   compactt   coordst   datetimet   disabledt   enctypet   forRR   t   headerst   heightt   hreft   hreflangt   hspacet   idt   ismapR,   t   longdesct	   maxlengtht   mediat   methodt   multiplet   namet   nohreft   noshadet   nowrapt   promptt   readonlyRd   t   revt   rowst   rowspant   rulest   scopet   selectedt   shapet   sizet   srct   startt   summaryt   tabindext   targett   titleRe   t   usemapt   valignRq   t   vspacet   widtht   scriptt   applett   matht   mit   mnt   mot   mrowt   msupt   modet   xmlnsc         C   s   t  i |   d |  _ d  S(   Ni    (   RL   R_   t   unacceptablestack(   R]   (    (    sb   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/textile.pyR_   _  s    c         C   s   | |  i  j o+ | |  i j o |  i d 7_ n d  Sn |  i |  } g  } | D]- \ } } | |  i j o | | | f qU qU ~ } t i |  | |  d  S(   Ni   (   t   acceptable_elementst"   unacceptable_elements_with_end_tagR  Rm   t   acceptable_attributesRL   Rs   (   R]   R   Rh   Ri   Rp   Rq   (    (    sb   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/textile.pyRs   c  s    Ac         C   sO   | |  i  j o+ | |  i j o |  i d 8_ n d  Sn t i |  |  d  S(   Ni   (   R  R  R  RL   Rt   (   R]   R   (    (    sb   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/textile.pyRt   l  s
    c         C   s   d  S(   N(    (   R]   R   (    (    sb   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/textile.pyRz   s  s    c         C   s   d  S(   N(    (   R]   R   (    (    sb   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/textile.pyR{   v  s    c         C   s"   |  i  p t i |  |  n d  S(   N(   R  RL   Rx   (   R]   R   (    (    sb   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/textile.pyRx   y  s    
(   R}   R~   R  R  R  t   mathml_elementst   mathml_attributesR_   Rs   Rt   Rz   R{   Rx   (    (    (    sb   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/textile.pyR   A  s:   $

						t   Textilerc           B   s  e  Z d  Z d d  Z d   Z d   Z e e e e	 e
 d  Z d   Z d   Z d% d d	  Z h  d
 d  Z d% d% d% d  Z d% d% d  Z d% d% d  Z d% d% d  Z d% d% d% d  Z d% d d% d  Z d% d d% d  Z d   Z d% d% d% d  Z d% d% d% d  Z d% d% d  Z d   Z d   Z d% d  Z d   Z d   Z  d   Z! d   Z" d   Z# d    Z$ d!   Z% d"   Z& d#   Z' d$   Z( RS(&   sU   Textile formatter.

    This is the base class for the PyTextile text processor.
    R8   c         C   s  | |  _  t |  _ h  |  _ d |  i d <d |  i d <d |  i d <t oH d i d t d	 t g  |  i d
 <d i d t d t g  |  i d <n? d i d t d g  |  i d
 <d i d t d g  |  i d <d |  i |  i f d |  i |  i f d |  i |  i f d |  i |  i	 f d |  i |  i
 f d |  i f d |  i |  i f d |  i |  i f d |  i |  i f d |  i f d |  i f d |  i f d |  i |  i f d |  i f d |  i f g |  _ d S(   s   Instantiate the class, passing the text to be formatted.
            
        Here we pre-process the text and collect all the link
        lookups for later.
        s   http://www.imdb.com/Find?for=%st   imdbs!   http://www.google.com/search?q=%st   googles4   http://www.python.org/doc/current/lib/module-%s.htmlt   pythonR8   s   http://s   /exec/obidos/ASIN/%s/t   isbns9   /exec/obidos/external-search?mode=blended&keyword=%s&tag=t   amazons   /exec/obidos/ASIN/%ss4   /exec/obidos/external-search?mode=blended&keyword=%ss  ^p                       # Paragraph signature
                                %(battr)s                # Paragraph attributes
                                (?P<dot>\.)              # .
                                (?P<extend>\.)?          # Extended paragraph denoted by a second dot
                                \s                       # whitespace
                                (?P<text>.*)             # text
                             s  ^pre                     # Pre signature
                                %(battr)s                # Pre attributes
                                (?P<dot>\.)              # .
                                (?P<extend>\.)?          # Extended pre denoted by a second dot
                                \s                       # whitespace
                                (?P<text>.*)             # text
                             s  ^bc                      # Blockcode signature
                                %(battr)s                # Blockcode attributes
                                (?P<dot>\.)              # .
                                (?P<extend>\.)?          # Extended blockcode denoted by a second dot
                                \s                       # whitespace
                                (?P<text>.*)             # text
                             sc  ^bq                      # Blockquote signature
                                %(battr)s                # Blockquote attributes
                                (?P<dot>\.)              # .
                                (?P<extend>\.)?          # Extended blockquote denoted by a second dot
                                (:(?P<cite>              # Optional cite attribute
                                (                        #
                                    %(url)s              #     URL
                                |   "[\w]+(?:\s[\w]+)*"  #     "Name inside quotes"
                                ))                       #
                                )?                       #
                                \s                       # whitespace
                                (?P<text>.*)             # text
                             s  ^h                       # Header signature
                                (?P<header>\d)           # Header number
                                %(battr)s                # Header attributes
                                (?P<dot>\.)              # .
                                (?P<extend>\.)?          # Extended header denoted by a second dot
                                \s                       # whitespace
                                (?P<text>.*)             # text
                             s  ^fn                      # Footnote signature
                                (?P<footnote>[\d]+)      # Footnote number
                                (?P<dot>\.)              # .
                                (?P<extend>\.)?          # Extended footnote denoted by a second dot
                                \s                       # whitespace
                                (?P<text>.*)             # text
                             s  ^dl                      # Definition list signature
                                %(battr)s                # Definition list attributes
                                (?P<dot>\.)              # .
                                (?P<extend>\.)?          # Extended definition list denoted by a second dot
                                \s                       # whitespace
                                (?P<text>.*)             # text
                             s  ^%(olattr)s              # Ordered list attributes
                                \#                       # Ordered list signature
                                %(liattr)s               # List item attributes
                                (?P<dot>\.)?             # .
                                \s                       # whitespace
                                (?P<text>.*)             # text
                             s  ^%(olattr)s              # Unrdered list attributes
                                \*                       # Unordered list signature
                                %(liattr)s               # Unordered list attributes
                                (?P<dot>\.)?             # .
                                \s                       # whitespace
                                (?P<text>.*)             # text
                             sE   ^==?(?P<text>.*?)(==)?$  # Escaped text
                             sB   ^(?P<text><.*)$          # XHTML tag
                             s:  ^(?P<text>               # itex code
                                \\\[                     # starts with \[
                                .*?                      # complicated mathematical equations go here
                                \\\])                    # ends with \]
                             s  ^table                   # Table signature
                                %(tattr)s                # Table attributes
                                (?P<dot>\.)              # .
                                (?P<extend>\.)?          # Extended blockcode denoted by a second dot
                                \s                       # whitespace
                                (?P<text>.*)             # text
                             so   ^(?P<text>
                                \|
                                .*)
                             s&   ^(?P<text>tell\sme\sabout\stextile\.)$N(   R   t   rest   searchest   amazon_associate_idRH   t   AMAZONt	   paragraphR
   t   bcR   t   headert   footnoteR   R   R   t   escapet   itexR   t   aboutt
   signatures(   R]   R   (    (    sb   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/textile.pyR\     s4    			"&		
					c         C   s[   |  i  i   |  _  |  i  i d d  |  _  |  i  i d d  |  _  |  i |  i   |  _  d S(   sV   Pre-processing of the text.

        Remove whitespace, fix carriage returns.
        s   
s   
s   N(   R   R   R   t   sanitize(   R]   (    (    sb   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/textile.pyt
   preprocess  s    c         C   sk   h  } t  i d |  i t  i  } x* | i |  i  D] \ } } | | | <q5 W| i d |  i  |  _ | S(   s}   Grab link lookups.

        Check the text for link lookups, store them in a 
        dictionary, and clean them up.
        s%   (?:^|\n)\[([\w]+?)\](%(url)s)(?:$|\n)R8   (   R@   RA   R  t   VERBOSEt   findallR   RB   (   R]   t   linksRD   Rp   RW   (    (    sb   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/textile.pyt
   grab_links&  s     c   
      C   s  |  i    |  i   |  _ | |  _ |  i   |  _ g  } x* |  i D] \ } } | i | |    qA Wd i |  } |  i |  } t	 | t
  o t | |  } n | i | d  } | o& t   }	 |	 i |  |	 i   } n t o | o t |  } n | S(   s   Process the text.

        Here we actually process the text, splitting the text in
        blocks and applying the corresponding function to each
        one of them.
        s   

t   xmlcharrefreplace(   R  R  t   _linkst   head_offsett
   split_textt   blocksRG   RH   t	   footnotest
   isinstanceR!   t   unicodet   encodeR   t   feedR|   t   _tidy(
   R]   R!  t   validateR  R|   t   encodingR   t   functiont   capturesRD   (    (    sb   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/textile.pyt   process8  s(    
	
 	c         C   s(   t  d d |  } t  d d |  } | S(   sn  Fix single tags.

        Fix tags like <img />, <br /> and <hr />.

        ---
        h1. Sanitizing

        Textile can help you generate valid XHTML(eXtensible HyperText Markup Language).
        It will fix any single tags that are not properly closed, like
        @<img />@, @<br />@ and @<hr />@.

        If you have "mx.Tidy":http://www.egenix.com/files/python/mxTidy.html
        and/or "&micro;TidyLib":http://utidylib.sourceforge.net/ installed,
        it also can optionally validade the generated code with these wrappers
        to ensure 100% valid XHTML(eXtensible HyperText Markup Language).
        s   <(img|br|hr)(.*?)(?:\s*/?\s*)?>s   <\1\2 />s%   &(?!#?[xX]?(?:[0-9a-fA-F]+|\w{1,8});)s   &amp;(   R   (   R]   R   (    (    sb   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/textile.pyR  f  s    c      	   C   s&  d } d } d } t i d |  i  } g  } x| D]} t i | |  } | o@ | i d  } | o  h  d d <d d <| } qd	 } q4 x|  i D]*\ } }	 t i | t i t i	 B }
 |
 i |  } | o | i
   } | o1 | i d
 d  o | d d d c | 7<Pn | i d
  o | d
 =n d } | i d  o | d } | d =n | i d  o t | d  |  i | d <n | o | | d <d } n | i |	 | g  Pq q W| o | d d d c | 7<q4 | i   o# | i |  i h  | d <g  q4 q4 W| S(   s9	  Process the blocks from the text.

        Split the blocks according to the signatures, join extended
        blocks and associate each one of them with a function to
        process them.

        ---
        h1. Blocks

        Textile process your text by dividing it in blocks. Each block
        is identified by a signature and separated from other blocks by
        an empty line.

        All signatures should end with a period followed by a space. A
        header @<h1></h1>@ can be done this way:

        pre. h1. This is a header 1.

        Blocks may continue for multiple paragraphs of text. If you want
        a block signature to stay "active", use two periods after the
        signature instead of one. For example:

        pre.. bq.. This is paragraph one of a block quote.

        This is paragraph two of a block quote.

        =p. Now we're back to a regular paragraph.

        p. Becomes:
        
        pre.. <blockquote>
        <p>This is paragraph one of a block quote.</p>

        <p>This is paragraph two of a block quote.</p>
        </blockquote>

        <p>Now we&#8217;re back to a regular paragraph.</p>

        p. The blocks can be customised by adding parameters between the
        signature and the period. These include:

        dl. {style rule}:A CSS(Cascading Style Sheets) style rule.
        [ll]:A language identifier (for a "lang" attribute).
        (class) or (#id) or (class#id):For CSS(Cascading Style Sheets) class and id attributes.
        &gt;, &lt;, =, &lt;&gt;:Modifier characters for alignment. Right-justification, left-justification, centered, and full-justification. The paragraph will also receive the class names "right", "left", "center" and "justify", respectively.
        ( (one or more):Adds padding on the left. 1em per "(" character is applied. When combined with the align-left or align-right modifier, it makes the block float. 
        ) (one or more):Adds padding on the right. 1em per ")" character is applied. When combined with the align-left or align-right modifier, it makes the block float.

        Here's an overloaded example:

        pre. p(())>(class#id)[en]{color:red}. A simple paragraph.

        Becomes:

        pre. <p lang="en" style="color:red;padding-left:2em;padding-right:2em;float:right;" class="class right" id="id">A simple paragraph.</p>
        s   ^clear(?P<alignment>[<>])?\.$i    s   (\n{2,})t	   alignments   clear:left;t   <s   clear:right;R   s   clear:both;t   dotii   R   t   extendR  R   N(   t   NoneR@   R   R   RF   t   groupR  RA   R  t   DOTALLt	   groupdictt   gett   has_keyRa   R!  RG   R   R  (   R]   t	   clear_sigR   t	   extendingR#  R|   t   blockRb   t   regexpR,  RD   R-  (    (    sb   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/textile.pyR"    sP    :  

 


	'R;  c         C   sS  | p  | o h  | d <Sq' h  Sn h  } t  i d |  } | o | i d  | d <n t  i d |  } | o | i d  | d <n t  i d |  } | o | i d  | d <n t  i d |  } | oK | i d  i d	 d
  | d <| d i d  p | d c d 7<q!n | o | i d d
  | | d <n t d d
 |  } t d d
 |  } t d d
 |  } g  } | i d  } | o | i d |  n | i d  } | o | i d |  n | d j o d9 d: g }	 d; d< d= g }
 x|	 |
 g D]\ } xS | D]K \ } } } | i |  o, | i |  | i d d
  | | d <PqqWqWn| d# j o d> d? d@ dA g }	 dB dC g }
 x2 |	 D]* \ } } | i |  o | | d, <qqWx2 |
 D]* \ } } | i |  o | | d- <qqWt  i d. |  } | o t	 | i
   d/  | d0 <n t  i d1 |  } | o t	 | i
   d/  | d2 <qn | p | o dD dE dF dG g } n dH dI dJ dK g } xS | D]K \ } } } | i |  o, | i |  | i d d
  | | d <PqqW| i d d
  d
 i |  | d <| i d  o | d i   | d <n | S(L   s  Parse the parameters from a block signature.

        This function parses the parameters from a block signature,
        splitting the information about class, id, language and
        style. The positioning (indentation and alignment) is parsed
        and stored in the style.

        A paragraph like:

            p>(class#id){color:red}[en]. Paragraph.

        or:
            
            p{color:red}[en](class#id)>. Paragraph.

        will have its parameters parsed to:

            output = {'lang' : 'en',
                      'class': 'class',
                      'id'   : 'id',
                      'style': 'color:red;text-align:right;'}

        Note that order is not important.
        R-   s(   \((?P<class>[\w]+(\s[\w]+)*)(\#[\w]+)?\)R   s"   \([\w]*(\s[\w]+)*\#(?P<id>[\w]+)\)R   s   \[(?P<lang>[\w-]+)\]R,   s   {(?P<style>[^\}]+)}s   
R8   t   ;s   \([\#\w\s]+\)s
   \[[\w-]+\]s   {[\w:;#%-]+}t   (s   padding-left:%dem;t   )s   padding-right:%dem;t   imageR0  s   float:left;s    leftR   s   float:right;s    rightt   ^s   vertical-align:text-top;s    topt   -s   vertical-align:middle;s    middlet   ~s   vertical-align:text-bottom;s    bottomR   t   leftt   rightt   =R   s   <>t   justifyt   topt   bottomR)   R   s   \\(\d+)i    R   s   /(\d+)R   s   text-align:justify;s    justifys   text-align:center;s    centers   text-align:left;s   text-align:right;(   R0  s   float:left;s    left(   R   s   float:right;s    right(   RA  s   vertical-align:text-top;s    top(   RB  s   vertical-align:middle;s    middle(   RC  s   vertical-align:text-bottom;s    bottom(   R0  s   left(   R   RE  (   RF  s   center(   s   <>RG  (   RA  s   top(   RC  RI  (   s   <>s   text-align:justify;s    justify(   RF  s   text-align:center;s    center(   R0  s   float:left;s    left(   R   s   float:right;s    right(   s   <>s   text-align:justify;s    justify(   RF  s   text-align:center;s    center(   R0  s   text-align:left;s    left(   R   s   text-align:right;s    right(   R@   RE   R4  R   t   endswithR7  R   R   RG   Ra   R9   RH   R8  R   (   R]   t
   parametersR   t
   align_typeR|   Rb   R-   t   l_indentt   r_indentR)   R   t
   alignmentst   _alignt   _stylet   _class(    (    sb   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/textile.pyt   parse_params  s         		  		  "	 	#i    c         C   s   d | g } xI | i    D]; \ } } | d j p | o | i d | | f  q q W| o | i d  n | i d  d i |  S(   s   Build the open tag with specified attributes.

        This function is used by all block builders to 
        generate the opening tags with the attributes of
        the block.
        s   <%sR   s    %s="%s"s    /R   R8   (   t   itemsRG   RH   (   R]   R   t
   attributest   singlet   open_tagRj   Rk   (    (    sb   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/textile.pyt   build_open_tag  s      c   
      C   s   t  i d |  } | p |  i | |  } g  } x | D] } | o | i   } |  i d |  } d }	 | i d  o | d =n t d d |  } t d d |  } |  i |  } | i | | |	  q8 q8 Wd	 i	 |  S(
   sJ  Process a paragraph.

        This function processes the paragraphs, enclosing the text in a 
        <p> tag and breaking lines with <br />. Paragraphs are formatted
        with all the inline rules.

        ---
        h1. Paragraph
        
        This is how you write a paragraph:

        pre. p. This is a paragraph, although a short one.
        
        Since the paragraph is the default block, you can safely omit its
        signature ([@p@]). Simply write:

        pre. This is a paragraph, although a short one.

        Text in a paragraph block is wrapped in @<p></p>@ tags, and
        newlines receive a <br /> tag. In both cases Textile will process
        the text to:

        pre. <p>This is a paragraph, although a short one.</p>

        Text in a paragraph block is processed with all the inline rules.
        s   
{2,}RD   s   </p>R   s   (<br />|\n)+s   <br />
s   (<[^>]*)<br />\n(.*?>)s   \1 \2s   

(
   R@   R   RS  R   RX  R8  R   t   inlineRG   RH   (
   R]   R   RK  RU  R   RI   R|   RJ   RW  t	   close_tag(    (    sb   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/textile.pyR    s       c         C   sf   | i    } |  i | |  } |  i d |  } d } | i d d  } | i d d  } | | | S(   sI  Process pre-formatted text.

        This function processes pre-formatted text into a <pre> tag.
        No HTML is added for the lines, but @<@ and @>@ are translated into
        HTML entities.

        ---
        h1. Pre-formatted text

        Pre-formatted text can be specified using the @pre@ signature.
        Inside a "pre" block, whitespace is preserved and @<@ and @>@ are
        translated into HTML(HyperText Markup Language) entities
        automatically.

        Text in a "pre" block is __not processed__ with any inline rule.

        Here's a simple example:

        pre. pre. This text is pre-formatted.
        Nothing interesting happens inside here...
        
        Will become:

        pre. <pre>
        This text is pre-formatted.
        Nothing interesting happens inside here...
        </pre>
        R
   s   
</pre>R0  s   &lt;R   s   &gt;(   t   rstripRS  RX  R   (   R]   R   RK  R   RU  RW  RZ  (    (    sb   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/textile.pyR
     s    c         C   s   |  i  | |  } | i d  o | d } | d =n d } d |  i d |  d } d } t o | d j o t |  } n% | i d d  } | i d	 d
  } | | | S(   s  Process block code.

        This function processes block code into a <code> tag inside a
        <pre>. No HTML is added for the lines, but @<@ and @>@ are translated
        into HTML entities.

        ---
        h1. Block code

        A block code, specified by the @bc@ signature, is a block of
        pre-formatted text which also receives a @<code></code>@ tag. As
        with "pre", whitespace is preserved and @<@ and @>@ are translated
        into HTML(HyperText Markup Language) entities automatically.

        Text in a "bc" code is _not processed_ with the inline rules.
        
        If you have "Twisted":http://www.twistedmatrix.com/ installed,
        Textile can automatically colorize your Python code if you
        specify its language as "Python":
        
        pre. bc[python]. from twisted.python import htmlizer

        This will become:

        pre. <pre>
        <code lang="python">
        <span class="py-src-keyword">from</span> <span class="py-src-variable">twisted</span><span class="py-src-op">.</span><span class="py-src-variable">python</span> <span class="py-src-keyword">import</span> <span class="py-src-variable">htmlizer</span>
        </code>
        </pre>

        The colors can be specified in your CSS(Cascading Style Sheets)
        file. If you don't want to install Twisted, you can download just
        the @htmlizer@ module "independently":http://dealmeida.net/code/htmlizer.py.txt.
        R,   s   <pre>
R   s   
s   
</code>
</pre>R
  R0  s   &lt;R   s   &gt;N(   RS  R8  R3  RX  R   R   R   (   R]   R   RK  R   RU  R,   RW  RZ  (    (    sb   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/textile.pyR    s    %
c         C   s   |  i  | |  } |  i d |  d } d } | i d  } g  } xi | D]a }	 |	 i d  o |	 i d d  \ }
 } n |	 d }
 } |
 o | i d |
 | f  qJ qJ Wd i |  } |  i |  } | | | S(   s  Process definition list.

        This function process definition lists. The text inside
        the <dt> and <dd> tags is processed for inline formatting.

        ---
        h1. Definition list

        A definition list starts with the signature @dl@, and has
        its items separated by a @:@. Here's a simple example:

        pre. dl. name:Sir Lancelot of Camelot.
        quest:To seek the Holy Grail.
        color:Blue.

        Becomes:

        pre. <dl>
        <dt>name</dt>
        <dd>Sir Lancelot of Camelot.</dd>
        <dt>quest</dt>
        <dd>To seek the Holy Grail.</dd>
        <dt>color</dt>
        <dd>Blue.</dd>
        </dl>
        R   s   
s   
</dl>t   :i   R8   s   <dt>%s</dt>
<dd>%s</dd>(   RS  RX  R   R   RG   RH   RY  (   R]   R   RK  R   RU  RW  RZ  RI   R|   RJ   R   R   (    (    sb   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/textile.pyR   U  s      c         C   s   |  i  | |  } | o | i d  } | | d <nK | i d  } | d i d  o | i   d | d <n d i |  } |  i d |  d } d } |  i |  } | | | S(	   s  Process block quote.

        The block quote is inserted into a <blockquote> tag, and
        processed as a paragraph. An optional cite attribute can
        be appended on the last line after two dashes (--), or
        after the period following ':' for compatibility with the
        Perl version.

        ---
        h1. Blockquote

        A blockquote is denoted by the signature @bq@. The text in this
        block will be enclosed in @<blockquote></blockquote>@ and @<p></p>@,
        receiving the same formatting as a paragraph. For example:

        pre. bq. This is a blockquote.

        Becomes:

        pre. <blockquote>
        <p>This is a blockquote.</p>
        </blockquote>

        You can optionally specify the @cite@ attribute of the blockquote,
        using the following syntax:

        pre. bq.:http://example.com Some text.

        pre. bq.:"John Doe" Some other text.

        Becomes:

        pre. <blockquote cite="http://example.com">
        <p>Some text.</p>
        </blockquote>

        pre. <blockquote cite="John Doe">
        <p>Some other text.</p>
        </blockquote>

        You can also specify the @cite@ using a pair of dashes on the
        last line of the blockquote:

        pre. bq. Some text.
        -- http://example.com
        t   "R   s   
is   -- i   R   s   
</blockquote>(   RS  R   R   t
   startswitht   popRH   RX  R  (   R]   R   RK  R   R   RU  RW  RZ  (    (    sb   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/textile.pyR     s    1i   c   	      C   sq   |  i  | |  } | } t | d  } t | d  } |  i d | |  } d | } |  i |  } | | | S(   s  Process a header.

        The header number is captured by the regular 
        expression and lives in header. If head_offset is
        set, it is adjusted accordingly.

        ---
        h1. Header

        A header is produced by the signature @hn@, where @n@ goes
        from 1 to 6. You can adjust the relative output of the headers
        passing a @head_offset@ attribute when calling @textile()@.

        To make a header:

        pre. h1. This is a header.

        Becomes:

        pre. <h1>This is a header.</h1>
        i   i   s   h%ds   </h%d>(   RS  t   mint   maxRX  RY  (	   R]   R   RK  R  R   RU  t   nRW  RZ  (    (    sb   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/textile.pyR    s    
c         C   sZ   t  |  } |  i | |  } d | d <d | | d <d | | } |  i d | d |  S(   s-  Process a footnote.

        A footnote is formatted as a paragraph of class
        'footnote' and id 'fn%d', starting with the footnote
        number in a <sup> tag. Here we just build the
        attributes and pass them directly to self.paragraph().

        ---
        h1. Footnote

        A footnote is produced by the signature @fn@ followed by
        a number. Footnotes are paragraphs of a special CSS(Cascading Style Sheets)
        class. An example:

        pre. fn1. This is footnote number one.

        Will produce this:

        pre. <p class="footnote" id="fn1"><sup>1</sup> This is footnote number one.</p>

        This footnote can be referenced anywhere on the text by the
        following way:

        pre. This is a reference[1] to footnote number one.

        Which becomes:

        pre. <p>This is a reference<sup class="footnote"><a href="#fn1" title="This is footnote number one.">1</a></sup> to footnote number 1.</p>

        Note that the text from the footnote appears in the @title@ of the
        link pointing to it.
        R  R   s   fn%dR   s   <sup>%d</sup> R   RU  (   Ra   RS  R  (   R]   R   RK  R  R   Rb  RU  (    (    sb   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/textile.pyR    s    "
c         C   s  g  } xt  |  o| i d  } | i   } | i d d  } t i d |  i t i  } | i |  } | o/ | i	 d  } | d } | i
 d |  } n d } | p |  i |  } |  i d |  }	 h  } d }
 t  |  og  } | i d  } t i d	 |  i t i  } | i |  } | o/ | i	 d  } | d
 } | i
 d |  } n d } | i d  o | } | i |  xS t  |  oE | i d  } | i d  o | i |  q| i d |  PqW|  i d i |  d
 | } | d | d } q| i d  o | } | i |  xS t  |  oE | i d  } | i d  o | i |  q:| i d |  Pq:W|  i d i |  d
 | } | d | d } q| i d |  n |  i |  } |	 | |
 } | i |  q	 Wd i |  S(   s'  Build the list item.

        This function build the list item of an (un)ordered list. It
        works by peeking at the next list item, and searching for a
        multi-list. If a multi-list is found, it is processed and 
        appended inside the list item tags, as it should be.
        i    s   
s   <br />
s   ^%(liattr)s\sR8   t   liparametersR   s   </li>s   ^%(olattr)st   olparameterst   #t   *(   t   lenR_  t   lstripR   R@   RA   R  R  RF   R6  RB   RS  RX  R^  RG   t   insertR   RH   R   RY  (   R]   RT  t   liattributesRI   t   itemRD   Rb   t   cRc  t   open_tag_lit   close_tag_lit   inlistt   n_itemRd  t   tmp(    (    sb   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/textile.pyt   build_li+  sp     

  c   
      C   s   |  i  | |  } |  i  |  } | i d  o | d } n | i d  } |  i d |  d } d }	 |  i | |  } | | |	 S(   s$  Build an ordered list.

        This function basically just sets the <ol></ol> with the
        right attributes, and then pass everything inside to 
        _build_li, which does the real tough recursive job.

        ---
        h1. Ordered lists

        Ordered lists can be constructed this way:

        pre. # Item number 1.
        # Item number 2.
        # Item number 3.

        And you get:

        pre. <ol>
        <li>Item number 1.</li>
        <li>Item number 2.</li>
        <li>Item number 3.</li>
        </ol>

        If you want a list to "break" an extended block, you should
        add a period after the hash. This is useful for writing 
        Python code:

        pre.. bc[python].. #!/usr/bin/env python

        # This is a comment, not an ordered list!
        # So this won't break the extended "bc".

        p. Lists can be nested:

        pre. # Item number 1.
        ## Item number 1a.
        ## Item number 1b.
        # Item number 2.
        ## Item number 2a.

        Textile will transform this to:

        pre. <ol>
        <li>Item number 1.
        <ol>
        <li>Item number 1a.</li>
        <li>Item number 1b.</li>
        </ol>
        </li>
        <li>Item number 2.
        <ol>
        <li>Item number 2a.</li>
        </ol>
        </li>
        </ol>

        You can also mix ordered and unordered lists:

        pre. `*` To write well you need:
        `*`# to read every day
        `*`# to write every day
        `*`# and X

        You'll get this:

        pre. <ul>
        <li>To write well you need:
        <ol>
        <li>to read every day</li>
        <li>to write every day</li>
        <li>and X</li>
        </ol>
        </li>
        </ul>

        To style a list, the parameters should go before the hash if you want
        to set the attributes on the @<ol>@ tag:

        pre. (class#id)# one
        # two
        # three

        If you want to customize the firsr @<li>@ tag, apply the parameters
        after the hash:

        pre. #(class#id) one
        # two
        # three
        Re  i   s   
#R   s   
s   
</ol>(   RS  R^  R   RX  Rr  (
   R]   R   Rc  Rd  R   t   olattributesRj  RT  RW  RZ  (    (    sb   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/textile.pyR     s    [c   
      C   s   |  i  | |  } |  i  |  } | i d  o | d } n | i d  } |  i d |  d } d }	 |  i | |  } | | |	 S(   s0  Build an unordered list.

        This function basically just sets the <ul></ul> with the
        right attributes, and then pass everything inside to 
        _build_li, which does the real tough recursive job.

        ---
        h1. Unordered lists

        Unordered lists behave exactly like the ordered lists, and are
        defined using a star:

        pre. * Python
        * Perl
        * PHP

        Becomes:

        pre. <ul>
        <li>Python</li>
        <li>Perl</li>
        <li><span class="caps">PHP</span></li>
        </ul>
        Rf  i   s   
*R   s   
s   
</ul>(   RS  R^  R   RX  Rr  (
   R]   R   Rc  Rd  R   Rs  Rj  RT  RW  RZ  (    (    sb   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/textile.pyR      s    c      
   C   s_  |  i  | | d d } |  i d |  d } d } g  } h  } t i d |  }	 x|	 D]}
 |
 i d  } | i d  } |  i  | d d } |  i d |  d } | i |  | i d	  o
 d
 } n d } d } xU| d  D]I} t i d |  i t i	  } | i
 |  } | o| i d  } |  i  | d d d } | i d d  } | d i d	  o
 d
 } n | d
 j o8 xW t | | |  D] } | i d d  | | <qWn# | i d | i | d   | d <|  i | |  } d | } | i | |  i | d i    |  n | | 7} q W| i d  qY W| d i |  | } | S(   sy	  Build a table.

        To build a table we split the text in lines to get the
        rows, and split the rows between '|' to get the individual
        cells.

        ---
        h1. Tables

        Making a simple table is as easy as possible:

        pre. |a|b|c|
        |1|2|3|

        Will be processed into:

        pre. <table>
        <tr>
        <td>a</td>
        <td>b</td>
        <td>c</td>
        </tr>
        <tr>
        <td>1</td>
        <td>2</td>
        <td>3</td>
        </tr>
        </table>

        If you want to customize the @<table>@ tag, you must use the
        @table@ signature:

        pre. table(class#id)[en]. |a|b|c|
        |1|2|3|

        To customize a row, apply the modifier _before_ the first @|@:

        pre. table. (class)<>|a|b|c|
        |1|2|3|

        Individual cells can by customized by adding the parameters _after_
        the @|@, proceded by a period and a space:

        pre. |(#id). a|b|c|
        |1|2|3|

        The allowed modifiers are:

        dl. {style rule}:A CSS(Cascading Style Sheets) style rule. 
        (class) or (#id) or (class#id):A CSS(Cascading Style Sheets) class and/or id attribute. 
        ( (one or more):Adds 1em of padding to the left for each '(' character. 
        ) (one or more):Adds 1em of padding to the right for each ')' character. 
        &lt;:Aligns to the left (floats to left for tables if combined with the ')' modifier). 
        &gt;:Aligns to the right (floats to right for tables if combined with the '(' modifier). 
        =:Aligns to center (sets left, right margins to 'auto' for tables). 
        &lt;&gt;:For cells only. Justifies text. 
        ^:For rows and cells only. Aligns to the top. 
        ~ (tilde):For rows and cells only. Aligns to the bottom. 
        _ (underscore):Can be applied to a table row or cell to indicate a header row or cell. 
        \2 or \3 or \4, etc.:Used within cells to indicate a colspan of 2, 3, 4, etc. columns. When you see "\", think "push forward". 
        /2 or /3 or /4, etc.:Used within cells to indicate a rowspan of 2, 3, 4, etc. rows. When you see "/", think "push downward". 
        
        When a cell is identified as a header cell and an alignment is
        specified, that becomes the default alignment for cells below it.
        You can always override this behavior by specifying an alignment
        for one of the lower cells.
        RL  R   s   
s   </table>s   \n+t   |i    R   t   _R   R   is   (?:%(tattr)s\.\s)?(?P<text>.*)R8   RK  R   i   R)   s   </%s>
R   s   </tr>
N(   RS  RX  R@   R   R_  RG   R   RA   R  R  RF   R6  R7  t   rangeR3  RY  R   RH   (   R]   R   RK  R   RU  RW  RZ  R|   t   default_alignR   t   rowt   columnst   rowattrt   open_trt   td_tagRQ   t   cellRD   Rb   Rl  t   cellattrR   R   t   open_tdt   close_td(    (    sb   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/textile.pyR   .  sN    D 
 
 "
,c         C   s   | S(   s	  Do nothing.

        This is used to match escaped text. Nothing to see here!

        ---
        h1. Escaping

        If you don't want Textile processing a block, you can simply
        enclose it inside @==@:

        pre. p. Regular paragraph

        pre. ==
        Escaped portion -- will not be formatted
        by Textile at all
        ==

        pre. p. Back to normal.

        This can also be used inline, disabling the formatting temporarily:

        pre. p. This is ==*a test*== of escaping.
        (    (   R]   R   (    (    sb   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/textile.pyR    s    c         C   s<   t  o1 y# t i d | t  f  i   } Wq8 q8 Xn | S(   sq  Convert itex to MathML.

        If the itex2mml binary is set, we use it to convert the
        itex to MathML. Otherwise, the text is unprocessed and 
        return as is.

        ---
        h1. itex

        Textile can automatically convert itex code to MathML(Mathematical Markup Language)
        for you, if you have the itex2MML binary (you can download it
        from the "Movable Type plugin":http://golem.ph.utexas.edu/~distler/blog/files/itexToMML.tar.gz).

        Block equations should be enclosed inbetween @\[@ and @\]@:

        pre. \[ e^{i\pi} + 1 = 0 \]

        Will be translated to:

        pre. <math xmlns='http://www.w3.org/1998/Math/MathML' mode='display'>
        <msup><mi>e</mi> <mrow><mi>i</mi>
        <mi>&amp;pi;</mi></mrow></msup>
        <mo>+</mo><mn>1</mn><mo>=</mo><mn>0</mn>
        </math>

        Equations can also be displayed inline:

        pre. Euler's formula, $e^{i\pi}+1=0$, ...

        (Note that if you want to display MathML(Mathematical Markup Language)
        your content must be served as @application/xhtml+xml@, which is not
        accepted by all browsers.)
        s   echo '%s' | %s(   t   itex2mmlt   ost   popent   read(   R]   R   (    (    sb   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/textile.pyR    s    "#c   	      C   s  g  } | i  t d d |  i  | i  t t i d d  d d |  i  |  i d f |  i d f |  i d f |  i d f |  i	 d f |  i
 d f |  i d f |  i d f |  i d f |  i d f |  i d f |  i d f |  i d f |  i d f |  i d f |  i d f |  i d f |  i d f |  i d f |  i d f |  i d f g } x | D] \ } } | i i d d  d } | i d  } g  } x' | D] } | i   } | i  |  qWd i |  } | i  t | d |  i |  qWWd i |  } | i d d  } | S(	   s   Show PyTextile's functionalities.

        An introduction to PyTextile. Can be called when running the
        main script or if you write the following line:

            'tell me about textile.'

        But keep it a secret!
        s   h1. This is TextileR!  s   ---i   i   s   
s   <br />R8   (   RG   t   textileR!  t   __doc__R   R"  R  R
   R  R   R   R  R  R  R  R   R   R   RY  t   qtagst   glyphst   macrosR   t   imagesR  R  R   RH   R   (	   R]   R   R  t	   functionsR,  t   offsett   docRI   RJ   (    (    sb   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/textile.pyR    sL    ,  $c         C   s   d } x t  i | |  D] \ } } d i t  i d |   } d i t  i d |   } | o7 | | j o* | i d | | f d | | f  } q q Wt d d |  } | S(   sj  Process acronyms.

        Acronyms can have letters in upper and lower caps, or even numbers,
        provided that the numbers and upper caps are the same in the
        abbreviation and in the description. For example:

            XHTML(eXtensible HyperText Markup Language)
            OPeNDAP(Open source Project for a Network Data Access Protocol)
            L94(Levitus 94)

        are all valid acronyms.

        ---
        h1. Acronyms

        You can define acronyms in your text the following way:

        pre. This is XHTML(eXtensible HyperText Markup Language).

        The resulting code is:

        pre. <p><acronym title="eXtensible HyperText Markup Language"><span class="caps">XHTML</span></acronym></p>

        Acronyms can have letters in upper and lower caps, or even numbers,
        provided that the numbers and upper caps are the same in the
        abbreviation and in the description. For example:

        pre. XHTML(eXtensible HyperText Markup Language)
        OPeNDAP(Open source Project for a Network Data Access Protocol)
        L94(Levitus 94)

        are all valid acronyms.
        s/   (?P<acronym>[\w]+)\((?P<definition>[^\(\)]+?)\)R8   s   [A-Z\d]+s   %s(%s)s    <acronym title="%s">%s</acronym>s   (^|\s)([A-Z]{3,})\b(?!\()s   \1<span class="caps">\2</span>(   R@   R  RH   R   RK   (   R]   R   t   acronymsR   t
   definitiont   caps_acronymt   caps_definition(    (    sb   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/textile.pyR   4  s    # .c         C   s   t  i d  } xp | i |  D]_ } | i d  } | i d  i   } t  i d d |  } | i d | d | | f  } q W| S(   s   Add titles to footnotes references.

        This function searches for footnotes references like this [1], and 
        adds a title to the link containing the first paragraph of the
        footnote.
        sG   <p class="footnote" id="fn(?P<n>\d+)"><sup>(?P=n)</sup>(?P<note>.*)</p>Rb  t   notes   <.*?>R8   s   <a href="#fn%s">s   <a href="#fn%s" title="%s">(   R@   RA   t   finditerR4  R   RB   R   (   R]   R   RD   Rb   Rb  R  (    (    sb   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/textile.pyR$  e  s     $c         C   s  | i  d  } h  d d <d d <d d <d d <d d	 <d d
 <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d  <d d! <d" d# <d" d$ <d% d& <d% d' <d( d) <d( d* <d+ d, <d+ d- <d. d/ <d0 d1 <d0 d2 <d3 d4 <d3 d5 <d6 d7 <d6 d8 <d9 d: <d9 d; <d< d= <d< d> <d? d@ <d? dA <dB dC <dB dD <dE dF <dE dG <dH dI <dH dJ <dK dL <dK dM <dN dO <dN dP <dQ dR <dQ dS <dT dU <dT dV <dW dX <dW dY <dZ d[ <dZ d\ <d] d^ <d] d_ <d` da <d` db <dc dd <dc de <df dg <df dh <di dj <di dk <dl dm <dl dn <do dp <do dq <dr ds <dr dt <du dv <du dw <dx dy <dx dz <d{ d| <d{ d} <d~ d <d~ d <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d <} y | | } Wna t j
 oU t o= y% t i |  } | i d d  } Wqd | } qXqd | } n X| S(   s  Quick macros.

        This function replaces macros inside brackets using a built-in
        dictionary, and also unicode names if the key doesn't exist.

        ---
        h1. Macros

        Textile has support for character macros, which should be enclosed
        in curly braces. A few useful ones are:

        pre. {C=} or {=C}: euro sign
        {+-} or {-+}: plus-minus sign
        {L-} or {-L}: pound sign.

        You can also make accented characters:

        pre. Expos{e'}

        Becomes:

        pre. <p>Expos&amp;#233;</p>

        You can also specify Unicode names like:

        pre. {umbrella}
        {white smiling face}
        i   s   &#162;s   c|s   |cs   &#163;s   L-s   -Ls   &#165;s   Y=s   =Ys   &#169;s   (c)s   &#171;s   <<s   &#174;s   (r)s   &#177;s   +_s   _+s   &#187;s   >>s   &#188;s   1/4s   &#189;s   1/2s   &#190;s   3/4s   &#192;s   A`s   `As   &#193;s   A's   'As   &#194;s   A^s   ^As   &#195;s   A~s   ~As   &#196;s   A"s   "As   &#197;t   Aot   oAs   &#198;t   AEs   &#199;s   C,s   ,Cs   &#200;s   E`s   `Es   &#201;s   E's   'Es   &#202;s   E^s   ^Es   &#203;s   E"s   "Es   &#204;s   I`s   `Is   &#205;s   I's   'Is   &#206;s   I^s   ^Is   &#207;s   I"s   "Is   &#208;s   D-s   -Ds   &#209;s   N~s   ~Ns   &#210;s   O`s   `Os   &#211;s   O's   'Os   &#212;s   O^s   ^Os   &#213;s   O~s   ~Os   &#214;s   O"s   "Os   &#216;s   O/s   /Os   &#217;s   U`s   `Us   &#218;s   U's   'Us   &#219;s   U^s   ^Us   &#220;s   U"s   "Us   &#221;s   Y's   'Ys   &#224;s   a`s   `as   &#225;s   a's   'as   &#226;s   a^s   ^as   &#227;s   a~s   ~as   &#228;s   a"s   "as   &#229;t   aot   oas   &#230;t   aes   &#231;s   c,s   ,cs   &#232;s   e`s   `es   &#233;s   e's   'es   &#234;s   e^s   ^es   &#235;s   e"s   "es   &#236;s   i`s   `is   &#237;s   i's   'is   &#238;s   i^s   ^is   &#239;s   i"s   "is   &#241;s   n~s   ~ns   &#242;s   o`s   `os   &#243;s   o's   'os   &#244;s   o^s   ^os   &#245;s   o~s   ~os   &#246;s   o"s   "os   &#247;s   :-s   -:s   &#248;s   o/s   /os   &#249;s   u`s   `us   &#250;s   u's   'us   &#251;s   u^s   ^us   &#252;s   u"s   "us   &#253;s   y's   'ys   &#255s   y"s   "ys   &#338;t   OEs   &#339;t   oes   &#8226;Rf  s   &#8355;t   Frs   &#8356;s   L=s   =Ls   &#8360;t   Rss   &#8364;s   C=s   =Cs   &#8482;t   tms   &#8592;s   <-s   &#8594;s   ->s   &#8656;s   <=s   &#8658;s   =>s   &#8800;s   =/s   /=s   &#8804;s   <_s   _<s   &#8805;s   >_s   _>s   &#9785;s   :(s   &#9786;s   :)s   &#9824;t   spades   &#9827;t   clubs   &#9829;t   hearts   &#9830;t   diamondR    R  s   {%s}(   R4  t   KeyErrort   unicodedatat   lookupR'  (   R]   Rb   t   entityR  (    (    sb   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/textile.pyR  {  sR   																																																																																																																																																											c   	      C   s  d+ d, d- d. d/ d0 d1 d2 d3 d4 d5 d6 d7 d8 d9 d: g } t  i d  |  i |  } t | t  o( | i d! d  } | i d" d  } n d# } d$ } t  i d% |  pu x& | D] \ } } t | | |  } q Wt  i t  i | t  i	  d& |  } t  i t  i | t  i	  d' |  } n g  } x t  i
 d( |  D] } t  i d) |  pu x& | D] \ } } t | | |  } qSWt  i t  i | t  i	  d& |  } t  i t  i | t  i	  d' |  } n | i |  q3Wd* i |  } | S(;   s  Glyph formatting.

        This function replaces quotations marks, dashes and a few other
        symbol for numerical entities. The em/en dashes use definitions
        comes from http://alistapart.com/articles/emen/.

        ---
        h1. Glyphs

        Textile replaces some of the characters in your text with their
        equivalent numerical entities. These include:

        * Replace single and double primes used as quotation marks with HTML(HyperText Markup Language) entities for opening and closing quotation marks in readable text, while leaving untouched the primes required within HTML(HyperText Markup Language) tags.
        * Replace double hyphens (==--==) with an em-dash (&#8212;) entity.
        * Replace triple hyphens (==---==) with two em-dash (&#8212;&#8212;) entities.
        * Replace single hyphens surrounded by spaces with an en-dash (&#8211;) entity.
        * Replace triplets of periods (==...==) with an ellipsis (&#8230;) entity.
        * Convert many nonstandard characters to browser-safe entities corresponding to keyboard input.
        * Convert ==(TM)==, ==(R)==, and  ==(C)== to &#8482;, &#174;, and &#169;.
        * Convert the letter x to a dimension sign: 2==x==4 to 2x4 and 8 ==x== 10 to 8x10.
        s
   "(?<!\w)\bs   &#8220;R]  s   &#8221;s   \b's   &#8217;s
   '(?<!\w)\bs   &#8216;t   's   (\b|^)( )?\.{3}s	   \1&#8230;s   \b---\bs   &#8212;&#8212;s   \s?--\s?s   &#8212;s   (\d+)-(\d+)s   \1&#8211;\2s
   (\d+)-(\W)s   \1&#8212;\2s   \s-\ss	    &#8211; s   (\d+) ?x ?(\d+)s
   \1&#215;\2s   \b ?(\((tm|TM)\))s   &#8482;s   \b ?(\([rR]\))s   &#174;s   \b ?(\([cC]\))s   &#169;s   ([^\s])\[(\d+)\]s4   \1<sup class="footnote"><a href="#fn\2">\2</a></sup>s	   {([^}]+)}s   ``s   s  (?=[a-zA-Z0-9./#])                          # Must start correctly
                  ((?:                                        # Match the leading part (proto://hostname, or just hostname)
                      (?:ftp|https?|telnet|nntp)              #     protocol
                      ://                                     #     ://
                      (?:                                     #     Optional 'username:password@'
                          \w+                                 #         username
                          (?::\w+)?                           #         optional :password
                          @                                   #         @
                      )?                                      # 
                      [-\w]+(?:\.\w[-\w]*)+                   #     hostname (sub.example.com)
                  )                                           #
                  (?::\d+)?                                   # Optional port number
                  (?:                                         # Rest of the URL, optional
                      /?                                      #     Start with '/'
                      [^.!,?;:"'<>()\[\]{}\s\x7F-\xFF]*       #     Can't start with these
                      (?:                                     #
                          [.!,?;:]+                           #     One or more of these
                          [^.!,?;:"'<>()\[\]{}\s\x7F-\xFF]+   #     Can't finish with these
                          #'"                                 #     # or ' or "
                      )*                                      #
                  )?)                                         #
               s   (?:mailto:)?            # Optional mailto:
                    ([-\+\w]+               # username
                    \@                      # at
                    [-\w]+(?:\.\w[-\w]*)+)  # hostname
                 s   <.*>s   <a href="\1">\1</a>s   <a href="mailto:\1">\1</a>s   (<.*?>)s   <.*?>R8   (   s
   "(?<!\w)\bs   &#8220;(   R]  s   &#8221;(   s   \b's   &#8217;(   s
   '(?<!\w)\bs   &#8216;(   R  s   &#8217;(   s   (\b|^)( )?\.{3}s	   \1&#8230;(   s   \b---\bs   &#8212;&#8212;(   s   \s?--\s?s   &#8212;(   s   (\d+)-(\d+)s   \1&#8211;\2(   s
   (\d+)-(\W)s   \1&#8212;\2(   s   \s-\ss	    &#8211; (   s   (\d+) ?x ?(\d+)s
   \1&#215;\2(   s   \b ?(\((tm|TM)\))s   &#8482;(   s   \b ?(\([rR]\))s   &#174;(   s   \b ?(\([cC]\))s   &#169;(   s   ([^\s])\[(\d+)\]s4   \1<sup class="footnote"><a href="#fn\2">\2</a></sup>(   R@   RB   R  R%  R!   R   RE   R   RA   R  R   RF   RG   RH   (	   R]   R   R  R/   t   emailt   glyph_searcht   glyph_replaceRI   RJ   (    (    sb   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/textile.pyR  L	  sR     	 $(  $(c            s  t  i d   f d   |  } d d h  d d <d d <f d	 d
 h  d d <d d <f d d h  d d <d d <f d d h  d d <d d <f d d h  d d <d d <f d d h  d d <d d <f d d h  d d <d d <f d d h  d d <d  d <f d! d" h  d# d <d$ d <f d% d& h  d' d <d( d <f d) d* h  d+ d <d) d <f d, d- h  d. d <d, d <f g } t  i d/ d0 |  } xg | D]_ \ }  }   i i |  t  i d1   i t  i  }    f d2   } | i | |  } qW| S(3   s  Quick tags formatting.

        This function does the inline formatting of text, like
        bold, italic, strong and also itex code.

        ---
        h1. Quick tags

        Quick tags allow you to format your text, making it bold, 
        emphasized or small, for example. The quick tags operators
        include:

        dl. ==*strong*==:Translates into @<strong>strong</strong>@.
        ==_emphasis_==:Translates into @<em>emphasis</em>@. 
        ==**bold**==:Translates into @<b>bold</b>@. 
        ==__italics__==:Translates into @<i>italics</i>@. 
        ==++bigger++==:Translates into @<big>bigger</big>@. 
        ==--smaller--==:Translates into: @<small>smaller</small>@. 
        ==-deleted text-==:Translates into @<del>deleted text</del>@. 
        ==+inserted text+==:Translates into @<ins>inserted text</ins>@. 
        ==^superscript^==:Translates into @<sup>superscript</sup>@. 
        ==~subscript~==:Translates into @<sub>subscript</sub>@. 
        ==%span%==:Translates into @<span>span</span>@. 
        ==@code@==:Translates into @<code>code</code>@. 
        
        Note that within a "==@==...==@==" section, @<@ and @>@ are
        translated into HTML entities automatically. 

        Inline formatting operators accept the following modifiers:

        dl. {style rule}:A CSS(Cascading Style Sheets) style rule. 
        [ll]:A language identifier (for a "lang" attribute). 
        (class) or (#id) or (class#id):For CSS(Cascading Style Sheets) class and id attributes. 
        s	   \$(.*?)\$c            s     i  |  i    S(    (   R  R4  (   Rb   (   R]   (    sb   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/textile.pyRc   	  s    s   **R   s   (?<!\*)\*\*(?!\*)t   qfs   \*t   clst   __R   s   (?<!_)__(?!_)Ru  s   ??R   s
   \?\?(?!\?)s   \?RB  R   s   (?<!\-)\-(?!\-)t   +R   s   (?<!\+)\+(?!\+)s   \+Rf  R   s   (?<!\*)\*(?!\*)R   s   (?<!_)_(?!_)s   ++R   s   (?<!\+)\+\+(?!\+)s   \+\+s   --R   s   (?<!\-)\-\-(?!\-)s   \-\-RC  RB   s   (?<!\~)\~(?!(\\/~))s   \~t   @R   s   (?<!@)@(?!@)t   %R   s   (?<!%)%(?!%)s#   (?<!\^)\^(?!\^)(.+?)(?<!\^)\^(?!\^)s   <sup>\1</sup>s  (?:                          #
                                   ^                        # Start of string
                                   |                        #
                                   (?<=[\s>'"])             # Whitespace, end of tag, quotes
                                   |                        #
                                   (?P<pre>[{[])            # Surrounded by [ or {
                                   |                        #
                                   (?<=%(punct)s)           # Punctuation
                               )                            #
                               %(qf)s                       # opening tag
                               %(qattr)s                    # attributes
                               (?P<text>[^%(cls)s\s].*?)    # text
                               (?<=\S)                      # non-whitespace
                               %(qf)s                       # 
                               (?:                          #
                                   $                        # End of string
                                   |                        #
                                   (?P<post>[\]}])          # Surrounded by ] or }
                                   |                        # 
                                   (?=%(punct)s{1,2}|\s)    # punctuation
                                )                           #
                             c            s   |  i  d  }   i | d  }   i  |  } d  }  d j o8 | d i d d  | d <| d i d d	  | d <n | | d | S(
   NR8   RK  s   </%s>R   R   R0  s   &lt;R   s   &gt;(   R6  RS  RX  R   (   Rb   Rl  RU  RW  RZ  (   R]   t   htmltag(    sb   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/textile.pyt   _replace
  s    
(   R@   RB   R  t   updateRA   R  (   R]   R   R  t   qtagt   redictRD   R  (    (   R]   R  sb   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/textile.pyR  	  s,    $$ c         C   s  t  i d |  i t  i  } x | i |  D] } | i d  } |  i | d d d } | i |  | d o | d | d <n | i   d p | i   d	 p | i   d
 | d <| i   d p | i   d p | i   d | d <|  i	 |  } | i
 | i   |  } q, W| S(   s  Process images.

        This function process images tags, with or without links. Images
        can have vertical and/or horizontal alignment, and can be resized
        unefficiently using width and height tags.

        ---
        h1. Images

        An image is generated by enclosing the image source in @!@:

        pre. !/path/to/image!

        You may optionally specify an alternative text for the image, which
        will also be used as its title:

        pre. !image.jpg (Nice picture)!

        Becomes:

        pre. <p><img src="image.jpg" alt="Nice picture" title="Nice picture" /></p>

        If you want to make the image point to a link, simply append a
        comma and the URL(Universal Republic of Love) to the image:

        pre. !image.jpg!:http://diveintopython.org

        Images can also be resized. These are all equivalent:

        pre. !image.jpg 10x20!
        !image.jpg 10w 20h!
        !image.jpg 20h 10w!

        The image @image.jpg@ will be resized to width 10 and height 20.

        Modifiers to the @<img>@ tag go after the opening @!@:

        pre. !(class#id)^image.jpg!

        Allowed modifiers include:
        
        dl. &lt;:Align the image to the left (causes the image to float if CSS options are enabled). 
        &gt;:Align the image to the right (causes the image to float if CSS options are enabled). 
        - (dash):Aligns the image to the middle. 
        ^:Aligns the image to the top. 
        ~ (tilde):Aligns the image to the bottom. 
        {style rule}:Applies a CSS style rule to the image. 
        (class) or (#id) or (class#id):Applies a CSS class and/or id to the image. 
        ( (one or more):Pads 1em on the left for each '(' character. 
        ) (one or more):Pads 1em on the right for each ')' character. 

        Images receive the class "top" when using top alignment, "bottom" 
        for bottom alignment and "middle" for middle alignment.
        s  \!               # Opening !
                           %(iattr)s        # Image attributes
                           (?P<src>%(url)s) # Image src
                           \s?              # Optional whitesapce
                           (                #
                               \(           #
                               (?P<alt>.*?) # Optional (alt) attribute
                               \)           #
                           )?               #
                           \s?              # Optional whitespace
                           %(resize)s       # Resize parameters
                           \!               # Closing !
                           (                # Optional link
                               :            #    starts with ':'
                               (?P<link>    #    
                               %(url)s      #    link HREF
                               )            #
                           )?               #
                        R8   RK  RL  R@  R   R   i   i   i
   R   i   i   i	   R   (   R@   RA   R  R  R  R6  RS  R  R9   R@  R   R4  (   R]   R   RD   Rb   Rl  RU  R   (    (    sb   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/textile.pyR  
  s    8 66c         C   sa   | d } | d =| d =|  i  d | d d } | o& t d d |  } d | | f } n | S(	   s"  Process each image.

        This method builds the <img> tag for each image in the text. It's
        separated from the 'images' method so it can be easily overriden when
        subclassing Textiler. Useful if you want to download and/or process
        the images, for example.
        RW   RK  RT   RV  i   s   &(?!(#|amp))s   &amp;s   <a href="%s">%s</a>(   RX  R   (   R]   RU  RW   R   R   (    (    sb   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/textile.pyR@  
  s    
c         C   s  d |  i  d |  i  g } xv| D]n} t i | t i  } xP| i |  D]?} | i d  } |  i | d  } | d i d d  | d <|  i i	 | d d  p | d } | i d	 d
  }	 |	 d }
 t |	  d j o |	 d
 } n | d } | i d d  } |  i i |
  o |  i |
 | } n t d d |  | d <|  i d |  } d } | | d | } | i | i   |  } qL Wq! W| S(   sL  Process links.

        This function is responsible for processing links. It has
        some nice shortcuts to Google, Amazon and IMDB queries.

        ---
        h1. Links

        A links is done the following way:

        pre. "This is the text link":http://example.com

        The result from this markup is:

        pre. <p><a href="http://example.com">This is the text link</a></p>

        You can add an optional @title@ attribute:

        pre. "This is the text link(This is the title)":http://example.com

        The link can be customised as well:

        pre. "(nospam)E-mail me please":mailto:someone@example.com

        You can use either single or double quotes. They must be enclosed in
        whitespace, punctuation or brackets:

        pre. You["gotta":http://example.com]seethis!

        If you are going to reference the same link a couple of times, you
        can define a lookup list anywhere on your document:

        pre. [python]http://www.python.org

        Links to the Python website can then be defined the following way:

        pre. "Check this":python

        There are also shortcuts for Amazon, IMDB(Internet Movie DataBase) and
        Google queries:

        pre. "Has anyone seen this guy?":imdb:Stephen+Fry
        "Really nice book":amazon:Goedel+Escher+Bach
        "PyBlosxom":google
        ["Using Textile and Blosxom with Python":google:python blosxom textile]

        Becomes:

        pre. <a href="http://www.imdb.com/Find?for=Stephen+Fry">Has anyone seen this guy?</a>
        <a href="http://www.amazon.com/exec/obidos/external-search?index=blended&amp;keyword=Goedel+Escher+Bach">Really nice book</a>
        <a href="http://www.google.com/search?q=PyBlosxom">PyBlosxom</a>
        <a href="http://www.google.com/search?q=python+blosxom+textile">Using Textile and Blosxom with Python</a>
        s  \[                           # [
                       (?P<quote>"|')               # Opening quotes
                       %(lattr)s                    # Link attributes
                       (?P<text>[^"]+?)             # Link text
                       \s?                          # Optional whitespace
                       (?:\((?P<title>[^\)]+?)\))?  # Optional (title)
                       (?P=quote)                   # Closing quotes
                       :                            # :
                       (?P<href>[^\]]+)             # HREF
                       \]                           # ]
                    s  (?P<quote>"|')               # Opening quotes
                       %(lattr)s                    # Link attributes
                       (?P<text>[^"]+?)             # Link text
                       \s?                          # Optional whitespace
                       (?:\((?P<title>[^\)]+?)\))?  # Optional (title)
                       (?P=quote)                   # Closing quotes
                       :                            # :
                       (?P<href>%(url)s)            # HREF
                    R8   RK  R   R]  s   &quot;R   R\  i   i    i   R   t    R  s   &(?!(#|amp))s   &amp;R   s   </a>N(   R  R@   RA   R  R  R6  RS  R   R   R7  R3  R   Rg  R  R8  R   RX  R4  (   R]   R   t   linkrest   linkreRD   Rb   Rl  RU  RW   t   partst   protot   queryRW  RZ  t   repl(    (    sb   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/textile.pyR  
  s2    @
	  $

 c         C   sO   |  i  |  } |  i |  } |  i |  } |  i |  } |  i |  } | S(   sy   Text formatting.

        This function basically defines the order on which the 
        formatting is applied.
        (   R  R  R  R   R  (   R]   R   (    (    sb   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/textile.pyt   format  s    c         C   s   t  i d |  p |  i |  } ns g  } xZ t  i d |  D]F } t  i d |  p |  i |  } n | d d !} | i |  q? Wd i |  } | S(   s   Inline formatting.

        This function calls the formatting on the inline text,
        taking care to avoid the escaped parts.

        ---
        h1. Inline 

        Inline formatting is applied within a block of text.
        s	   ==(.*?)==s	   (==.*?==)s   ==.*?==i   iR8   (   R@   RE   R  R   RF   RG   RH   (   R]   R   RI   RJ   (    (    sb   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/textile.pyRY    s     N()   R}   R~   R  R\   R  R  t   HEAD_OFFSETt   VALIDATEt   SANITIZEt   OUTPUTt   ENCODINGR.  R  R"  R3  RS  RX  R  R
   R  R   R   R  R  Rr  R   R   R   R  R  R  R   R$  R  R  R  R  R@  R  R  RY  (    (    (    sb   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/textile.pyR  ~  sB   		.		~<0=3L'0	fo.		+7	1			k	h	a		q	c         K   s   t  |   i |   S(   s   This is Textile.

    Generates XHTML from a simple markup developed by Dean Allen.

    This function should be called like this:
    
        textile(text, head_offset=0, validate=0, sanitize=0,
                encoding='latin-1', output='ASCII')
    (   R  R.  (   R   t   args(    (    sb   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/textile.pyR  4  s    
t   __main__s   tell me about textile.R!  (,   R  t   __authors__t   __version__t   __date__t   __copyright__t   __license__t   __history__R  R  R  R  R3  R  R  R#   R  R  R@   R$   R  RZ   R  t   ImportErrorR   R   R	   R   t   mx.TidyR   R   R)  R   R"   R(   RK  R  R   RK   R[   RL   R   R  R  R}   (    (    (    sb   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/textile.pys   <module>   s   	7		
	
		
			.		
			G=        	