-
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   starts   indents
   ts_resultss   lnls   grpss   rests   result(    (    sx   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_1/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    is    s   %s%s
N(   s   splits   untabifys   aStrings   rs   levels   tabs   join(   s   aStrings   indents   rs   tab(    (    sx   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_1/happydoclib/docstring/StructuredText/ClassicStructuredText.pys   indent s     i    c    s     | o  t |   }  n  t |   d }  | | j o  |  Sn  g  }  | i }  | | j oF  d | | }  x+ t	 |  d  D ] }  | | |  q Wn?  | | }  x+ t	 |  d  D ] }  | | |  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   ls   ss   rs   tabs   append(    (    sx   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_1/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   indents
   ts_resultss   starts   grpss   texts   is   l(    (    sx   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_1/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   levels   is   l(    (    sx   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_1/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   rs   sublens   is   l(    (    sx   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_1/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 ] }  g  }  x  d o  | i
 |  } | o d Sn | i d  } | i | i d   | t |  j o Pn | | } qO W|  i i |  q7 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   texts   mos   poss   lines   row(    (    sx   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_1/happydoclib/docstring/StructuredText/ClassicStructuredText.pys   create s$   
 		 
  c    s   	
g  } x |  i D] } g  } d } x^ | D]S } | d j o | d } qA n' | i |  i | | f  d } qA W| i |  i	 t
 | d   q W|  i t
 | d  Sd S(   s'   Creates an HTML representation of tablei   s    N(   s	   htmltables   selfs   tables   rows   htmlrows   colspans   cells   appends   CELLs   ROWs   joins   TABLE(   s   selfs   cells   colspans	   htmltables   htmlrows   row(    (    sx   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_1/happydoclib/docstring/StructuredText/ClassicStructuredText.pys   html	s   	 			
 	
$(   s   CELLs   ROWs   TABLEs   res   compiles   creates   html(    (    (    sx   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_1/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    s1  %.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=":is	   <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   pats
   paragraphss	   protolesss   p_reg(    (    sx   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_1/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_1/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_1/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_1/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_1/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_1/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_1/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_1/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_1/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_1/happydoclib/docstring/StructuredText/ClassicStructuredText.pys   normals   i    c    s   | o d Sn | o d } n
 d } xA | D]6 } d | t | d  |  i | d d  f } qC W| o | d } n | Sd  S(   Ns    s   <PRE>
s   %s%s

%si    i   s   </PRE>
(   s	   structures   taggeds   rs   ss
   html_quotes   selfs   pre(   s   selfs	   structures   taggeds   ss   r(    (    sx   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_1/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_1/happydoclib/docstring/StructuredText/ClassicStructuredText.pys   tables   s   [ 	
]*[o*-][ 	
]+\([^ ]*\)s   [ - ]examples?:[ - ]*$s   \([^
]+\)[ 	]+--[ 	
]+\([^ ]*\)s   
s1   [ 	]*\(\([0-9]+\|[%s]+\)[.)]\)+[ 	
]+\([^ ]*\|$\)s   [ 	]*([0-9]+)[ 	
]+\([^ ]*\|$\)c	  	  sE  d } x(| D]} | | 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 o7 |  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   is   ::i   i   is   :(   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   pss
   ts_resultss   ps   ss   rs   ts   d(    (    sx   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_1/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_1/happydoclib/docstring/StructuredText/ClassicStructuredText.pys   HTMLis   	0	s   &s   &amp;s   <s   &lt;s   >s   &gt;s   "s   &quot;c    sO   t  |   } x, | D]! \ } } | i | |  } q W| Sd  S(   N(   s   strs   vs   texts   character_entitiess   res   names   sub(   s   vs   character_entitiess   res   names   text(    (    sx   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_1/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_1/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_1/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_1/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   locales   mos   argss   syss   ss   ts   getopts   infiles   opts(    (    sx   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_1/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   ctags   strings   strips   untabifys   html_with_referencess   ctag_prefixs   gsubs
   paragraphss   indents   tables   finds	   structures   reindents   regexs   ts_regexs   joins   indent_levels   ctag_middles   res   StructuredTexts   HTMLs   mains   splits   ctag_suffixs   Tables   ctag_middl2s
   html_quote(    (    sx   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_1/happydoclib/docstring/StructuredText/ClassicStructuredText.pys   ? s2   ",8				W' 