*
2<c    
   sk    d  Z    d k Z  d k Z  d k l Z  d k l Z l Z l Z l Z  d k Z d k	 Z	  e i
 d  i d  Z  d d  Z  d d d	  Z  e i
 d
  i d  Z  d   Z  d   Z  d f  d     YZ e   Z d f  d     YZ Sd Z Td Z Ud Z Vd Z Xe	 i
 e e d f d e  e	 i
 e e d f d e  e	 i
 e e d f d e  e	 i
 e e d f d e  d  Z id e f d     YZ e	 i
 d  d f e	 i
 d   d! f e	 i
 d"  d# f e	 i
 d$  d% f f d&  Z d' d(  Z 	d)   Z 0e d* j o 0e   n d S(+   s  Structured Text Manipulation

Parse a structured text string into a form that can be used with 
structured formats, like html.

Structured text is text that uses indentation and simple
symbology to indicate the structure of a document.  

A structured string consists of a sequence of paragraphs separated by
one or more blank lines.  Each paragraph has a level which is defined
as the minimum indentation of the paragraph.  A paragraph is a
sub-paragraph of another paragraph if the other paragraph is the last
preceding paragraph that has a lower level.

Special symbology is used to indicate special constructs:

- A single-line paragraph whose immediately succeeding paragraphs are lower
  level is treated as a header.

- A paragraph that begins with a '-', '*', or 'o' is treated as an
  unordered list (bullet) element.

- A paragraph that begins with a sequence of digits followed by a
  white-space character is treated as an ordered list element.

- A paragraph that begins with a sequence of sequences, where each
  sequence is a sequence of digits or a sequence of letters followed
  by a period, is treated as an ordered list element.

- A paragraph with a first line that contains some text, followed by
  some white-space and '--' is treated as
  a descriptive list element. The leading text is treated as the
  element title.

- Sub-paragraphs of a paragraph that ends in the word 'example' or the
  word 'examples', or '::' is treated as example code and is output as is.

- Text enclosed single quotes (with white-space to the left of the
  first quote and whitespace or punctuation to the right of the second quote)
  is treated as example code.

- Text surrounded by '*' characters (with white-space to the left of the
  first '*' and whitespace or punctuation to the right of the second '*')
  is emphasized.

- Text surrounded by '**' characters (with white-space to the left of the
  first '**' and whitespace or punctuation to the right of the second '**')
  is made strong.

- Text surrounded by '_' underscore characters (with whitespace to the left 
  and whitespace or punctuation to the right) is made underlined.

- Text encloded by double quotes followed by a colon, a URL, and concluded
  by punctuation plus white space, *or* just white space, is treated as a
  hyper link. For example:

    "Zope":http://www.zope.org/ is ...

  Is interpreted as '<a href="http://www.zope.org/">Zope</a> is ....'
  Note: This works for relative as well as absolute URLs.

- Text enclosed by double quotes followed by a comma, one or more spaces,
  an absolute URL and concluded by punctuation plus white space, or just
  white space, is treated as a hyper link. For example: 

    "mail me", mailto:amos@digicool.com.

  Is interpreted as '<a href="mailto:amos@digicool.com">mail me</a>.' 

- Text enclosed in brackets which consists only of letters, digits,
  underscores and dashes is treated as hyper links within the document.
  For example:
    
    As demonstrated by Smith [12] this technique is quite effective.

  Is interpreted as '... by Smith <a href="#12">[12]</a> this ...'. Together
  with the next rule this allows easy coding of references or end notes.

- Text enclosed in brackets which is preceded by the start of a line, two
  periods and a space is treated as a named link. For example:

    .. [12] "Effective Techniques" Smith, Joe ... 

  Is interpreted as '<a name="12">[12]</a> "Effective Techniques" ...'.
  Together with the previous rule this allows easy coding of references or
  end notes. 


- A paragraph that has blocks of text enclosed in '||' is treated as a
  table. The text blocks correspond to table cells and table rows are
  denoted by newlines. By default the cells are center aligned. A cell
  can span more than one column by preceding a block of text with an
  equivalent number of cell separators '||'. Newlines and '|' cannot
  be a part of the cell text. For example:

      |||| **Ingredients** ||
      || *Name* || *Amount* ||
      ||Spam||10||
      ||Eggs||3||

  is interpreted as::

    <TABLE BORDER=1 CELLPADDING=2>
     <TR>
      <TD ALIGN=CENTER COLSPAN=2> <strong>Ingredients</strong> </TD>
     </TR>
     <TR>
      <TD ALIGN=CENTER COLSPAN=1> <em>Name</em> </TD>
      <TD ALIGN=CENTER COLSPAN=1> <em>Amount</em> </TD>
     </TR>
     <TR>
      <TD ALIGN=CENTER COLSPAN=1>Spam</TD>
      <TD ALIGN=CENTER COLSPAN=1>10</TD>
     </TR>
     <TR>
      <TD ALIGN=CENTER COLSPAN=1>Eggs</TD>
      <TD ALIGN=CENTER COLSPAN=1>3</TD>
     </TR>
    </TABLE>

