<s> """<STR_LIT>""" <EOL> __docformat__ = '<STR_LIT>' <EOL> import re , string , types , sys , os . path <EOL> from epydoc . markup import * <EOL> from epydoc . util import wordwrap , plaintext_to_html , plaintext_to_latex <EOL> from epydoc . markup . doctest import doctest_to_html , doctest_to_latex <EOL> class Element : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , tag , * children , ** attribs ) : <EOL> self . tag = tag <EOL> """<STR_LIT>""" <EOL> self . children = list ( children ) <EOL> """<STR_LIT>""" <EOL> self . attribs = attribs <EOL> """<STR_LIT>""" <EOL> def __str__ ( self ) : <EOL> """<STR_LIT>""" <EOL> attribs = '<STR_LIT>' . join ( [ '<STR_LIT>' % t for t in self . attribs . items ( ) ] ) <EOL> return ( '<STR_LIT>' % ( self . tag , attribs ) + <EOL> '<STR_LIT>' . join ( [ str ( child ) for child in self . children ] ) + <EOL> '<STR_LIT>' % self . tag ) <EOL> def __repr__ ( self ) : <EOL> attribs = '<STR_LIT>' . join ( [ '<STR_LIT>' % t for t in self . attribs . items ( ) ] ) <EOL> args = '<STR_LIT>' . join ( [ '<STR_LIT>' % c for c in self . children ] ) <EOL> return '<STR_LIT>' % ( self . tag , args , attribs ) <EOL> _HEADING_CHARS = "<STR_LIT>" <EOL> _ESCAPES = { '<STR_LIT>' : '<STR_LIT:{>' , '<STR_LIT:rb>' : '<STR_LIT:}>' } <EOL> SYMBOLS = [ <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:v>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT:int>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> ] <EOL> _SYMBOLS = { } <EOL> for symbol in SYMBOLS : _SYMBOLS [ symbol ] = <NUM_LIT:1> <EOL> symblist = '<STR_LIT:U+0020>' <EOL> symblist += '<STR_LIT>' . join ( [ '<STR_LIT>' % ( symbol , symbol ) <EOL> for symbol in SYMBOLS ] ) <EOL> __doc__ = __doc__ . replace ( '<STR_LIT>' , symblist ) <EOL> del symbol , symblist <EOL> _COLORIZING_TAGS = { <EOL> '<STR_LIT:C>' : '<STR_LIT:code>' , <EOL> '<STR_LIT:M>' : '<STR_LIT>' , <EOL> '<STR_LIT:X>' : '<STR_LIT>' , <EOL> '<STR_LIT:I>' : '<STR_LIT>' , <EOL> '<STR_LIT:B>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:L>' : '<STR_LIT>' , <EOL> '<STR_LIT:E>' : '<STR_LIT>' , <EOL> '<STR_LIT:S>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> _LINK_COLORIZING_TAGS = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> def parse ( str , errors = None ) : <EOL> """<STR_LIT>""" <EOL> if errors == None : <EOL> errors = [ ] <EOL> raise_on_error = <NUM_LIT:1> <EOL> else : <EOL> raise_on_error = <NUM_LIT:0> <EOL> str = re . sub ( '<STR_LIT>' , '<STR_LIT>' , str ) <EOL> str = string . expandtabs ( str ) <EOL> tokens = _tokenize ( str , errors ) <EOL> encountered_field = <NUM_LIT:0> <EOL> doc = Element ( '<STR_LIT>' ) <EOL> stack = [ None , doc ] <EOL> indent_stack = [ - <NUM_LIT:1> , None ] <EOL> for token in tokens : <EOL> _pop_completed_blocks ( token , stack , indent_stack ) <EOL> if token . tag == Token . PARA : <EOL> _add_para ( doc , token , stack , indent_stack , errors ) <EOL> elif token . tag == Token . HEADING : <EOL> _add_section ( doc , token , stack , indent_stack , errors ) <EOL> elif token . tag == Token . LBLOCK : <EOL> stack [ - <NUM_LIT:1> ] . children . append ( token . to_dom ( doc ) ) <EOL> elif token . tag == Token . DTBLOCK : <EOL> stack [ - <NUM_LIT:1> ] . children . append ( token . to_dom ( doc ) ) <EOL> elif token . tag == Token . BULLET : <EOL> _add_list ( doc , token , stack , indent_stack , errors ) <EOL> else : <EOL> assert <NUM_LIT:0> , '<STR_LIT>' + token . tag <EOL> if stack [ - <NUM_LIT:1> ] . tag == '<STR_LIT>' : <EOL> encountered_field = <NUM_LIT:1> <EOL> elif encountered_field == <NUM_LIT:1> : <EOL> if len ( stack ) <= <NUM_LIT:3> : <EOL> estr = ( "<STR_LIT>" + <EOL> "<STR_LIT>" ) <EOL> errors . append ( StructuringError ( estr , token . startline ) ) <EOL> for child in doc . children : <EOL> _raise_graphs ( child , doc ) <EOL> if len ( [ e for e in errors if e . is_fatal ( ) ] ) > <NUM_LIT:0> : <EOL> if raise_on_error : <EOL> raise errors [ <NUM_LIT:0> ] <EOL> else : <EOL> return None <EOL> return doc <EOL> def _raise_graphs ( tree , parent ) : <EOL> have_graph_child = False <EOL> for elt in tree . children : <EOL> if isinstance ( elt , Element ) : <EOL> _raise_graphs ( elt , tree ) <EOL> if elt . tag == '<STR_LIT>' : have_graph_child = True <EOL> block = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> if have_graph_child and tree . tag not in block : <EOL> child_index = <NUM_LIT:0> <EOL> parent_index = parent . children . index ( tree ) <EOL> for elt in tree . children : <EOL> if isinstance ( elt , Element ) and elt . tag == '<STR_LIT>' : <EOL> left = tree . children [ : child_index ] <EOL> right = tree . children [ child_index + <NUM_LIT:1> : ] <EOL> parent . children [ parent_index : parent_index + <NUM_LIT:1> ] = [ <EOL> Element ( tree . tag , * left , ** tree . attribs ) , <EOL> elt , <EOL> Element ( tree . tag , * right , ** tree . attribs ) ] <EOL> child_index = <NUM_LIT:0> <EOL> parent_index += <NUM_LIT:2> <EOL> tree = parent . children [ parent_index ] <EOL> else : <EOL> child_index += <NUM_LIT:1> <EOL> def _pop_completed_blocks ( token , stack , indent_stack ) : <EOL> """<STR_LIT>""" <EOL> indent = token . indent <EOL> if indent != None : <EOL> while ( len ( stack ) > <NUM_LIT:2> ) : <EOL> pop = <NUM_LIT:0> <EOL> if indent_stack [ - <NUM_LIT:1> ] != None and indent < indent_stack [ - <NUM_LIT:1> ] : pop = <NUM_LIT:1> <EOL> elif indent_stack [ - <NUM_LIT:1> ] == None and indent < indent_stack [ - <NUM_LIT:2> ] : pop = <NUM_LIT:1> <EOL> elif ( token . tag == '<STR_LIT>' and indent == indent_stack [ - <NUM_LIT:2> ] and <EOL> stack [ - <NUM_LIT:1> ] . tag in ( '<STR_LIT>' , '<STR_LIT>' ) ) : pop = <NUM_LIT:1> <EOL> elif ( stack [ - <NUM_LIT:1> ] . tag in ( '<STR_LIT>' , '<STR_LIT>' ) and <EOL> ( token . tag != '<STR_LIT>' or token . contents [ - <NUM_LIT:1> ] == '<STR_LIT::>' ) ) : <EOL> pop = <NUM_LIT:1> <EOL> if pop == <NUM_LIT:0> : return <EOL> stack . pop ( ) <EOL> indent_stack . pop ( ) <EOL> def _add_para ( doc , para_token , stack , indent_stack , errors ) : <EOL> """<STR_LIT>""" <EOL> if indent_stack [ - <NUM_LIT:1> ] == None : <EOL> indent_stack [ - <NUM_LIT:1> ] = para_token . indent <EOL> if para_token . indent == indent_stack [ - <NUM_LIT:1> ] : <EOL> para = _colorize ( doc , para_token , errors ) <EOL> if para_token . inline : <EOL> para . attribs [ '<STR_LIT>' ] = True <EOL> stack [ - <NUM_LIT:1> ] . children . append ( para ) <EOL> else : <EOL> estr = "<STR_LIT>" <EOL> errors . append ( StructuringError ( estr , para_token . startline ) ) <EOL> def _add_section ( doc , heading_token , stack , indent_stack , errors ) : <EOL> """<STR_LIT>""" <EOL> if indent_stack [ - <NUM_LIT:1> ] == None : <EOL> indent_stack [ - <NUM_LIT:1> ] = heading_token . indent <EOL> elif indent_stack [ - <NUM_LIT:1> ] != heading_token . indent : <EOL> estr = "<STR_LIT>" <EOL> errors . append ( StructuringError ( estr , heading_token . startline ) ) <EOL> for tok in stack [ <NUM_LIT:2> : ] : <EOL> if tok . tag != "<STR_LIT>" : <EOL> estr = "<STR_LIT>" <EOL> errors . append ( StructuringError ( estr , heading_token . startline ) ) <EOL> break <EOL> if ( heading_token . level + <NUM_LIT:2> ) > len ( stack ) : <EOL> estr = "<STR_LIT>" <EOL> errors . append ( StructuringError ( estr , heading_token . startline ) ) <EOL> stack [ heading_token . level + <NUM_LIT:2> : ] = [ ] <EOL> indent_stack [ heading_token . level + <NUM_LIT:2> : ] = [ ] <EOL> head = _colorize ( doc , heading_token , errors , '<STR_LIT>' ) <EOL> sec = Element ( "<STR_LIT>" ) <EOL> stack [ - <NUM_LIT:1> ] . children . append ( sec ) <EOL> stack . append ( sec ) <EOL> sec . children . append ( head ) <EOL> indent_stack . append ( None ) <EOL> def _add_list ( doc , bullet_token , stack , indent_stack , errors ) : <EOL> """<STR_LIT>""" <EOL> if bullet_token . contents [ - <NUM_LIT:1> ] == '<STR_LIT:->' : <EOL> list_type = '<STR_LIT>' <EOL> elif bullet_token . contents [ - <NUM_LIT:1> ] == '<STR_LIT:.>' : <EOL> list_type = '<STR_LIT>' <EOL> elif bullet_token . contents [ - <NUM_LIT:1> ] == '<STR_LIT::>' : <EOL> list_type = '<STR_LIT>' <EOL> else : <EOL> raise AssertionError ( '<STR_LIT>' % bullet_token . contents ) <EOL> newlist = <NUM_LIT:0> <EOL> if stack [ - <NUM_LIT:1> ] . tag != list_type : <EOL> newlist = <NUM_LIT:1> <EOL> elif list_type == '<STR_LIT>' and stack [ - <NUM_LIT:1> ] . tag == '<STR_LIT>' : <EOL> old_listitem = stack [ - <NUM_LIT:1> ] . children [ - <NUM_LIT:1> ] <EOL> old_bullet = old_listitem . attribs . get ( "<STR_LIT>" ) . split ( '<STR_LIT:.>' ) [ : - <NUM_LIT:1> ] <EOL> new_bullet = bullet_token . contents . split ( '<STR_LIT:.>' ) [ : - <NUM_LIT:1> ] <EOL> if ( new_bullet [ : - <NUM_LIT:1> ] != old_bullet [ : - <NUM_LIT:1> ] or <EOL> int ( new_bullet [ - <NUM_LIT:1> ] ) != int ( old_bullet [ - <NUM_LIT:1> ] ) + <NUM_LIT:1> ) : <EOL> newlist = <NUM_LIT:1> <EOL> if newlist : <EOL> if stack [ - <NUM_LIT:1> ] . tag is '<STR_LIT>' : <EOL> estr = "<STR_LIT>" <EOL> errors . append ( StructuringError ( estr , bullet_token . startline ) ) <EOL> if stack [ - <NUM_LIT:1> ] . tag in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> stack . pop ( ) <EOL> indent_stack . pop ( ) <EOL> if ( list_type != '<STR_LIT>' and indent_stack [ - <NUM_LIT:1> ] is not None and <EOL> bullet_token . indent == indent_stack [ - <NUM_LIT:1> ] ) : <EOL> if bullet_token . startline != <NUM_LIT:1> or bullet_token . indent != <NUM_LIT:0> : <EOL> estr = "<STR_LIT>" <EOL> errors . append ( StructuringError ( estr , bullet_token . startline ) ) <EOL> if list_type == '<STR_LIT>' : <EOL> for tok in stack [ <NUM_LIT:2> : ] : <EOL> if tok . tag != "<STR_LIT>" : <EOL> estr = "<STR_LIT>" <EOL> errors . append ( <EOL> StructuringError ( estr , bullet_token . startline ) ) <EOL> break <EOL> stack [ <NUM_LIT:2> : ] = [ ] <EOL> indent_stack [ <NUM_LIT:2> : ] = [ ] <EOL> lst = Element ( list_type ) <EOL> stack [ - <NUM_LIT:1> ] . children . append ( lst ) <EOL> stack . append ( lst ) <EOL> indent_stack . append ( bullet_token . indent ) <EOL> if list_type == '<STR_LIT>' : <EOL> start = bullet_token . contents . split ( '<STR_LIT:.>' ) [ : - <NUM_LIT:1> ] <EOL> if start != '<STR_LIT:1>' : <EOL> lst . attribs [ "<STR_LIT:start>" ] = start [ - <NUM_LIT:1> ] <EOL> if list_type == '<STR_LIT>' : <EOL> li = Element ( "<STR_LIT>" ) <EOL> token_words = bullet_token . contents [ <NUM_LIT:1> : - <NUM_LIT:1> ] . split ( None , <NUM_LIT:1> ) <EOL> tag_elt = Element ( "<STR_LIT>" ) <EOL> tag_elt . children . append ( token_words [ <NUM_LIT:0> ] ) <EOL> li . children . append ( tag_elt ) <EOL> if len ( token_words ) > <NUM_LIT:1> : <EOL> arg_elt = Element ( "<STR_LIT>" ) <EOL> arg_elt . children . append ( token_words [ <NUM_LIT:1> ] ) <EOL> li . children . append ( arg_elt ) <EOL> else : <EOL> li = Element ( "<STR_LIT>" ) <EOL> if list_type == '<STR_LIT>' : <EOL> li . attribs [ "<STR_LIT>" ] = bullet_token . contents <EOL> stack [ - <NUM_LIT:1> ] . children . append ( li ) <EOL> stack . append ( li ) <EOL> indent_stack . append ( None ) <EOL> class Token : <EOL> """<STR_LIT>""" <EOL> PARA = "<STR_LIT>" <EOL> LBLOCK = "<STR_LIT>" <EOL> DTBLOCK = "<STR_LIT>" <EOL> HEADING = "<STR_LIT>" <EOL> BULLET = "<STR_LIT>" <EOL> def __init__ ( self , tag , startline , contents , indent , level = None , <EOL> inline = False ) : <EOL> """<STR_LIT>""" <EOL> self . tag = tag <EOL> self . startline = startline <EOL> self . contents = contents <EOL> self . indent = indent <EOL> self . level = level <EOL> self . inline = inline <EOL> def __repr__ ( self ) : <EOL> """<STR_LIT>""" <EOL> return '<STR_LIT>' % ( self . tag , self . startline ) <EOL> def to_dom ( self , doc ) : <EOL> """<STR_LIT>""" <EOL> e = Element ( self . tag ) <EOL> e . children . append ( self . contents ) <EOL> return e <EOL> _ULIST_BULLET = '<STR_LIT>' <EOL> _OLIST_BULLET = '<STR_LIT>' <EOL> _FIELD_BULLET = '<STR_LIT>' <EOL> _BULLET_RE = re . compile ( _ULIST_BULLET + '<STR_LIT:|>' + <EOL> _OLIST_BULLET + '<STR_LIT:|>' + <EOL> _FIELD_BULLET ) <EOL> _LIST_BULLET_RE = re . compile ( _ULIST_BULLET + '<STR_LIT:|>' + _OLIST_BULLET ) <EOL> _FIELD_BULLET_RE = re . compile ( _FIELD_BULLET ) <EOL> del _ULIST_BULLET , _OLIST_BULLET , _FIELD_BULLET <EOL> def _tokenize_doctest ( lines , start , block_indent , tokens , errors ) : <EOL> """<STR_LIT>""" <EOL> min_indent = block_indent <EOL> linenum = start + <NUM_LIT:1> <EOL> while linenum < len ( lines ) : <EOL> line = lines [ linenum ] <EOL> indent = len ( line ) - len ( line . lstrip ( ) ) <EOL> if indent == len ( line ) : break <EOL> if indent < block_indent : <EOL> min_indent = min ( min_indent , indent ) <EOL> estr = '<STR_LIT>' <EOL> errors . append ( TokenizationError ( estr , linenum ) ) <EOL> linenum += <NUM_LIT:1> <EOL> contents = [ line [ min_indent : ] for line in lines [ start : linenum ] ] <EOL> contents = '<STR_LIT:\n>' . join ( contents ) <EOL> tokens . append ( Token ( Token . DTBLOCK , start , contents , block_indent ) ) <EOL> return linenum <EOL> def _tokenize_literal ( lines , start , block_indent , tokens , errors ) : <EOL> """<STR_LIT>""" <EOL> linenum = start + <NUM_LIT:1> <EOL> while linenum < len ( lines ) : <EOL> line = lines [ linenum ] <EOL> indent = len ( line ) - len ( line . lstrip ( ) ) <EOL> if len ( line ) != indent and indent <= block_indent : <EOL> break <EOL> linenum += <NUM_LIT:1> <EOL> contents = [ line [ block_indent + <NUM_LIT:1> : ] for line in lines [ start : linenum ] ] <EOL> contents = '<STR_LIT:\n>' . join ( contents ) <EOL> contents = re . sub ( '<STR_LIT>' , '<STR_LIT>' , contents ) <EOL> tokens . append ( Token ( Token . LBLOCK , start , contents , block_indent ) ) <EOL> return linenum <EOL> def _tokenize_listart ( lines , start , bullet_indent , tokens , errors ) : <EOL> """<STR_LIT>""" <EOL> linenum = start + <NUM_LIT:1> <EOL> para_indent = None <EOL> doublecolon = lines [ start ] . rstrip ( ) [ - <NUM_LIT:2> : ] == '<STR_LIT>' <EOL> para_start = _BULLET_RE . match ( lines [ start ] , bullet_indent ) . end ( ) <EOL> bcontents = lines [ start ] [ bullet_indent : para_start ] . strip ( ) <EOL> while linenum < len ( lines ) : <EOL> line = lines [ linenum ] <EOL> indent = len ( line ) - len ( line . lstrip ( ) ) <EOL> if doublecolon : break <EOL> if line . rstrip ( ) [ - <NUM_LIT:2> : ] == '<STR_LIT>' : doublecolon = <NUM_LIT:1> <EOL> if indent == len ( line ) : break <EOL> if indent < bullet_indent : break <EOL> if _BULLET_RE . match ( line , indent ) : break <EOL> if para_indent == None : para_indent = indent <EOL> if indent != para_indent : break <EOL> linenum += <NUM_LIT:1> <EOL> tokens . append ( Token ( Token . BULLET , start , bcontents , bullet_indent , <EOL> inline = True ) ) <EOL> pcontents = ( [ lines [ start ] [ para_start : ] . strip ( ) ] + <EOL> [ line . strip ( ) for line in lines [ start + <NUM_LIT:1> : linenum ] ] ) <EOL> pcontents = '<STR_LIT:U+0020>' . join ( pcontents ) . strip ( ) <EOL> if pcontents : <EOL> tokens . append ( Token ( Token . PARA , start , pcontents , para_indent , <EOL> inline = True ) ) <EOL> return linenum <EOL> def _tokenize_para ( lines , start , para_indent , tokens , errors ) : <EOL> """<STR_LIT>""" <EOL> linenum = start + <NUM_LIT:1> <EOL> doublecolon = <NUM_LIT:0> <EOL> while linenum < len ( lines ) : <EOL> line = lines [ linenum ] <EOL> indent = len ( line ) - len ( line . lstrip ( ) ) <EOL> if doublecolon : break <EOL> if line . rstrip ( ) [ - <NUM_LIT:2> : ] == '<STR_LIT>' : doublecolon = <NUM_LIT:1> <EOL> if indent == len ( line ) : break <EOL> if indent != para_indent : break <EOL> if _BULLET_RE . match ( line , indent ) : break <EOL> if line [ indent ] == '<STR_LIT:@>' : <EOL> estr = "<STR_LIT>" <EOL> errors . append ( TokenizationError ( estr , linenum , is_fatal = <NUM_LIT:0> ) ) <EOL> linenum += <NUM_LIT:1> <EOL> contents = [ line . strip ( ) for line in lines [ start : linenum ] ] <EOL> if ( ( len ( contents ) < <NUM_LIT:2> ) or <EOL> ( contents [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] not in _HEADING_CHARS ) or <EOL> ( abs ( len ( contents [ <NUM_LIT:0> ] ) - len ( contents [ <NUM_LIT:1> ] ) ) > <NUM_LIT:5> ) ) : <EOL> looks_like_heading = <NUM_LIT:0> <EOL> else : <EOL> looks_like_heading = <NUM_LIT:1> <EOL> for char in contents [ <NUM_LIT:1> ] : <EOL> if char != contents [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] : <EOL> looks_like_heading = <NUM_LIT:0> <EOL> break <EOL> if looks_like_heading : <EOL> if len ( contents [ <NUM_LIT:0> ] ) != len ( contents [ <NUM_LIT:1> ] ) : <EOL> estr = ( "<STR_LIT>" + <EOL> "<STR_LIT>" + <EOL> "<STR_LIT>" ) <EOL> errors . append ( TokenizationError ( estr , start , is_fatal = <NUM_LIT:0> ) ) <EOL> else : <EOL> level = _HEADING_CHARS . index ( contents [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] ) <EOL> tokens . append ( Token ( Token . HEADING , start , <EOL> contents [ <NUM_LIT:0> ] , para_indent , level ) ) <EOL> return start + <NUM_LIT:2> <EOL> contents = '<STR_LIT:U+0020>' . join ( contents ) <EOL> tokens . append ( Token ( Token . PARA , start , contents , para_indent ) ) <EOL> return linenum <EOL> def _tokenize ( str , errors ) : <EOL> """<STR_LIT>""" <EOL> tokens = [ ] <EOL> lines = str . split ( '<STR_LIT:\n>' ) <EOL> linenum = <NUM_LIT:0> <EOL> while linenum < len ( lines ) : <EOL> line = lines [ linenum ] <EOL> indent = len ( line ) - len ( line . lstrip ( ) ) <EOL> if indent == len ( line ) : <EOL> linenum += <NUM_LIT:1> <EOL> continue <EOL> elif line [ indent : indent + <NUM_LIT:4> ] == '<STR_LIT>' : <EOL> linenum = _tokenize_doctest ( lines , linenum , indent , <EOL> tokens , errors ) <EOL> elif _BULLET_RE . match ( line , indent ) : <EOL> linenum = _tokenize_listart ( lines , linenum , indent , <EOL> tokens , errors ) <EOL> if tokens [ - <NUM_LIT:1> ] . indent != None : <EOL> indent = tokens [ - <NUM_LIT:1> ] . indent <EOL> else : <EOL> if line [ indent ] == '<STR_LIT:@>' : <EOL> estr = "<STR_LIT>" <EOL> errors . append ( TokenizationError ( estr , linenum , is_fatal = <NUM_LIT:0> ) ) <EOL> linenum = _tokenize_para ( lines , linenum , indent , tokens , errors ) <EOL> if ( tokens [ - <NUM_LIT:1> ] . tag == Token . PARA and <EOL> tokens [ - <NUM_LIT:1> ] . contents [ - <NUM_LIT:2> : ] == '<STR_LIT>' ) : <EOL> tokens [ - <NUM_LIT:1> ] . contents = tokens [ - <NUM_LIT:1> ] . contents [ : - <NUM_LIT:1> ] <EOL> linenum = _tokenize_literal ( lines , linenum , indent , tokens , errors ) <EOL> return tokens <EOL> _BRACE_RE = re . compile ( '<STR_LIT>' ) <EOL> _TARGET_RE = re . compile ( '<STR_LIT>' ) <EOL> def _colorize ( doc , token , errors , tagName = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> str = token . contents <EOL> linenum = <NUM_LIT:0> <EOL> stack = [ Element ( tagName ) ] <EOL> openbrace_stack = [ <NUM_LIT:0> ] <EOL> start = <NUM_LIT:0> <EOL> while <NUM_LIT:1> : <EOL> match = _BRACE_RE . search ( str , start ) <EOL> if match == None : break <EOL> end = match . start ( ) <EOL> if match . group ( ) == '<STR_LIT:{>' : <EOL> if ( end > <NUM_LIT:0> ) and '<STR_LIT:A>' <= str [ end - <NUM_LIT:1> ] <= '<STR_LIT>' : <EOL> if ( end - <NUM_LIT:1> ) > start : <EOL> stack [ - <NUM_LIT:1> ] . children . append ( str [ start : end - <NUM_LIT:1> ] ) <EOL> if str [ end - <NUM_LIT:1> ] not in _COLORIZING_TAGS : <EOL> estr = "<STR_LIT>" <EOL> errors . append ( ColorizingError ( estr , token , end - <NUM_LIT:1> ) ) <EOL> stack . append ( Element ( '<STR_LIT>' ) ) <EOL> else : <EOL> tag = _COLORIZING_TAGS [ str [ end - <NUM_LIT:1> ] ] <EOL> stack . append ( Element ( tag ) ) <EOL> else : <EOL> if end > start : <EOL> stack [ - <NUM_LIT:1> ] . children . append ( str [ start : end ] ) <EOL> stack . append ( Element ( '<STR_LIT>' ) ) <EOL> openbrace_stack . append ( end ) <EOL> stack [ - <NUM_LIT:2> ] . children . append ( stack [ - <NUM_LIT:1> ] ) <EOL> elif match . group ( ) == '<STR_LIT:}>' : <EOL> if len ( stack ) <= <NUM_LIT:1> : <EOL> estr = "<STR_LIT>" <EOL> errors . append ( ColorizingError ( estr , token , end ) ) <EOL> start = end + <NUM_LIT:1> <EOL> continue <EOL> if end > start : <EOL> stack [ - <NUM_LIT:1> ] . children . append ( str [ start : end ] ) <EOL> if stack [ - <NUM_LIT:1> ] . tag == '<STR_LIT>' : <EOL> if ( len ( stack [ - <NUM_LIT:1> ] . children ) != <NUM_LIT:1> or <EOL> not isinstance ( stack [ - <NUM_LIT:1> ] . children [ <NUM_LIT:0> ] , basestring ) ) : <EOL> estr = "<STR_LIT>" <EOL> errors . append ( ColorizingError ( estr , token , end ) ) <EOL> else : <EOL> symb = stack [ - <NUM_LIT:1> ] . children [ <NUM_LIT:0> ] <EOL> if symb in _SYMBOLS : <EOL> stack [ - <NUM_LIT:2> ] . children [ - <NUM_LIT:1> ] = Element ( '<STR_LIT>' , symb ) <EOL> else : <EOL> estr = "<STR_LIT>" <EOL> errors . append ( ColorizingError ( estr , token , end ) ) <EOL> if stack [ - <NUM_LIT:1> ] . tag == '<STR_LIT>' : <EOL> if ( len ( stack [ - <NUM_LIT:1> ] . children ) != <NUM_LIT:1> or <EOL> not isinstance ( stack [ - <NUM_LIT:1> ] . children [ <NUM_LIT:0> ] , basestring ) ) : <EOL> estr = "<STR_LIT>" <EOL> errors . append ( ColorizingError ( estr , token , end ) ) <EOL> else : <EOL> escp = stack [ - <NUM_LIT:1> ] . children [ <NUM_LIT:0> ] <EOL> if escp in _ESCAPES : <EOL> stack [ - <NUM_LIT:2> ] . children [ - <NUM_LIT:1> ] = _ESCAPES [ escp ] <EOL> elif len ( escp ) == <NUM_LIT:1> : <EOL> stack [ - <NUM_LIT:2> ] . children [ - <NUM_LIT:1> ] = escp <EOL> else : <EOL> estr = "<STR_LIT>" <EOL> errors . append ( ColorizingError ( estr , token , end ) ) <EOL> if stack [ - <NUM_LIT:1> ] . tag == '<STR_LIT>' : <EOL> stack [ - <NUM_LIT:2> ] . children [ - <NUM_LIT:1> : ] = [ '<STR_LIT:{>' ] + stack [ - <NUM_LIT:1> ] . children + [ '<STR_LIT:}>' ] <EOL> if stack [ - <NUM_LIT:1> ] . tag == '<STR_LIT>' : <EOL> _colorize_graph ( doc , stack [ - <NUM_LIT:1> ] , token , end , errors ) <EOL> if stack [ - <NUM_LIT:1> ] . tag in _LINK_COLORIZING_TAGS : <EOL> _colorize_link ( doc , stack [ - <NUM_LIT:1> ] , token , end , errors ) <EOL> openbrace_stack . pop ( ) <EOL> stack . pop ( ) <EOL> start = end + <NUM_LIT:1> <EOL> if start < len ( str ) : <EOL> stack [ - <NUM_LIT:1> ] . children . append ( str [ start : ] ) <EOL> if len ( stack ) != <NUM_LIT:1> : <EOL> estr = "<STR_LIT>" <EOL> errors . append ( ColorizingError ( estr , token , openbrace_stack [ - <NUM_LIT:1> ] ) ) <EOL> return stack [ <NUM_LIT:0> ] <EOL> GRAPH_TYPES = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> def _colorize_graph ( doc , graph , token , end , errors ) : <EOL> """<STR_LIT>""" <EOL> bad_graph_spec = False <EOL> children = graph . children [ : ] <EOL> graph . children = [ ] <EOL> if len ( children ) != <NUM_LIT:1> or not isinstance ( children [ <NUM_LIT:0> ] , basestring ) : <EOL> bad_graph_spec = "<STR_LIT>" <EOL> else : <EOL> pieces = children [ <NUM_LIT:0> ] . split ( None , <NUM_LIT:1> ) <EOL> graphtype = pieces [ <NUM_LIT:0> ] . replace ( '<STR_LIT::>' , '<STR_LIT>' ) . strip ( ) . lower ( ) <EOL> if graphtype in GRAPH_TYPES : <EOL> if len ( pieces ) == <NUM_LIT:2> : <EOL> if re . match ( r'<STR_LIT>' , pieces [ <NUM_LIT:1> ] ) : <EOL> args = pieces [ <NUM_LIT:1> ] . replace ( '<STR_LIT:U+002C>' , '<STR_LIT:U+0020>' ) . replace ( '<STR_LIT::>' , '<STR_LIT>' ) . split ( ) <EOL> else : <EOL> bad_graph_spec = "<STR_LIT>" <EOL> else : <EOL> args = [ ] <EOL> else : <EOL> bad_graph_spec = ( "<STR_LIT>" % <EOL> ( pieces [ <NUM_LIT:0> ] , '<STR_LIT:U+002CU+0020>' . join ( GRAPH_TYPES ) ) ) <EOL> if bad_graph_spec : <EOL> errors . append ( ColorizingError ( bad_graph_spec , token , end ) ) <EOL> graph . children . append ( '<STR_LIT:none>' ) <EOL> graph . children . append ( '<STR_LIT>' ) <EOL> return <EOL> graph . children . append ( graphtype ) <EOL> for arg in args : <EOL> graph . children . append ( arg ) <EOL> def _colorize_link ( doc , link , token , end , errors ) : <EOL> variables = link . children [ : ] <EOL> if len ( variables ) == <NUM_LIT:0> or not isinstance ( variables [ - <NUM_LIT:1> ] , basestring ) : <EOL> estr = "<STR_LIT>" % link . tag <EOL> errors . append ( ColorizingError ( estr , token , end ) ) <EOL> return <EOL> match2 = _TARGET_RE . match ( variables [ - <NUM_LIT:1> ] ) <EOL> if match2 : <EOL> ( text , target ) = match2 . groups ( ) <EOL> variables [ - <NUM_LIT:1> ] = text <EOL> elif len ( variables ) == <NUM_LIT:1> : <EOL> target = variables [ <NUM_LIT:0> ] <EOL> else : <EOL> estr = "<STR_LIT>" % link . tag <EOL> errors . append ( ColorizingError ( estr , token , end ) ) <EOL> return <EOL> name_elt = Element ( '<STR_LIT:name>' , * variables ) <EOL> target = re . sub ( r'<STR_LIT>' , '<STR_LIT>' , target ) <EOL> if link . tag == '<STR_LIT>' : <EOL> if not re . match ( r'<STR_LIT>' , target ) : <EOL> if re . match ( r'<STR_LIT>' , target ) : <EOL> target = '<STR_LIT>' + target <EOL> else : <EOL> target = '<STR_LIT>' + target <EOL> elif link . tag == '<STR_LIT>' : <EOL> target = re . sub ( r'<STR_LIT>' , '<STR_LIT>' , target ) <EOL> if not re . match ( r'<STR_LIT>' , target ) : <EOL> estr = "<STR_LIT>" <EOL> errors . append ( ColorizingError ( estr , token , end ) ) <EOL> return <EOL> target_elt = Element ( '<STR_LIT:target>' , target ) <EOL> link . children = [ name_elt , target_elt ] <EOL> def to_epytext ( tree , indent = <NUM_LIT:0> , seclevel = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( tree , basestring ) : <EOL> str = re . sub ( r'<STR_LIT>' , '<STR_LIT>' , tree ) <EOL> str = re . sub ( r'<STR_LIT>' , '<STR_LIT>' , str ) <EOL> return str <EOL> if tree . tag == '<STR_LIT>' : indent -= <NUM_LIT:2> <EOL> if tree . tag == '<STR_LIT>' : seclevel += <NUM_LIT:1> <EOL> variables = [ to_epytext ( c , indent + <NUM_LIT:2> , seclevel ) for c in tree . children ] <EOL> childstr = '<STR_LIT>' . join ( variables ) <EOL> childstr = re . sub ( '<STR_LIT>' , '<STR_LIT>' , childstr ) <EOL> if tree . tag == '<STR_LIT>' : <EOL> str = wordwrap ( childstr , indent ) + '<STR_LIT:\n>' <EOL> str = re . sub ( r'<STR_LIT>' , r'<STR_LIT>' , str ) <EOL> str = re . sub ( r'<STR_LIT>' , r'<STR_LIT>' , str ) <EOL> str = re . sub ( r'<STR_LIT>' , r'<STR_LIT>' , str ) <EOL> str = re . sub ( r'<STR_LIT>' , r'<STR_LIT>' , str ) <EOL> str = re . sub ( '<STR_LIT>' , '<STR_LIT>' , str ) <EOL> str = re . sub ( '<STR_LIT>' , '<STR_LIT>' , str ) <EOL> return str <EOL> elif tree . tag == '<STR_LIT>' : <EOL> bullet = tree . attribs . get ( '<STR_LIT>' ) or '<STR_LIT:->' <EOL> return indent * '<STR_LIT:U+0020>' + bullet + '<STR_LIT:U+0020>' + childstr . lstrip ( ) <EOL> elif tree . tag == '<STR_LIT>' : <EOL> str = re . sub ( '<STR_LIT>' , '<STR_LIT>' , childstr ) <EOL> str = re . sub ( '<STR_LIT>' , '<STR_LIT>' , str ) <EOL> uline = len ( childstr ) * _HEADING_CHARS [ seclevel - <NUM_LIT:1> ] <EOL> return ( indent - <NUM_LIT:2> ) * '<STR_LIT:U+0020>' + str + '<STR_LIT:\n>' + ( indent - <NUM_LIT:2> ) * '<STR_LIT:U+0020>' + uline + '<STR_LIT:\n>' <EOL> elif tree . tag == '<STR_LIT>' : <EOL> str = re . sub ( '<STR_LIT>' , '<STR_LIT:{>' , childstr ) <EOL> str = re . sub ( '<STR_LIT>' , '<STR_LIT:}>' , str ) <EOL> lines = [ '<STR_LIT:U+0020>' + indent * '<STR_LIT:U+0020>' + line for line in str . split ( '<STR_LIT:\n>' ) ] <EOL> return '<STR_LIT:\n>' . join ( lines ) + '<STR_LIT>' <EOL> elif tree . tag == '<STR_LIT>' : <EOL> str = re . sub ( '<STR_LIT>' , '<STR_LIT:{>' , childstr ) <EOL> str = re . sub ( '<STR_LIT>' , '<STR_LIT:}>' , str ) <EOL> lines = [ ( indent + <NUM_LIT:1> ) * '<STR_LIT:U+0020>' + line for line in str . split ( '<STR_LIT:\n>' ) ] <EOL> return '<STR_LIT>' + '<STR_LIT:\n>' . join ( lines ) + '<STR_LIT>' <EOL> elif tree . tag == '<STR_LIT>' : <EOL> numargs = <NUM_LIT:0> <EOL> while tree . children [ numargs + <NUM_LIT:1> ] . tag == '<STR_LIT>' : numargs += <NUM_LIT:1> <EOL> tag = variables [ <NUM_LIT:0> ] <EOL> args = variables [ <NUM_LIT:1> : <NUM_LIT:1> + numargs ] <EOL> body = variables [ <NUM_LIT:1> + numargs : ] <EOL> str = ( indent ) * '<STR_LIT:U+0020>' + '<STR_LIT:@>' + variables [ <NUM_LIT:0> ] <EOL> if args : str += '<STR_LIT:(>' + '<STR_LIT:U+002CU+0020>' . join ( args ) + '<STR_LIT:)>' <EOL> return str + '<STR_LIT>' + '<STR_LIT>' . join ( body ) <EOL> elif tree . tag == '<STR_LIT:target>' : <EOL> return '<STR_LIT>' % childstr <EOL> elif tree . tag in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:name>' ) : <EOL> return childstr <EOL> elif tree . tag == '<STR_LIT>' : <EOL> return '<STR_LIT>' % childstr <EOL> elif tree . tag == '<STR_LIT>' : <EOL> return '<STR_LIT>' % '<STR_LIT:U+0020>' . join ( variables ) <EOL> else : <EOL> for ( tag , name ) in _COLORIZING_TAGS . items ( ) : <EOL> if name == tree . tag : <EOL> return '<STR_LIT>' % ( tag , childstr ) <EOL> raise ValueError ( '<STR_LIT>' % tree . tag ) <EOL> SYMBOL_TO_PLAINTEXT = { <EOL> '<STR_LIT>' : '<STR_LIT:\\>' , <EOL> } <EOL> def to_plaintext ( tree , indent = <NUM_LIT:0> , seclevel = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( tree , basestring ) : return tree <EOL> if tree . tag == '<STR_LIT>' : seclevel += <NUM_LIT:1> <EOL> if tree . tag == '<STR_LIT>' : cindent = indent <EOL> elif tree . tag == '<STR_LIT>' and tree . attribs . get ( '<STR_LIT>' ) : <EOL> cindent = indent + <NUM_LIT:1> + len ( tree . attribs . get ( '<STR_LIT>' ) ) <EOL> else : <EOL> cindent = indent + <NUM_LIT:2> <EOL> variables = [ to_plaintext ( c , cindent , seclevel ) for c in tree . children ] <EOL> childstr = '<STR_LIT>' . join ( variables ) <EOL> if tree . tag == '<STR_LIT>' : <EOL> return wordwrap ( childstr , indent ) + '<STR_LIT:\n>' <EOL> elif tree . tag == '<STR_LIT>' : <EOL> bullet = tree . attribs . get ( '<STR_LIT>' ) or '<STR_LIT:->' <EOL> return indent * '<STR_LIT:U+0020>' + bullet + '<STR_LIT:U+0020>' + childstr . lstrip ( ) <EOL> elif tree . tag == '<STR_LIT>' : <EOL> uline = len ( childstr ) * _HEADING_CHARS [ seclevel - <NUM_LIT:1> ] <EOL> return ( ( indent - <NUM_LIT:2> ) * '<STR_LIT:U+0020>' + childstr + '<STR_LIT:\n>' + <EOL> ( indent - <NUM_LIT:2> ) * '<STR_LIT:U+0020>' + uline + '<STR_LIT:\n>' ) <EOL> elif tree . tag == '<STR_LIT>' : <EOL> lines = [ ( indent + <NUM_LIT:2> ) * '<STR_LIT:U+0020>' + line for line in childstr . split ( '<STR_LIT:\n>' ) ] <EOL> return '<STR_LIT:\n>' . join ( lines ) + '<STR_LIT>' <EOL> elif tree . tag == '<STR_LIT>' : <EOL> lines = [ ( indent + <NUM_LIT:1> ) * '<STR_LIT:U+0020>' + line for line in childstr . split ( '<STR_LIT:\n>' ) ] <EOL> return '<STR_LIT:\n>' . join ( lines ) + '<STR_LIT>' <EOL> elif tree . tag == '<STR_LIT>' : <EOL> return childstr <EOL> elif tree . tag == '<STR_LIT>' : <EOL> numargs = <NUM_LIT:0> <EOL> while tree . children [ numargs + <NUM_LIT:1> ] . tag == '<STR_LIT>' : numargs += <NUM_LIT:1> <EOL> tag = variables [ <NUM_LIT:0> ] <EOL> args = variables [ <NUM_LIT:1> : <NUM_LIT:1> + numargs ] <EOL> body = variables [ <NUM_LIT:1> + numargs : ] <EOL> str = ( indent ) * '<STR_LIT:U+0020>' + '<STR_LIT:@>' + variables [ <NUM_LIT:0> ] <EOL> if args : str += '<STR_LIT:(>' + '<STR_LIT:U+002CU+0020>' . join ( args ) + '<STR_LIT:)>' <EOL> return str + '<STR_LIT>' + '<STR_LIT>' . join ( body ) <EOL> elif tree . tag == '<STR_LIT>' : <EOL> if len ( variables ) != <NUM_LIT:2> : raise ValueError ( '<STR_LIT>' ) <EOL> elif variables [ <NUM_LIT:0> ] == variables [ <NUM_LIT:1> ] : return '<STR_LIT>' % variables [ <NUM_LIT:1> ] <EOL> else : return '<STR_LIT>' % ( variables [ <NUM_LIT:0> ] , variables [ <NUM_LIT:1> ] ) <EOL> elif tree . tag == '<STR_LIT>' : <EOL> if len ( variables ) != <NUM_LIT:2> : raise ValueError ( '<STR_LIT>' ) <EOL> return '<STR_LIT:%s>' % variables [ <NUM_LIT:0> ] <EOL> elif tree . tag in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> return childstr . replace ( '<STR_LIT>' , '<STR_LIT:\n>' ) + '<STR_LIT:\n>' <EOL> elif tree . tag == '<STR_LIT>' : <EOL> return '<STR_LIT:%s>' % SYMBOL_TO_PLAINTEXT . get ( childstr , childstr ) <EOL> elif tree . tag == '<STR_LIT>' : <EOL> return '<STR_LIT>' % ( variables [ <NUM_LIT:0> ] , '<STR_LIT:U+002CU+0020>' . join ( variables [ <NUM_LIT:1> : ] ) ) <EOL> else : <EOL> return childstr <EOL> def to_debug ( tree , indent = <NUM_LIT:4> , seclevel = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( tree , basestring ) : <EOL> str = re . sub ( r'<STR_LIT>' , '<STR_LIT>' , tree ) <EOL> str = re . sub ( r'<STR_LIT>' , '<STR_LIT>' , str ) <EOL> return str <EOL> if tree . tag == '<STR_LIT>' : seclevel += <NUM_LIT:1> <EOL> variables = [ to_debug ( c , indent + <NUM_LIT:2> , seclevel ) for c in tree . children ] <EOL> childstr = '<STR_LIT>' . join ( variables ) <EOL> childstr = re . sub ( '<STR_LIT>' , '<STR_LIT>' , childstr ) <EOL> if tree . tag == '<STR_LIT>' : <EOL> str = wordwrap ( childstr , indent - <NUM_LIT:6> , <NUM_LIT> ) + '<STR_LIT:\n>' <EOL> str = re . sub ( r'<STR_LIT>' , r'<STR_LIT>' , str ) <EOL> str = re . sub ( r'<STR_LIT>' , r'<STR_LIT>' , str ) <EOL> str = re . sub ( r'<STR_LIT>' , r'<STR_LIT>' , str ) <EOL> str = re . sub ( r'<STR_LIT>' , r'<STR_LIT>' , str ) <EOL> str = re . sub ( '<STR_LIT>' , '<STR_LIT>' , str ) <EOL> str = re . sub ( '<STR_LIT>' , '<STR_LIT>' , str ) <EOL> lines = str . rstrip ( ) . split ( '<STR_LIT:\n>' ) <EOL> lines [ <NUM_LIT:0> ] = '<STR_LIT>' + lines [ <NUM_LIT:0> ] <EOL> lines [ <NUM_LIT:1> : ] = [ '<STR_LIT>' + l for l in lines [ <NUM_LIT:1> : ] ] <EOL> return '<STR_LIT:\n>' . join ( lines ) + '<STR_LIT>' <EOL> elif tree . tag == '<STR_LIT>' : <EOL> bullet = tree . attribs . get ( '<STR_LIT>' ) or '<STR_LIT:->' <EOL> return '<STR_LIT>' + ( indent - <NUM_LIT:6> ) * '<STR_LIT:U+0020>' + bullet + '<STR_LIT:U+0020>' + childstr [ <NUM_LIT:6> : ] . lstrip ( ) <EOL> elif tree . tag in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> return '<STR_LIT>' + ( indent - <NUM_LIT:4> ) * '<STR_LIT:U+0020>' + childstr [ indent + <NUM_LIT:2> : ] <EOL> elif tree . tag == '<STR_LIT>' : <EOL> str = re . sub ( '<STR_LIT>' , '<STR_LIT>' , childstr ) <EOL> str = re . sub ( '<STR_LIT>' , '<STR_LIT>' , str ) <EOL> uline = len ( childstr ) * _HEADING_CHARS [ seclevel - <NUM_LIT:1> ] <EOL> return ( '<STR_LIT>' + ` seclevel ` + '<STR_LIT>' + ( indent - <NUM_LIT:8> ) * '<STR_LIT:U+0020>' + str + '<STR_LIT:\n>' + <EOL> '<STR_LIT>' + ( indent - <NUM_LIT:8> ) * '<STR_LIT:U+0020>' + uline + '<STR_LIT:\n>' ) <EOL> elif tree . tag == '<STR_LIT>' : <EOL> str = re . sub ( '<STR_LIT>' , '<STR_LIT:{>' , childstr ) <EOL> str = re . sub ( '<STR_LIT>' , '<STR_LIT:}>' , str ) <EOL> lines = [ '<STR_LIT>' + ( indent - <NUM_LIT:4> ) * '<STR_LIT:U+0020>' + line for line in str . split ( '<STR_LIT:\n>' ) ] <EOL> lines [ <NUM_LIT:0> ] = '<STR_LIT>' + lines [ <NUM_LIT:0> ] [ <NUM_LIT:5> : ] <EOL> return '<STR_LIT:\n>' . join ( lines ) + '<STR_LIT>' <EOL> elif tree . tag == '<STR_LIT>' : <EOL> str = re . sub ( '<STR_LIT>' , '<STR_LIT:{>' , childstr ) <EOL> str = re . sub ( '<STR_LIT>' , '<STR_LIT:}>' , str ) <EOL> lines = [ '<STR_LIT>' + ( indent - <NUM_LIT:5> ) * '<STR_LIT:U+0020>' + line for line in str . split ( '<STR_LIT:\n>' ) ] <EOL> lines [ <NUM_LIT:0> ] = '<STR_LIT>' + lines [ <NUM_LIT:0> ] [ <NUM_LIT:5> : ] <EOL> return '<STR_LIT>' + '<STR_LIT:\n>' . join ( lines ) + '<STR_LIT>' <EOL> elif tree . tag == '<STR_LIT>' : <EOL> numargs = <NUM_LIT:0> <EOL> while tree . children [ numargs + <NUM_LIT:1> ] . tag == '<STR_LIT>' : numargs += <NUM_LIT:1> <EOL> tag = variables [ <NUM_LIT:0> ] <EOL> args = variables [ <NUM_LIT:1> : <NUM_LIT:1> + numargs ] <EOL> body = variables [ <NUM_LIT:1> + numargs : ] <EOL> str = '<STR_LIT>' + ( indent - <NUM_LIT:6> ) * '<STR_LIT:U+0020>' + '<STR_LIT:@>' + variables [ <NUM_LIT:0> ] <EOL> if args : str += '<STR_LIT:(>' + '<STR_LIT:U+002CU+0020>' . join ( args ) + '<STR_LIT:)>' <EOL> return str + '<STR_LIT>' + '<STR_LIT>' . join ( body ) <EOL> elif tree . tag == '<STR_LIT:target>' : <EOL> return '<STR_LIT>' % childstr <EOL> elif tree . tag in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:name>' ) : <EOL> return childstr <EOL> elif tree . tag == '<STR_LIT>' : <EOL> return '<STR_LIT>' % childstr <EOL> elif tree . tag == '<STR_LIT>' : <EOL> return '<STR_LIT>' % '<STR_LIT:U+0020>' . join ( variables ) <EOL> else : <EOL> for ( tag , name ) in _COLORIZING_TAGS . items ( ) : <EOL> if name == tree . tag : <EOL> return '<STR_LIT>' % ( tag , childstr ) <EOL> raise ValueError ( '<STR_LIT>' % tree . tag ) <EOL> SCRWIDTH = <NUM_LIT> <EOL> def pparse ( str , show_warnings = <NUM_LIT:1> , show_errors = <NUM_LIT:1> , stream = sys . stderr ) : <EOL> """<STR_LIT>""" <EOL> errors = [ ] <EOL> confused = <NUM_LIT:0> <EOL> try : <EOL> val = parse ( str , errors ) <EOL> warnings = [ e for e in errors if not e . is_fatal ( ) ] <EOL> errors = [ e for e in errors if e . is_fatal ( ) ] <EOL> except : <EOL> confused = <NUM_LIT:1> <EOL> if not show_warnings : warnings = [ ] <EOL> warnings . sort ( ) <EOL> errors . sort ( ) <EOL> if warnings : <EOL> print >> stream , '<STR_LIT:=>' * SCRWIDTH <EOL> print >> stream , "<STR_LIT>" <EOL> print >> stream , '<STR_LIT:->' * SCRWIDTH <EOL> for warning in warnings : <EOL> print >> stream , warning . as_warning ( ) <EOL> print >> stream , '<STR_LIT:=>' * SCRWIDTH <EOL> if errors and show_errors : <EOL> if not warnings : print >> stream , '<STR_LIT:=>' * SCRWIDTH <EOL> print >> stream , "<STR_LIT>" <EOL> print >> stream , '<STR_LIT:->' * SCRWIDTH <EOL> for error in errors : <EOL> print >> stream , error <EOL> print >> stream , '<STR_LIT:=>' * SCRWIDTH <EOL> if confused : raise <EOL> elif errors : raise SyntaxError ( '<STR_LIT>' ) <EOL> else : return val <EOL> class TokenizationError ( ParseError ) : <EOL> """<STR_LIT>""" <EOL> class StructuringError ( ParseError ) : <EOL> """<STR_LIT>""" <EOL> class ColorizingError ( ParseError ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , descr , token , charnum , is_fatal = <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> ParseError . __init__ ( self , descr , token . startline , is_fatal ) <EOL> self . token = token <EOL> self . charnum = charnum <EOL> CONTEXT_RANGE = <NUM_LIT:20> <EOL> def descr ( self ) : <EOL> RANGE = self . CONTEXT_RANGE <EOL> if self . charnum <= RANGE : <EOL> left = self . token . contents [ <NUM_LIT:0> : self . charnum ] <EOL> else : <EOL> left = '<STR_LIT>' + self . token . contents [ self . charnum - RANGE : self . charnum ] <EOL> if ( len ( self . token . contents ) - self . charnum ) <= RANGE : <EOL> right = self . token . contents [ self . charnum : ] <EOL> else : <EOL> right = ( self . token . contents [ self . charnum : self . charnum + RANGE ] <EOL> + '<STR_LIT>' ) <EOL> return ( '<STR_LIT>' % ( self . _descr , left , right , '<STR_LIT:U+0020>' * len ( left ) ) ) <EOL> def parse_as_literal ( str ) : <EOL> """<STR_LIT>""" <EOL> return Element ( '<STR_LIT>' , Element ( '<STR_LIT>' , str ) ) <EOL> def parse_as_para ( str ) : <EOL> """<STR_LIT>""" <EOL> return Element ( '<STR_LIT>' , Element ( '<STR_LIT>' , str ) ) <EOL> def parse_docstring ( docstring , errors , ** options ) : <EOL> """<STR_LIT>""" <EOL> return ParsedEpytextDocstring ( parse ( docstring , errors ) , ** options ) <EOL> class ParsedEpytextDocstring ( ParsedDocstring ) : <EOL> SYMBOL_TO_HTML = { <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:v>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:int>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> SYMBOL_TO_LATEX = { <EOL> '<STR_LIT>' : r'<STR_LIT>' , '<STR_LIT>' : r'<STR_LIT>' , <EOL> '<STR_LIT>' : r'<STR_LIT>' , '<STR_LIT:v>' : r'<STR_LIT>' , <EOL> '<STR_LIT>' : r'<STR_LIT>' , '<STR_LIT>' : r'<STR_LIT>' , '<STR_LIT>' : <EOL> r'<STR_LIT>' , '<STR_LIT>' : r'<STR_LIT>' , '<STR_LIT>' : <EOL> r'<STR_LIT>' , '<STR_LIT>' : r'<STR_LIT>' , '<STR_LIT>' : r'<STR_LIT>' , <EOL> '<STR_LIT>' : r'<STR_LIT>' , '<STR_LIT>' : r'<STR_LIT>' , '<STR_LIT>' : <EOL> r'<STR_LIT>' , '<STR_LIT>' : r'<STR_LIT>' , '<STR_LIT>' : r'<STR_LIT>' , <EOL> '<STR_LIT>' : r'<STR_LIT>' , '<STR_LIT>' : r'<STR_LIT>' , '<STR_LIT>' : r'<STR_LIT>' , '<STR_LIT>' : <EOL> r'<STR_LIT>' , '<STR_LIT>' : r'<STR_LIT>' , '<STR_LIT>' : r'<STR_LIT>' , '<STR_LIT>' : <EOL> r'<STR_LIT>' , '<STR_LIT>' : r'<STR_LIT>' , '<STR_LIT>' : r'<STR_LIT>' , <EOL> '<STR_LIT>' : r'<STR_LIT>' , '<STR_LIT>' : r'<STR_LIT>' , '<STR_LIT>' : <EOL> r'<STR_LIT>' , <EOL> '<STR_LIT>' : r'<STR_LIT>' , '<STR_LIT>' : r'<STR_LIT>' , '<STR_LIT>' : <EOL> r'<STR_LIT>' , '<STR_LIT>' : r'<STR_LIT>' , '<STR_LIT>' : <EOL> r'<STR_LIT>' , '<STR_LIT>' : r'<STR_LIT>' , '<STR_LIT>' : r'<STR_LIT>' , <EOL> '<STR_LIT>' : r'<STR_LIT>' , '<STR_LIT>' : r'<STR_LIT>' , '<STR_LIT>' : <EOL> r'<STR_LIT>' , '<STR_LIT>' : r'<STR_LIT>' , '<STR_LIT>' : r'<STR_LIT>' , <EOL> '<STR_LIT>' : r'<STR_LIT>' , '<STR_LIT>' : r'<STR_LIT>' , '<STR_LIT>' : r'<STR_LIT>' , '<STR_LIT>' : <EOL> r'<STR_LIT>' , '<STR_LIT>' : r'<STR_LIT>' , '<STR_LIT>' : r'<STR_LIT>' , '<STR_LIT>' : <EOL> r'<STR_LIT>' , '<STR_LIT>' : r'<STR_LIT>' , '<STR_LIT>' : r'<STR_LIT>' , <EOL> '<STR_LIT>' : r'<STR_LIT>' , '<STR_LIT>' : r'<STR_LIT>' , '<STR_LIT>' : <EOL> r'<STR_LIT>' , <EOL> '<STR_LIT>' : r'<STR_LIT>' , '<STR_LIT>' : r'<STR_LIT>' , '<STR_LIT>' : <EOL> r'<STR_LIT>' , '<STR_LIT>' : r'<STR_LIT>' , '<STR_LIT>' : <EOL> r'<STR_LIT>' , '<STR_LIT>' : r'<STR_LIT>' , <EOL> '<STR_LIT>' : r'<STR_LIT>' , '<STR_LIT>' : r'<STR_LIT>' , '<STR_LIT>' : <EOL> r'<STR_LIT>' , '<STR_LIT>' : r'<STR_LIT>' , '<STR_LIT>' : <EOL> r'<STR_LIT>' , '<STR_LIT>' : r'<STR_LIT>' , <EOL> '<STR_LIT>' : r'<STR_LIT>' , '<STR_LIT>' : r'<STR_LIT>' , '<STR_LIT>' : <EOL> r'<STR_LIT>' , '<STR_LIT>' : r'<STR_LIT>' , '<STR_LIT>' : <EOL> r'<STR_LIT>' , '<STR_LIT>' : r'<STR_LIT>' , '<STR_LIT>' : r'<STR_LIT>' , <EOL> '<STR_LIT>' : r'<STR_LIT>' , '<STR_LIT>' : r'<STR_LIT>' , '<STR_LIT>' : r'<STR_LIT>' , <EOL> '<STR_LIT>' : r'<STR_LIT>' , '<STR_LIT>' : r'<STR_LIT>' , '<STR_LIT>' : <EOL> r'<STR_LIT>' , '<STR_LIT>' : r'<STR_LIT>' , '<STR_LIT>' : r'<STR_LIT>' , '<STR_LIT>' : <EOL> r'<STR_LIT>' , '<STR_LIT>' : r'<STR_LIT>' , '<STR_LIT:int>' : r'<STR_LIT>' , '<STR_LIT>' : <EOL> r'<STR_LIT>' , '<STR_LIT>' : r'<STR_LIT>' , '<STR_LIT>' : r'<STR_LIT>' , <EOL> '<STR_LIT>' : r'<STR_LIT>' , '<STR_LIT>' : r'<STR_LIT>' , '<STR_LIT>' : <EOL> r'<STR_LIT>' , '<STR_LIT>' : r'<STR_LIT>' , '<STR_LIT>' : r'<STR_LIT>' , '<STR_LIT>' : <EOL> r'<STR_LIT>' , '<STR_LIT>' : r'<STR_LIT>' , '<STR_LIT>' : r'<STR_LIT>' , <EOL> '<STR_LIT>' : r'<STR_LIT>' , '<STR_LIT>' : r'<STR_LIT>' , '<STR_LIT>' : <EOL> r'<STR_LIT>' , '<STR_LIT>' : r'<STR_LIT>' , '<STR_LIT>' : r'<STR_LIT>' , <EOL> '<STR_LIT>' : r'<STR_LIT>' , '<STR_LIT>' : r'<STR_LIT>' , '<STR_LIT>' : <EOL> r'<STR_LIT>' , '<STR_LIT>' : r'<STR_LIT>' , '<STR_LIT>' : r'<STR_LIT>' , <EOL> } <EOL> def __init__ ( self , dom_tree , ** options ) : <EOL> self . _tree = dom_tree <EOL> self . _html = self . _latex = self . _plaintext = None <EOL> self . _terms = None <EOL> if options . get ( '<STR_LIT>' ) and self . _tree is not None : <EOL> for elt in self . _tree . children : <EOL> elt . attribs [ '<STR_LIT>' ] = True <EOL> def __str__ ( self ) : <EOL> return str ( self . _tree ) <EOL> def to_html ( self , docstring_linker , directory = None , docindex = None , <EOL> context = None , ** options ) : <EOL> if self . _html is not None : return self . _html <EOL> if self . _tree is None : return '<STR_LIT>' <EOL> indent = options . get ( '<STR_LIT>' , <NUM_LIT:0> ) <EOL> self . _html = self . _to_html ( self . _tree , docstring_linker , directory , <EOL> docindex , context , indent ) <EOL> return self . _html <EOL> def to_latex ( self , docstring_linker , directory = None , docindex = None , <EOL> context = None , ** options ) : <EOL> if self . _latex is not None : return self . _latex <EOL> if self . _tree is None : return '<STR_LIT>' <EOL> indent = options . get ( '<STR_LIT>' , <NUM_LIT:0> ) <EOL> self . _hyperref = options . get ( '<STR_LIT>' , <NUM_LIT:1> ) <EOL> self . _latex = self . _to_latex ( self . _tree , docstring_linker , directory , <EOL> docindex , context , indent ) <EOL> return self . _latex <EOL> def to_plaintext ( self , docstring_linker , ** options ) : <EOL> if self . _tree is None : return '<STR_LIT>' <EOL> if '<STR_LIT>' in options : <EOL> self . _plaintext = to_plaintext ( self . _tree , <EOL> indent = options [ '<STR_LIT>' ] ) <EOL> else : <EOL> self . _plaintext = to_plaintext ( self . _tree ) <EOL> return self . _plaintext <EOL> def _index_term_key ( self , tree ) : <EOL> str = to_plaintext ( tree ) <EOL> str = re . sub ( r'<STR_LIT>' , '<STR_LIT:->' , str ) <EOL> return "<STR_LIT>" + re . sub ( "<STR_LIT>" , "<STR_LIT:_>" , str ) <EOL> def _to_html ( self , tree , linker , directory , docindex , context , <EOL> indent = <NUM_LIT:0> , seclevel = <NUM_LIT:0> ) : <EOL> if isinstance ( tree , basestring ) : <EOL> return plaintext_to_html ( tree ) <EOL> if tree . tag == '<STR_LIT>' : indent -= <NUM_LIT:2> <EOL> if tree . tag == '<STR_LIT>' : seclevel += <NUM_LIT:1> <EOL> variables = [ self . _to_html ( c , linker , directory , docindex , context , <EOL> indent + <NUM_LIT:2> , seclevel ) <EOL> for c in tree . children ] <EOL> childstr = '<STR_LIT>' . join ( variables ) <EOL> if tree . tag == '<STR_LIT>' : <EOL> return wordwrap ( <EOL> ( tree . attribs . get ( '<STR_LIT>' ) and '<STR_LIT:%s>' or '<STR_LIT>' ) % childstr , <EOL> indent ) <EOL> elif tree . tag == '<STR_LIT:code>' : <EOL> style = tree . attribs . get ( '<STR_LIT>' ) <EOL> if style : <EOL> return '<STR_LIT>' % ( style , childstr ) <EOL> else : <EOL> return '<STR_LIT>' % childstr <EOL> elif tree . tag == '<STR_LIT>' : <EOL> return ( '<STR_LIT>' % <EOL> ( variables [ <NUM_LIT:1> ] , variables [ <NUM_LIT:0> ] ) ) <EOL> elif tree . tag == '<STR_LIT>' : <EOL> return linker . translate_identifier_xref ( variables [ <NUM_LIT:1> ] , variables [ <NUM_LIT:0> ] ) <EOL> elif tree . tag == '<STR_LIT>' : <EOL> return '<STR_LIT>' % childstr <EOL> elif tree . tag == '<STR_LIT>' : <EOL> return '<STR_LIT>' % childstr <EOL> elif tree . tag == '<STR_LIT>' : <EOL> term = Element ( '<STR_LIT>' , * tree . children , ** tree . attribs ) <EOL> return linker . translate_indexterm ( ParsedEpytextDocstring ( term ) ) <EOL> elif tree . tag == '<STR_LIT>' : <EOL> return '<STR_LIT>' % childstr <EOL> elif tree . tag == '<STR_LIT>' : <EOL> return '<STR_LIT>' % ( indent * '<STR_LIT:U+0020>' , childstr , indent * '<STR_LIT:U+0020>' ) <EOL> elif tree . tag == '<STR_LIT>' : <EOL> start = tree . attribs . get ( '<STR_LIT:start>' ) or '<STR_LIT>' <EOL> return ( '<STR_LIT>' % <EOL> ( indent * '<STR_LIT:U+0020>' , start , childstr , indent * '<STR_LIT:U+0020>' ) ) <EOL> elif tree . tag == '<STR_LIT>' : <EOL> return indent * '<STR_LIT:U+0020>' + '<STR_LIT>' % ( childstr , indent * '<STR_LIT:U+0020>' ) <EOL> elif tree . tag == '<STR_LIT>' : <EOL> return ( '<STR_LIT>' % <EOL> ( ( indent - <NUM_LIT:2> ) * '<STR_LIT:U+0020>' , seclevel , childstr , seclevel ) ) <EOL> elif tree . tag == '<STR_LIT>' : <EOL> return '<STR_LIT>' % childstr <EOL> elif tree . tag == '<STR_LIT>' : <EOL> return doctest_to_html ( tree . children [ <NUM_LIT:0> ] . strip ( ) ) <EOL> elif tree . tag == '<STR_LIT>' : <EOL> raise AssertionError ( "<STR_LIT>" ) <EOL> elif tree . tag in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT:name>' , '<STR_LIT:target>' , '<STR_LIT:html>' ) : <EOL> return childstr <EOL> elif tree . tag == '<STR_LIT>' : <EOL> symbol = tree . children [ <NUM_LIT:0> ] <EOL> return self . SYMBOL_TO_HTML . get ( symbol , '<STR_LIT>' % symbol ) <EOL> elif tree . tag == '<STR_LIT>' : <EOL> if directory is None : return '<STR_LIT>' <EOL> graph = self . _build_graph ( variables [ <NUM_LIT:0> ] , variables [ <NUM_LIT:1> : ] , linker , <EOL> docindex , context ) <EOL> if not graph : return '<STR_LIT>' <EOL> return graph . to_html ( directory ) <EOL> else : <EOL> raise ValueError ( '<STR_LIT>' % tree . tag ) <EOL> def _build_graph ( self , graph_type , graph_args , linker , <EOL> docindex , context ) : <EOL> if graph_type == '<STR_LIT>' : <EOL> from epydoc . apidoc import ClassDoc <EOL> if graph_args : <EOL> bases = [ docindex . find ( name , context ) <EOL> for name in graph_args ] <EOL> elif isinstance ( context , ClassDoc ) : <EOL> bases = [ context ] <EOL> else : <EOL> log . warning ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> return None <EOL> from epydoc . docwriter . dotgraph import class_tree_graph <EOL> return class_tree_graph ( bases , linker , context ) <EOL> elif graph_type == '<STR_LIT>' : <EOL> from epydoc . apidoc import ModuleDoc <EOL> if graph_args : <EOL> packages = [ docindex . find ( name , context ) <EOL> for name in graph_args ] <EOL> elif isinstance ( context , ModuleDoc ) : <EOL> packages = [ context ] <EOL> else : <EOL> log . warning ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> return None <EOL> from epydoc . docwriter . dotgraph import package_tree_graph <EOL> return package_tree_graph ( packages , linker , context ) <EOL> elif graph_type == '<STR_LIT>' : <EOL> from epydoc . apidoc import ModuleDoc <EOL> modules = [ d for d in docindex . root if isinstance ( d , ModuleDoc ) ] <EOL> from epydoc . docwriter . dotgraph import import_graph <EOL> return import_graph ( modules , docindex , linker , context ) <EOL> elif graph_type == '<STR_LIT>' : <EOL> if graph_args : <EOL> docs = [ docindex . find ( name , context ) for name in graph_args ] <EOL> docs = [ doc for doc in docs if doc is not None ] <EOL> else : <EOL> docs = [ context ] <EOL> from epydoc . docwriter . dotgraph import call_graph <EOL> return call_graph ( docs , docindex , linker , context ) <EOL> else : <EOL> log . warning ( "<STR_LIT>" % graph_type ) <EOL> def _to_latex ( self , tree , linker , directory , docindex , context , <EOL> indent = <NUM_LIT:0> , seclevel = <NUM_LIT:0> , breakany = <NUM_LIT:0> ) : <EOL> if isinstance ( tree , basestring ) : <EOL> return plaintext_to_latex ( tree , breakany = breakany ) <EOL> if tree . tag == '<STR_LIT>' : seclevel += <NUM_LIT:1> <EOL> if tree . tag == '<STR_LIT>' : cindent = indent <EOL> else : cindent = indent + <NUM_LIT:2> <EOL> variables = [ self . _to_latex ( c , linker , directory , docindex , <EOL> context , cindent , seclevel , breakany ) <EOL> for c in tree . children ] <EOL> childstr = '<STR_LIT>' . join ( variables ) <EOL> if tree . tag == '<STR_LIT>' : <EOL> return wordwrap ( childstr , indent ) + '<STR_LIT:\n>' <EOL> elif tree . tag == '<STR_LIT:code>' : <EOL> return '<STR_LIT>' % childstr <EOL> elif tree . tag == '<STR_LIT>' : <EOL> if len ( variables ) != <NUM_LIT:2> : raise ValueError ( '<STR_LIT>' ) <EOL> if self . _hyperref : <EOL> uri = tree . children [ <NUM_LIT:1> ] . children [ <NUM_LIT:0> ] <EOL> uri = uri . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> uri = uri . replace ( '<STR_LIT>' , '<STR_LIT:#>' ) <EOL> if variables [ <NUM_LIT:0> ] == variables [ <NUM_LIT:1> ] : <EOL> return '<STR_LIT>' % ( uri , variables [ <NUM_LIT:1> ] ) <EOL> else : <EOL> return ( '<STR_LIT>' % <EOL> ( variables [ <NUM_LIT:0> ] , uri , variables [ <NUM_LIT:1> ] ) ) <EOL> else : <EOL> if variables [ <NUM_LIT:0> ] == variables [ <NUM_LIT:1> ] : <EOL> return '<STR_LIT>' % variables [ <NUM_LIT:1> ] <EOL> else : <EOL> return '<STR_LIT>' % ( variables [ <NUM_LIT:0> ] , variables [ <NUM_LIT:1> ] ) <EOL> elif tree . tag == '<STR_LIT>' : <EOL> if len ( variables ) != <NUM_LIT:2> : raise ValueError ( '<STR_LIT>' ) <EOL> return linker . translate_identifier_xref ( variables [ <NUM_LIT:1> ] , variables [ <NUM_LIT:0> ] ) <EOL> elif tree . tag == '<STR_LIT>' : <EOL> return '<STR_LIT>' % childstr <EOL> elif tree . tag == '<STR_LIT>' : <EOL> return '<STR_LIT>' % childstr <EOL> elif tree . tag == '<STR_LIT>' : <EOL> term = Element ( '<STR_LIT>' , * tree . children , ** tree . attribs ) <EOL> return linker . translate_indexterm ( ParsedEpytextDocstring ( term ) ) <EOL> elif tree . tag == '<STR_LIT>' : <EOL> return '<STR_LIT>' % childstr <EOL> elif tree . tag == '<STR_LIT>' : <EOL> return indent * '<STR_LIT:U+0020>' + '<STR_LIT>' + childstr . lstrip ( ) <EOL> elif tree . tag == '<STR_LIT>' : <EOL> sec = ( '<STR_LIT>' + <EOL> ( '<STR_LIT>' % ( '<STR_LIT>' * ( min ( seclevel , <NUM_LIT:3> ) - <NUM_LIT:1> ) ) ) . capitalize ( ) ) <EOL> return ( '<STR_LIT:U+0020>' * ( indent - <NUM_LIT:2> ) + '<STR_LIT>' % ( sec , childstr . strip ( ) ) ) <EOL> elif tree . tag == '<STR_LIT>' : <EOL> return doctest_to_latex ( tree . children [ <NUM_LIT:0> ] . strip ( ) ) <EOL> elif tree . tag == '<STR_LIT>' : <EOL> return '<STR_LIT>' % childstr <EOL> elif tree . tag == '<STR_LIT>' : <EOL> return indent * '<STR_LIT:U+0020>' + '<STR_LIT>' <EOL> elif tree . tag == '<STR_LIT>' : <EOL> return ( '<STR_LIT:U+0020>' * indent + '<STR_LIT>' + <EOL> '<STR_LIT:U+0020>' * indent + '<STR_LIT>' + <EOL> childstr + <EOL> '<STR_LIT:U+0020>' * indent + '<STR_LIT>' ) <EOL> elif tree . tag == '<STR_LIT>' : <EOL> return ( '<STR_LIT:U+0020>' * indent + '<STR_LIT>' + <EOL> '<STR_LIT:U+0020>' * indent + '<STR_LIT>' + <EOL> childstr + <EOL> '<STR_LIT:U+0020>' * indent + '<STR_LIT>' ) <EOL> elif tree . tag == '<STR_LIT>' : <EOL> symbol = tree . children [ <NUM_LIT:0> ] <EOL> return self . SYMBOL_TO_LATEX . get ( symbol , '<STR_LIT>' % symbol ) <EOL> elif tree . tag == '<STR_LIT>' : <EOL> if directory is None : return '<STR_LIT>' <EOL> graph = self . _build_graph ( variables [ <NUM_LIT:0> ] , variables [ <NUM_LIT:1> : ] , linker , <EOL> docindex , context ) <EOL> if not graph : return '<STR_LIT>' <EOL> return graph . to_latex ( directory ) <EOL> else : <EOL> return childstr <EOL> _SUMMARY_RE = re . compile ( r'<STR_LIT>' ) <EOL> def summary ( self ) : <EOL> if self . _tree is None : return self , False <EOL> tree = self . _tree <EOL> doc = Element ( '<STR_LIT>' ) <EOL> variables = tree . children <EOL> while ( len ( variables ) > <NUM_LIT:0> ) and ( variables [ <NUM_LIT:0> ] . tag != '<STR_LIT>' ) : <EOL> if variables [ <NUM_LIT:0> ] . tag in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> variables = variables [ <NUM_LIT:0> ] . children <EOL> else : <EOL> variables = variables [ <NUM_LIT:1> : ] <EOL> if ( len ( variables ) == <NUM_LIT:0> and len ( tree . children ) == <NUM_LIT:1> and <EOL> tree . children [ <NUM_LIT:0> ] . tag == '<STR_LIT>' ) : <EOL> str = re . split ( r'<STR_LIT>' , <EOL> tree . children [ <NUM_LIT:0> ] . children [ <NUM_LIT:0> ] , <NUM_LIT:1> ) [ <NUM_LIT:0> ] <EOL> variables = [ Element ( '<STR_LIT>' ) ] <EOL> variables [ <NUM_LIT:0> ] . children . append ( str ) <EOL> if len ( variables ) == <NUM_LIT:0> : return ParsedEpytextDocstring ( doc ) , False <EOL> long_docs = False <EOL> for var in variables [ <NUM_LIT:1> : ] : <EOL> if isinstance ( var , Element ) and var . tag == '<STR_LIT>' : <EOL> continue <EOL> long_docs = True <EOL> break <EOL> parachildren = variables [ <NUM_LIT:0> ] . children <EOL> para = Element ( '<STR_LIT>' , inline = True ) <EOL> doc . children . append ( para ) <EOL> for parachild in parachildren : <EOL> if isinstance ( parachild , basestring ) : <EOL> m = self . _SUMMARY_RE . match ( parachild ) <EOL> if m : <EOL> para . children . append ( m . group ( <NUM_LIT:1> ) ) <EOL> long_docs |= parachild is not parachildren [ - <NUM_LIT:1> ] <EOL> if not long_docs : <EOL> other = parachild [ m . end ( ) : ] <EOL> if other and not other . isspace ( ) : <EOL> long_docs = True <EOL> return ParsedEpytextDocstring ( doc ) , long_docs <EOL> para . children . append ( parachild ) <EOL> return ParsedEpytextDocstring ( doc ) , long_docs <EOL> def split_fields ( self , errors = None ) : <EOL> if self . _tree is None : return ( self , ( ) ) <EOL> tree = Element ( self . _tree . tag , * self . _tree . children , <EOL> ** self . _tree . attribs ) <EOL> fields = [ ] <EOL> if ( tree . children and <EOL> tree . children [ - <NUM_LIT:1> ] . tag == '<STR_LIT>' and <EOL> tree . children [ - <NUM_LIT:1> ] . children ) : <EOL> field_nodes = tree . children [ - <NUM_LIT:1> ] . children <EOL> del tree . children [ - <NUM_LIT:1> ] <EOL> for field in field_nodes : <EOL> tag = field . children [ <NUM_LIT:0> ] . children [ <NUM_LIT:0> ] . lower ( ) <EOL> del field . children [ <NUM_LIT:0> ] <EOL> if field . children and field . children [ <NUM_LIT:0> ] . tag == '<STR_LIT>' : <EOL> arg = field . children [ <NUM_LIT:0> ] . children [ <NUM_LIT:0> ] <EOL> del field . children [ <NUM_LIT:0> ] <EOL> else : <EOL> arg = None <EOL> field . tag = '<STR_LIT>' <EOL> fields . append ( Field ( tag , arg , ParsedEpytextDocstring ( field ) ) ) <EOL> if tree . children and tree . children [ <NUM_LIT:0> ] . children : <EOL> return ParsedEpytextDocstring ( tree ) , fields <EOL> else : <EOL> return None , fields <EOL> def index_terms ( self ) : <EOL> if self . _terms is None : <EOL> self . _terms = [ ] <EOL> self . _index_terms ( self . _tree , self . _terms ) <EOL> return self . _terms <EOL> def _index_terms ( self , tree , terms ) : <EOL> if tree is None or isinstance ( tree , basestring ) : <EOL> return <EOL> if tree . tag == '<STR_LIT>' : <EOL> term = Element ( '<STR_LIT>' , * tree . children , ** tree . attribs ) <EOL> terms . append ( ParsedEpytextDocstring ( term ) ) <EOL> for child in tree . children : <EOL> self . _index_terms ( child , terms ) </s>