N(   s   gsub(   s   splits   joins   strips   finds   \(
\|^\)\( *\)	c 	   s      d }  |  }  x  d o  | | d d f  }  | o}  | \ } }  t | d  }  t | d  }  | | |  }  d d | d d d | | | d | f } n  | | Sq Wd S(	   s,       Convert indentation tabs to spaces.
    s    i   i   i    s   
%s%ss    i   N(
   s   results   aStrings   rests
   indent_tabs
   ts_resultss   starts   grpss   lens   lnls   indent(	   s   aStrings
   indent_tabs   rests   lnls
   ts_resultss   results   indents   grpss   start(    (    sx   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_0/happydoclib/docstring/StructuredText/ClassicStructuredText.pys   untabify s   		 

7i   c    s      t  t |   d  }  | o  d Sn  | d o  | d =n  d t }  d | t | d |  f Sd S(   s*   Indent a string the given number of spacess   
s    i   s    s   %s%s
N(   s   splits   untabifys   aStrings   rs   levels   tabs   join(   s   aStrings   indents   tabs   r(    (    sx   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_0/happydoclib/docstring/StructuredText/ClassicStructuredText.pys   indent s     i    c    s     | o  t |   }  n  t |   d }  | | j o  |  Sn  g  }  | i }  | | j oH  d | | }  x- t	 |  d  d  r }  | | |  q WnA  | | }  x- t	 |  d  d  r }  | | |  q W t | d  Sd S(   s@   reindent a block of text, so that the minimum indent is as giveni    s    s   
N(   s   already_untabifieds   untabifys   aStrings   indent_levels   ls   indents   rs   appends   tabs   splits   ss   join(   s   aStrings   indents   already_untabifieds   appends   tabs   rs   ss   l(    (    sx   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_0/happydoclib/docstring/StructuredText/ClassicStructuredText.pys   reindent s$     	 	  	 s   
\( *\)c 	   s     d }  d |  }  t |  } }  x  d o  | | d d f |  }  | o  | \ } }  t | d  }  | | d }  | | j  o | | d j o=  | o  d |  f Sn  | | j  o  | } n n n  | |  f Sq5 Wd S(   sM       Find the minimum indentation for a string, not counting blank lines.
    i    s   
i   i   N(
   s   starts   aStrings   texts   lens   indents   ls   indent_spaces
   ts_resultss   grpss   i(	   s   aStrings   indent_spaces   ls   texts
   ts_resultss   indents   is   grpss   start(    (    sx   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_0/happydoclib/docstring/StructuredText/ClassicStructuredText.pys   indent_level s"   	 

!  c    s     t  |   }  |  | d }  | d }  x7  | | j  o |  | d | j o  | d } q6 W | d | Sd  S(   Ni    i   (   s   lens   lists   ls   starts   levels   i(   s   lists   starts   ls   is   level(    (    sx   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_0/happydoclib/docstring/StructuredText/ClassicStructuredText.pys
   paragraphs s    % c    s     |  o  g  Sn  d }  t |   }  g  }  xt  | | j  oc  t |  |  }  | d }  | i |  | d d t |  | | | ! f   | | } q@ W | Sd  S(   Ni    i   (	   s   lists   is   lens   ls   rs
   paragraphss   sublens   appends	   structure(   s   lists   ls   is   sublens   r(    (    sx   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_0/happydoclib/docstring/StructuredText/ClassicStructuredText.pys	   structure s    		 3s   Tablec      sD     d Z   d Z  d Z  e i d  d  Z 	d   Z RS(   Ns&     <TD ALIGN=CENTER COLSPAN=%i>%s</TD>
s    <TR>
%s </TR>
s*   
<TABLE BORDER=1 CELLPADDING=2>
%s</TABLE>s   [ \t\n]*\|\|([^|]*)c    s      g  |  _  t t t | d   }  x | d  r }  g  }  x  d o  | i
 |  } | o d Sn | i d  } | i | i d   | t |  j o Pn | | } qQ W|  i i |  q9 Wd Sd S(   sE   parses a table and returns nested list representing the
        tables   
i    i   N(   s   selfs   tables   filters   Nones   splits   aPars   texts   lines   rows   td_regs   matchs   mos   ends   poss   appends   groups   len(   s   selfs   aPars   td_regs   rows   lines   poss   texts   mo(    (    sx   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_0/happydoclib/docstring/StructuredText/ClassicStructuredText.pys   create s$    		 
  c    s   	
g  } x |  i d r } g  } d } x` | d rS } | d j o | d } qE n' | i |  i | | f  d } qE W| i |  i	 t
 | d   q W|  i t
 | d  Sd S(   s'   Creates an HTML representation of tablei    i   s    N(   s	   htmltables   selfs   tables   rows   htmlrows   colspans   cells   appends   CELLs   ROWs   joins   TABLE(   s   selfs   rows   htmlrows	   htmltables   colspans   cell(    (    sx   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_0/happydoclib/docstring/StructuredText/ClassicStructuredText.pys   html	s   	 			 	
$(   s   CELLs   ROWs   TABLEs   res   compiles   creates   html(    (    (    sx   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_0/happydoclib/docstring/StructuredText/ClassicStructuredText.pys   Table s
   			s   StructuredTextc      s5   d  Z  #%d e i d  d  Z Od   Z RS(   s   Model text as structured collection of paragraphs.

    Structure is implied by the indentation level.

    This class is intended as a base classes that do actual text
    output formatting.
    i    s   \(?
 *\)+?
c    s2  %.1d t  i d t  i d } 5t i | t i  } 7| i d |  } 9d t  i d t  i d } =t i | t i  } ?| i d |  } Bt	 | d  } C| d j o Dt i d d E|  } n G| |  _ Ht i t |  I|  } Jt t |  } Lt |  |  _ d	 S(
   s   Convert a structured text string into a structured text object.

        Aguments:

          aStructuredString -- The string to be parsed.
          level -- The level of top level headings to be created.
        s    "([%s0-9-_,./?=@~&]*)":s   ([-:%s0-9_,./?=@#~&]*?)s	   ([.:?;] )s   <a href="\2">\1</a>\3 s    "([%s0-9-_,./?=@~&]*)", s
   <a href=":i   s	   <a href="N(   s   strings   letterss   pats   res   compiles   Ms   p_regs   subs   aStructuredStrings   finds	   protolesss   levels   selfs   ts_regexs   splits   untabifys   paragraph_dividers
   paragraphss   maps   indent_levels	   structure(   s   selfs   aStructuredStrings   levels   paragraph_dividers	   protolesss
   paragraphss   p_regs   pat(    (    sx   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_0/happydoclib/docstring/StructuredText/ClassicStructuredText.pys   __init__%s    	c    s   OPt  |  i  Sd  S(   N(   s   strs   selfs	   structure(   s   self(    (    sx   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_0/happydoclib/docstring/StructuredText/ClassicStructuredText.pys   __str__Os   (   s   __doc__s   regexs   compiles   __init__s   __str__(    (    (    sx   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_0/happydoclib/docstring/StructuredText/ClassicStructuredText.pys   StructuredTexts   	*s   ([\x00- \\(]|^)s   ([\x00- ,.:;!?\\)]|$)s,   [%s]([^\x00- %s][^%s]*[^\x00- %s]|[^%s])[%s]s4   [%s][%s]([^\x00- %s][^%s]*[^\x00- %s]|[^%s])[%s][%s]s   *i   i   s   _s   'c    s   Xb|  t j o bd }  n c| i d |   }  d| i d |   }  e| i d |   }  f| i d |   }  g|  Sd  S(   Ns    s   \1<strong>\2</strong>\3s   \1<u>\2</u>\3s   \1<code>\2</code>\3s   \1<em>\2</em>\3(   s   ss   Nones   strongs   subs   unders   codes   em(   s   ss   ems   strongs   unders   code(    (    sx   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_0/happydoclib/docstring/StructuredText/ClassicStructuredText.pys   ctagXs   
 s   HTMLc      s  id  Z  moe i d  e i d  e i d  d  Z ~d   Z d   Z d   Z d   Z d	   Z d
 d  Z	 d   Z
 e i d  i e i d  i e i d  i e i d  i e i d e i  i e i d  i d  Z RS(   s+       An HTML structured text formatter.
    s
   </dl>
<dl>s
   </ul>
<ul>s
   </ol>
<ol>c    sk   owx|  i |  i |  i  } y| i d |  } z| i d |  } {| i d |  } || Sd S(   sS           Return an HTML string representation of the structured text data.

        s   
N(	   s   selfs   _strs	   structures   levels   ss   extra_dls   subs   extra_uls   extra_ol(   s   selfs   extra_dls   extra_uls   extra_ols   s(    (    sx   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_0/happydoclib/docstring/StructuredText/ClassicStructuredText.pys   __str__os   c    sB   ~| o d t t |   } n d | | | f Sd  S(   Ns	   <p>%s</p>s   %s<ul><li>%s
%s
</li></ul>
(   s   ps   strips   ctags   befores   after(   s   selfs   befores   ps   after(    (    sx   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_0/happydoclib/docstring/StructuredText/ClassicStructuredText.pys   ul~s   
 c    sB   | o d t t |   } n d | | | f Sd  S(   Ns	   <p>%s</p>s   %s<ol><li>%s
%s
</li></ol>
(   s   ps   strips   ctags   befores   after(   s   selfs   befores   ps   after(    (    sx   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_0/happydoclib/docstring/StructuredText/ClassicStructuredText.pys   ols   
 c    s*   d | t |  t |  | f Sd  S(   Ns-   %s<dl><dt>%s</dt><dd><p>%s</p>
%s
</dd></dl>
(   s   befores   ctags   ts   ds   after(   s   selfs   befores   ts   ds   after(    (    sx   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_0/happydoclib/docstring/StructuredText/ClassicStructuredText.pys   dls   c    s{   | d j o
 | d j  o* d | | t t |   | | f Sn d t t |   } d | | | f Sd  S(   Ni    i   s   %s<h%d>%s</h%d>
%s
s   <p><strong>%s</strong></p>s$   %s<dl><dt>%s
</dt><dd>%s
</dd></dl>
(   s   levels   befores   strips   ctags   ts   d(   s   selfs   befores   ts   levels   d(    (    sx   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_0/happydoclib/docstring/StructuredText/ClassicStructuredText.pys   heads   *c    s!   d | t |  | f Sd  S(   Ns   %s<p>%s</p>
%s
(   s   befores   ctags   ps   after(   s   selfs   befores   ps   after(    (    sx   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_0/happydoclib/docstring/StructuredText/ClassicStructuredText.pys   normals   i    c    s   | o d Sn | o d } n
 d } xC | d r6 } d | t | d  |  i | d d  f } qE W| o | d } n | Sd  S(   Ns    s   <PRE>
i    s   %s%s

%si   s   </PRE>
(   s	   structures   taggeds   rs   ss
   html_quotes   selfs   pre(   s   selfs	   structures   taggeds   rs   s(    (    sx   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_0/happydoclib/docstring/StructuredText/ClassicStructuredText.pys   pres    
	 	4 c    s!   d | t |  | f Sd  S(   Ns   %s<p>%s</p>
%s
(   s   befores   ctags   tables   after(   s   selfs   befores   tables   after(    (    sx   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_0/happydoclib/docstring/StructuredText/ClassicStructuredText.pys   tables   s   [ 	
]*[o*-][ 	
]+\([^ ]*\)s   [ - ]examples?:[ - ]*$s   \([^
]+\)[ 	]+--[ 	
]+\([^ ]*\)s   
s1   [ 	]*\(\([0-9]+\|[%s]+\)[.)]\)+[ 	
]+\([^ ]*\|$\)s   [ 	]*([0-9]+)[ 	
]+\([^ ]*\|$\)c	  
  sM  d } x0| d r#} | | d d f  }	 |	 o |	 d } | d d d j o | d o |  i | d  } n |  i	 | d |  } |  i | | |  } q n | | d d f  }	 |	 o |	 d } | d d d j o | d o |  i | d  } n |  i	 | d |  } |  i | | |  } q n | | d d f  }	 |	 o |	 d } | d d d j o | d o |  i | d  } n |  i	 | d |  } |  i | | |  } q n | | d d d f  }	 |	 oH |	 d \ }
 } |  i | |
 | |  i	 | d |   } q n | | d  d j o | d o3 |  i | | d |  i | d   } q n | d d d j o | d o8 |  i | | d d  |  i | d   } q n t i | d  o8 |  i | t i   |  i	 | d |   } q n | | d  d j  o | d o | d d d j oJ | d }
 |  i | |
 | |  i	 | d | o | d   } n- |  i | | d |  i	 | d |   } q W| Sd  S(   Ns    i    i   i   s   ::i   s   :(   s   rs	   structures   ss   bullets
   ts_resultss   ps   selfs   pres   pss   _strs   levels   uls   ols   olps   dls   ts   ds   examples   normals   tables   creates   htmls   nls   head(   s   selfs	   structures   levels   bullets   examples   dls   nls   ols   olps
   ts_resultss   ts   rs   ss   ps   ds   ps(    (    sx   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_0/happydoclib/docstring/StructuredText/ClassicStructuredText.pys   _strs^   	 	
$ 

$ 

$ 

+
%)
$.
.
;+0(   s   __doc__s   res   compiles   __str__s   uls   ols   dls   heads   normals   pres   tables   ts_regexs   match_groups   searchs   strings   letterss   _str(    (    (    sx   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_0/happydoclib/docstring/StructuredText/ClassicStructuredText.pys   HTMLis   	0	s   &s   &amp;s   <s   &lt;s   >s   &gt;s   "s   &quot;c    sQ   t  |   } x. | d r! \ } } | i | |  } q W| Sd  S(   Ni    (   s   strs   vs   texts   character_entitiess   res   names   sub(   s   vs   character_entitiess   texts   names   re(    (    sx   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_0/happydoclib/docstring/StructuredText/ClassicStructuredText.pys
   html_quotes
    i   c    s   t  i d t i d |   }  t  i d t i d |   }  t  i d d |   }  t |  d | Sd  S(   Ns   [\0\n]\.\. \[([0-9_%s-]+)\]s   \n  <a name="\1">[\1]</a>s/   ([\x00- ,])\[(?P<ref>[0-9_%s-]+)\]([\x00- ,.:])s   \1<a href="#\2">[\2]</a>\3s%   ([\0- ,])\[([^]]+)\.html\]([\0- ,.:])s   \1<a href="\2.html">[\2]</a>\3s   level(   s   res   subs   strings   letterss   texts   HTMLs   level(   s   texts   level(    (    sx   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_0/happydoclib/docstring/StructuredText/ClassicStructuredText.pys   html_with_referencess   c  	   s  	
d  k  } d  k } | i | i d d  \ }  } | o( | \ } t | d  i   } n | i	 i   } |  o>t
 d   |   o d GHn t
 d   |   o& d  k } | i | i d  n | d  d	 j o t i d
 d |  } n  t i d  i |  } !| t j	 o  "| t | i d   } n $t t |   } %| d  d j o0 &| d t | d  !} 'd | | f } n ,| GHn .t |  GHd  S(   Ni   s   twls   rc    s   |  d d j S(   Ni    s   -w(   s   o(   s   o(    (    sx   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_0/happydoclib/docstring/StructuredText/ClassicStructuredText.pys   <lambda>s    s   Content-Type: text/html
c    s   |  d d j S(   Ni    s   -l(   s   o(   s   o(    (    sx   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_0/happydoclib/docstring/StructuredText/ClassicStructuredText.pys   <lambda>s    s    i   s   #!s   ^#![^
]+s	   ([ -
]*
)i    i   s   <h1>s   </h1>sn   <html><head><title>%s</title>
            </head><body>
            %s
            </body></html>
            (   s   syss   getopts   argvs   optss   argss   infiles   opens   reads   ss   stdins   filters   locales	   setlocales   LC_ALLs   res   subs   compiles   matchs   mos   Nones   lens   groups   strs   html_with_referencess   finds   t(	   s   optss   infiles   getopts   ts   ss   argss   mos   locales   sys(    (    sx   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_0/happydoclib/docstring/StructuredText/ClassicStructuredText.pys   main	s.   "

 s   __main__(   s   __doc__s   ts_regexs   regexs   gsubs   strings   splits   joins   strips   finds   res   compiles   search_groups   untabifys   indents   reindents   indent_levels
   paragraphss	   structures   Tables   tables   StructuredTexts   ctag_prefixs   ctag_suffixs   ctag_middles   ctag_middl2s   ctags   HTMLs
   html_quotes   html_with_referencess   mains   __name__(   s   mains
   html_quotes   ctag_middl2s   Tables   ctag_suffixs   splits   ctag_middles   StructuredTexts   res   html_with_referencess   indents   strings   indent_levels   joins   ts_regexs   regexs	   structures   finds   tables   strips   gsubs
   paragraphss   ctag_prefixs   HTMLs   untabifys   reindents   ctag(    (    sx   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_0/happydoclib/docstring/StructuredText/ClassicStructuredText.pys   ? s2   ",8				W' 