<s> r"""<STR_LIT>""" <EOL> import os <EOL> import re <EOL> import sys <EOL> from string import punctuation as PUNCTUATION <EOL> from time import time <EOL> from docutils import nodes <EOL> from docutils . frontend import OptionParser <EOL> from docutils . io import FileInput <EOL> from docutils . parsers . rst import directives , Directive , DirectiveError , Parser <EOL> from docutils . parsers . rst . states import RSTStateMachine , state_classes <EOL> from docutils . readers . standalone import Reader <EOL> from docutils . transforms import writer_aux , universal , references , frontmatter <EOL> from docutils . transforms import misc <EOL> from docutils . writers . html4css1 import HTMLTranslator , Writer as HTMLWriter <EOL> from docutils . writers . latex2e import LaTeXTranslator , Writer as LaTexWriter <EOL> from docutils . utils import relative_path , new_document <EOL> from pygments import highlight <EOL> from pygments . formatters import HtmlFormatter <EOL> from pygments . lexers import get_lexer_by_name , TextLexer <EOL> from . . util . io import IteratorParser <EOL> HTML_VISITOR_ATTRIBUTES = ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:body>' , '<STR_LIT>' , <EOL> '<STR_LIT:title>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) <EOL> LATEX_VISITOR_ATTRIBUTES = ( <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:body>" , "<STR_LIT>" <EOL> ) <EOL> DEFAULT_TRANSFORMS = [ <EOL> universal . Decorations , <EOL> universal . ExposeInternals , <EOL> universal . StripComments , <EOL> references . Substitutions , <EOL> references . PropagateTargets , <EOL> frontmatter . DocTitle , <EOL> frontmatter . SectionSubTitle , <EOL> frontmatter . DocInfo , <EOL> references . AnonymousHyperlinks , <EOL> references . IndirectHyperlinks , <EOL> references . Footnotes , <EOL> references . ExternalTargets , <EOL> references . InternalTargets , <EOL> references . DanglingReferences , <EOL> misc . Transitions , <EOL> ] <EOL> HTML_TRANSFORMS = DEFAULT_TRANSFORMS + [ <EOL> universal . Messages , <EOL> universal . FilterMessages , <EOL> universal . StripClassesAndElements , <EOL> writer_aux . Admonitions , <EOL> ] <EOL> OPTION_PARSER = OptionParser ( ( Parser , Reader ) ) <EOL> HTML_OPTION_PARSER = OptionParser ( ( Parser , Reader , HTMLWriter ) ) <EOL> LATEX_OPTION_PARSER = OptionParser ( ( Parser , Reader , LaTexWriter ) ) <EOL> HTML_SETUP = ( '<STR_LIT:html>' , HTMLTranslator , HTML_TRANSFORMS , HTML_OPTION_PARSER ) <EOL> LATEX_SETUP = ( '<STR_LIT>' , LaTeXTranslator , DEFAULT_TRANSFORMS , LATEX_OPTION_PARSER ) <EOL> RAW_SETUP = ( None , None , DEFAULT_TRANSFORMS , OPTION_PARSER ) <EOL> replace_toc_attributes = re . compile ( <EOL> '<STR_LIT>' <EOL> ) . sub <EOL> replace_drop_shadows = re . compile ( <EOL> '<STR_LIT>' <EOL> ) . sub <EOL> replace_abstract_attributes = re . compile ( '<STR_LIT>' ) . sub <EOL> replace_ampersands = re . compile ( '<STR_LIT>' ) . sub <EOL> replace_comments = re . compile ( r'<STR_LIT>' ) . sub <EOL> replace_plexlinks = re . compile ( '<STR_LIT>' ) . sub <EOL> replace_title_headings = re . compile ( '<STR_LIT>' ) . sub <EOL> replace_whitespace = re . compile ( '<STR_LIT>' ) . sub <EOL> split_html_tags = re . compile ( '<STR_LIT>' ) . split <EOL> def imap_directive ( name , arguments , options , content , lineno , <EOL> content_offset , block_text , state , state_machine ) : <EOL> """<STR_LIT>""" <EOL> encoding = options . get ( '<STR_LIT>' , state . document . settings . input_encoding ) <EOL> image_alt = options . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> image_class = options . get ( '<STR_LIT:class>' , '<STR_LIT>' ) <EOL> attributes [ '<STR_LIT:source>' ] = imap_source = arguments [ <NUM_LIT:0> ] <EOL> source_dir = os . path . dirname ( <EOL> os . path . abspath ( state . document . current_source ) <EOL> ) <EOL> path = os . path . normpath ( os . path . join ( source_dir , imap_source ) ) <EOL> path = relative_path ( None , path ) <EOL> try : <EOL> state . document . settings . record_dependencies . add ( path ) <EOL> raw_file = FileInput ( <EOL> source_path = path , encoding = encoding , <EOL> error_handler = state . document . settings . input_encoding_error_handler , <EOL> handle_io_errors = None ) <EOL> except IOError , error : <EOL> severe = state_machine . reporter . severe ( <EOL> '<STR_LIT>' % ( name , error ) , <EOL> nodes . literal_block ( block_text , block_text ) , line = lineno ) <EOL> return [ severe ] <EOL> text = raw_file . read ( ) . replace ( <EOL> '<STR_LIT>' , image_alt ) . replace ( <EOL> '<STR_LIT>' , image_class ) <EOL> raw_node = nodes . raw ( '<STR_LIT>' , text , format = '<STR_LIT:html>' ) <EOL> return [ raw_node ] <EOL> imap_directive . arguments = ( <NUM_LIT:1> , <NUM_LIT:0> , False ) <EOL> imap_directive . options = { <EOL> '<STR_LIT>' : directives . unchanged , <EOL> '<STR_LIT:class>' : directives . class_option <EOL> } <EOL> imap_directive . content = False <EOL> def break_directive ( name , arguments , options , content , lineno , <EOL> content_offset , block_text , state , state_machine ) : <EOL> """<STR_LIT>""" <EOL> if arguments : <EOL> break_class = arguments [ <NUM_LIT:0> ] <EOL> else : <EOL> break_class = '<STR_LIT>' <EOL> raw_node = nodes . raw ( '<STR_LIT>' , '<STR_LIT>' % break_class , format = '<STR_LIT:html>' ) <EOL> return [ raw_node ] <EOL> break_directive . arguments = ( <NUM_LIT:0> , <NUM_LIT:1> , True ) <EOL> break_directive . options = { <EOL> '<STR_LIT:class>' : directives . class_option <EOL> } <EOL> break_directive . content = False <EOL> directives . register_directive ( '<STR_LIT>' , break_directive ) <EOL> SEEN_TAGS_CACHE = None <EOL> TAG_COUNTER = None <EOL> class TagDirective ( Directive ) : <EOL> """<STR_LIT>""" <EOL> required_arguments = <NUM_LIT:0> <EOL> optional_arguments = <NUM_LIT:1> <EOL> final_argument_whitespace = True <EOL> has_content = True <EOL> def run ( self , tag_cache = { } ) : <EOL> if not self . content : <EOL> return [ ] <EOL> if self . arguments : <EOL> arguments = self . arguments [ <NUM_LIT:0> ] . strip ( ) . split ( '<STR_LIT:U+002C>' ) <EOL> else : <EOL> arguments = [ ] <EOL> tag_list_id = CURRENT_PLAN_ID or '<STR_LIT:list>' <EOL> output = [ ] ; add = output . append <EOL> tag_id = None <EOL> for tag in arguments : <EOL> if tag in tag_cache : <EOL> add ( tag_cache [ tag ] ) <EOL> continue <EOL> ori_tag = tag <EOL> tag = tag . strip ( ) . rstrip ( u'<STR_LIT:U+002C>' ) . strip ( ) <EOL> if not tag : <EOL> continue <EOL> if tag . startswith ( '<STR_LIT>' ) : <EOL> tag_id = tag [ <NUM_LIT:3> : ] <EOL> continue <EOL> if tag . startswith ( '<STR_LIT:@>' ) : <EOL> tag_class = u'<STR_LIT:->' . join ( tag [ <NUM_LIT:1> : ] . lower ( ) . split ( ) ) <EOL> tag_type = '<STR_LIT>' <EOL> tag_text = tag <EOL> elif tag . startswith ( '<STR_LIT:#>' ) : <EOL> tag_class = u'<STR_LIT:->' . join ( tag [ <NUM_LIT:1> : ] . lower ( ) . split ( ) ) <EOL> tag_type = '<STR_LIT:2>' <EOL> tag_text = tag <EOL> elif '<STR_LIT::>' in tag : <EOL> tag_split = tag . split ( '<STR_LIT::>' , <NUM_LIT:1> ) <EOL> if len ( tag_split ) == <NUM_LIT:2> : <EOL> tag_type , tag_text = tag_split <EOL> else : <EOL> tag_type = tag_split [ <NUM_LIT:0> ] <EOL> tag_text = u"<STR_LIT>" <EOL> tag_type = tag_type . strip ( ) . lower ( ) <EOL> if tag_type == '<STR_LIT>' and '<STR_LIT::>' not in tag_text : <EOL> tag_class = u'<STR_LIT>' % ( CURRENT_PLAN_ID , tag_text ) <EOL> else : <EOL> tag_class = u'<STR_LIT:->' . join ( tag . replace ( '<STR_LIT::>' , '<STR_LIT:U+0020>' ) . lower ( ) . split ( ) ) <EOL> else : <EOL> tag_class = u'<STR_LIT:->' . join ( tag . lower ( ) . split ( ) ) <EOL> tag_type = '<STR_LIT:1>' <EOL> tag_text = tag . upper ( ) <EOL> if '<STR_LIT::>' in tag : <EOL> lead = tag . split ( '<STR_LIT::>' , <NUM_LIT:1> ) [ <NUM_LIT:0> ] <EOL> tag_name = '<STR_LIT>' % ( lead . lower ( ) , tag_text ) <EOL> else : <EOL> tag_name = tag_text <EOL> tag_span = ( <EOL> u'<STR_LIT>' % <EOL> ( tag_type , tag_class , tag_name , tag . lower ( ) , tag_text ) <EOL> ) <EOL> tag_cache [ ori_tag ] = tag_span <EOL> add ( tag_span ) <EOL> output . sort ( ) <EOL> if not tag_id : <EOL> global TAG_COUNTER <EOL> TAG_COUNTER = TAG_COUNTER + <NUM_LIT:1> <EOL> tag_id = '<STR_LIT>' % TAG_COUNTER <EOL> tag_id = '<STR_LIT>' % ( tag_list_id , tag_id ) <EOL> if tag_id in SEEN_TAGS_CACHE : <EOL> raise DirectiveError ( <NUM_LIT:2> , "<STR_LIT>" % tag_id ) <EOL> SEEN_TAGS_CACHE . add ( tag_id ) <EOL> if not output : <EOL> pass <EOL> output . append ( u'<STR_LIT>' % tag_id ) <EOL> output . insert ( <EOL> <NUM_LIT:0> , ( u'<STR_LIT>' % tag_id ) <EOL> ) <EOL> add ( u'<STR_LIT>' ) <EOL> tag_info = nodes . raw ( '<STR_LIT>' , u'<STR_LIT>' . join ( output ) , format = '<STR_LIT:html>' ) <EOL> tag_content_container = nodes . bullet_list ( <EOL> ids = [ '<STR_LIT>' % tag_id ] <EOL> ) <EOL> tag_content = nodes . list_item ( ) <EOL> self . state . nested_parse ( self . content , self . content_offset , tag_content ) <EOL> tag_content_container += tag_content <EOL> prefix = nodes . raw ( '<STR_LIT>' , u'<STR_LIT>' % tag_id , format = '<STR_LIT:html>' ) <EOL> suffix = nodes . raw ( '<STR_LIT>' , u'<STR_LIT>' , format = '<STR_LIT:html>' ) <EOL> return [ prefix , tag_content_container , tag_info , suffix ] <EOL> directives . register_directive ( '<STR_LIT>' , TagDirective ) <EOL> CURRENT_PLAN_ID = None <EOL> def plan_directive ( name , arguments , options , content , lineno , <EOL> content_offset , block_text , state , state_machine ) : <EOL> """<STR_LIT>""" <EOL> global CURRENT_PLAN_ID <EOL> if not CURRENT_PLAN_ID : <EOL> raw_node = nodes . raw ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> format = '<STR_LIT:html>' <EOL> ) <EOL> else : <EOL> raw_node = nodes . raw ( '<STR_LIT>' , '<STR_LIT>' , format = '<STR_LIT:html>' ) <EOL> CURRENT_PLAN_ID = arguments [ <NUM_LIT:0> ] <EOL> return [ raw_node ] <EOL> plan_directive . arguments = ( <NUM_LIT:1> , <NUM_LIT:0> , True ) <EOL> plan_directive . options = { } <EOL> plan_directive . content = False <EOL> directives . register_directive ( '<STR_LIT>' , plan_directive ) <EOL> SYNTAX_FORMATTER = HtmlFormatter ( cssclass = '<STR_LIT>' , lineseparator = '<STR_LIT>' ) <EOL> def syntax_directive ( name , arguments , options , content , lineno , <EOL> content_offset , block_text , state , state_machine ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> lexer = get_lexer_by_name ( arguments [ <NUM_LIT:0> ] ) <EOL> except ValueError : <EOL> lexer = TextLexer ( ) <EOL> return [ nodes . raw ( <EOL> '<STR_LIT>' , <EOL> highlight ( u'<STR_LIT:\n>' . join ( content ) , lexer , SYNTAX_FORMATTER ) , <EOL> format = '<STR_LIT:html>' <EOL> ) ] <EOL> syntax_directive . arguments = ( <NUM_LIT:1> , <NUM_LIT:0> , False ) <EOL> syntax_directive . options = { <EOL> '<STR_LIT>' : directives . unchanged <EOL> } <EOL> syntax_directive . content = True <EOL> directives . register_directive ( '<STR_LIT>' , syntax_directive ) <EOL> def doctest2html ( content ) : <EOL> """<STR_LIT>""" <EOL> out = [ ] <EOL> for line in content . splitlines ( ) : <EOL> if line . startswith ( '<STR_LIT>' ) or line . startswith ( '<STR_LIT>' ) : <EOL> line = '<STR_LIT>' + line + '<STR_LIT>' <EOL> elif line : <EOL> line = '<STR_LIT>' + line + '<STR_LIT>' <EOL> out . append ( line ) <EOL> return '<STR_LIT:\n>' . join ( out ) <EOL> def convert ( content ) : <EOL> """<STR_LIT>""" <EOL> content = content . replace ( <EOL> '<STR_LIT>' , '<STR_LIT:">' ) . replace ( <EOL> '<STR_LIT>' , '<STR_LIT>' ) . replace ( <EOL> '<STR_LIT>' , '<STR_LIT>' ) . replace ( <EOL> '<STR_LIT>' , '<STR_LIT>' ) . replace ( <EOL> '<STR_LIT>' , '<STR_LIT>' ) . replace ( <EOL> '<STR_LIT>' , '<STR_LIT>' ) . replace ( <EOL> '<STR_LIT>' , '<STR_LIT>' ) . replace ( <EOL> '<STR_LIT>' , '<STR_LIT>' ) . replace ( <EOL> '<STR_LIT>' , '<STR_LIT>' ) . replace ( <EOL> '<STR_LIT>' , '<STR_LIT>' ) . replace ( <EOL> '<STR_LIT>' , '<STR_LIT>' ) . replace ( <EOL> '<STR_LIT>' , '<STR_LIT>' ) . replace ( <EOL> '<STR_LIT>' , '<STR_LIT>' ) . replace ( <EOL> '<STR_LIT>' , '<STR_LIT>' ) . replace ( <EOL> '<STR_LIT>' , '<STR_LIT>' ) . replace ( <EOL> '<STR_LIT>' , '<STR_LIT>' ) <EOL> icontent = IteratorParser ( content ) <EOL> content = [ ] <EOL> _scurly = _dcurly = False <EOL> _space = True <EOL> _apply = False <EOL> index = <NUM_LIT:0> <EOL> prev = '<STR_LIT>' <EOL> while True : <EOL> try : <EOL> char = icontent . next ( ) <EOL> except StopIteration : <EOL> break <EOL> if not ( _scurly or _dcurly ) and _space : <EOL> if char == "<STR_LIT:'>" : <EOL> _scurly = index + <NUM_LIT:1> <EOL> elif char == '<STR_LIT:">' : <EOL> _dcurly = index + <NUM_LIT:1> <EOL> if _scurly and ( _scurly != index + <NUM_LIT:1> ) and char == "<STR_LIT:'>" and prev != '<STR_LIT:\\>' : <EOL> try : <EOL> n = icontent . next ( ) <EOL> if n in PUNCTUATION or n . isspace ( ) : <EOL> _apply = True <EOL> icontent . push ( n ) <EOL> except : <EOL> _apply = True <EOL> if _apply : <EOL> content [ _scurly - <NUM_LIT:1> ] = '<STR_LIT>' <EOL> char = '<STR_LIT>' <EOL> _scurly = False <EOL> _apply = False <EOL> if _dcurly and ( _dcurly != index + <NUM_LIT:1> ) and char == '<STR_LIT:">' and prev != '<STR_LIT:\\>' : <EOL> try : <EOL> n = icontent . next ( ) <EOL> if n in PUNCTUATION or n . isspace ( ) : <EOL> _apply = True <EOL> icontent . push ( n ) <EOL> except : <EOL> _apply = True <EOL> if _apply : <EOL> content [ _dcurly - <NUM_LIT:1> ] = '<STR_LIT>' <EOL> char = '<STR_LIT>' <EOL> _dcurly = False <EOL> _apply = False <EOL> content . append ( char ) <EOL> prev = char <EOL> index += <NUM_LIT:1> <EOL> if char . isspace ( ) : <EOL> _space = True <EOL> else : <EOL> _space = False <EOL> content = '<STR_LIT>' . join ( content ) . replace ( '<STR_LIT:">' , '<STR_LIT>' ) <EOL> content = replace_plexlinks ( render_plexlink , content ) <EOL> return content <EOL> def escape_and_prettify ( content ) : <EOL> """<STR_LIT>""" <EOL> _literal_block = _element = _content = False <EOL> output = [ ] <EOL> for i , block in enumerate ( split_html_tags ( content . strip ( ) ) ) : <EOL> if i % <NUM_LIT:2> : <EOL> _content = False <EOL> _element = True <EOL> if _literal_block and ( _literal_block [ <NUM_LIT:1> ] == block ) : <EOL> _literal_block = False <EOL> if block == '<STR_LIT>' : <EOL> _literal_block = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> elif block in [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] : <EOL> _literal_block = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> elif block in [ '<STR_LIT>' ] : <EOL> _literal_block = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> elif block == '<STR_LIT>' : <EOL> _literal_block = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> elif block == '<STR_LIT>' : <EOL> _literal_block = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> elif block == '<STR_LIT>' : <EOL> _literal_block = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> else : <EOL> _content = True <EOL> _element = False <EOL> if _element : <EOL> output . append ( '<STR_LIT:<>' + block + '<STR_LIT:>>' ) <EOL> elif _content : <EOL> if _literal_block : <EOL> if _literal_block [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> output . append ( doctest2html ( block ) ) <EOL> else : <EOL> output . append ( block ) <EOL> else : <EOL> output . append ( convert ( block ) ) <EOL> output = '<STR_LIT>' . join ( output ) <EOL> output = output . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> output = replace_ampersands ( '<STR_LIT>' , output ) <EOL> return output <EOL> def render_drop_cap ( content ) : <EOL> """<STR_LIT>""" <EOL> content = content . groups ( ) [ <NUM_LIT:0> ] <EOL> if content : <EOL> if len ( content ) >= <NUM_LIT:2> : <EOL> return '<STR_LIT>' + content [ <NUM_LIT:0> ] + '<STR_LIT>' + content [ <NUM_LIT:1> : ] <EOL> return '<STR_LIT>' <EOL> def render_plexlink ( content ) : <EOL> """<STR_LIT>""" <EOL> name = content . groups ( ) [ <NUM_LIT:0> ] <EOL> if '<STR_LIT:|>' in name : <EOL> name , linkname = name . split ( '<STR_LIT:|>' , <NUM_LIT:1> ) <EOL> else : <EOL> linkname = name <EOL> return u'<STR_LIT>' % ( u'<STR_LIT:->' . join ( name . split ( ) ) , linkname ) <EOL> def parse_headers ( source_lines , props , toplevel = False ) : <EOL> """<STR_LIT>""" <EOL> new_data = [ ] ; out = new_data . append <EOL> iterative_source = IteratorParser ( source_lines ) <EOL> for line in iterative_source : <EOL> if line . startswith ( '<STR_LIT::>' ) and line . find ( '<STR_LIT::>' , <NUM_LIT:2> ) != - <NUM_LIT:1> : <EOL> marker = line . find ( '<STR_LIT::>' , <NUM_LIT:2> ) <EOL> prop , value = line [ <NUM_LIT:1> : marker ] , line [ marker + <NUM_LIT:1> : ] . strip ( ) <EOL> if prop . lower ( ) . startswith ( '<STR_LIT>' ) : <EOL> _strip_prop = True <EOL> else : <EOL> _strip_prop = False <EOL> if not _strip_prop : <EOL> out ( line ) <EOL> while True : <EOL> try : <EOL> line = iterative_source . next ( ) <EOL> if not _strip_prop : <EOL> out ( line ) <EOL> except : <EOL> break <EOL> sline = line . strip ( ) <EOL> if sline and not ( sline . startswith ( '<STR_LIT::>' ) and sline . find ( '<STR_LIT::>' , <NUM_LIT:2> ) != - <NUM_LIT:1> ) : <EOL> value += '<STR_LIT:U+0020>' + sline <EOL> else : <EOL> iterative_source . push ( line ) <EOL> if not _strip_prop : <EOL> del new_data [ - <NUM_LIT:1> ] <EOL> break <EOL> prop = prop . lower ( ) <EOL> if prop in props : <EOL> oldvalue = props [ prop ] <EOL> if isinstance ( oldvalue , list ) : <EOL> oldvalue . append ( value ) <EOL> else : <EOL> props [ prop ] = [ oldvalue , value ] <EOL> else : <EOL> props [ prop ] = value <EOL> else : <EOL> out ( line ) <EOL> return new_data , props <EOL> def render_rst ( <EOL> source , format = '<STR_LIT>' , encoding = '<STR_LIT:utf-8>' , with_props = False , <EOL> with_docinfo = False , as_whole = False <EOL> ) : <EOL> """<STR_LIT>""" <EOL> global SEEN_TAGS_CACHE , TAG_COUNTER , CURRENT_PLAN_ID <EOL> SEEN_TAGS_CACHE = set ( ) <EOL> TAG_COUNTER = <NUM_LIT:0> <EOL> CURRENT_PLAN_ID = None <EOL> if format in ( '<STR_LIT>' , '<STR_LIT:html>' ) : <EOL> format , translator , transforms , option_parser = HTML_SETUP <EOL> elif format in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> format , translator , transforms , option_parser = LATEX_SETUP <EOL> elif format == '<STR_LIT>' : <EOL> format , translator , transforms , option_parser = RAW_SETUP <EOL> else : <EOL> raise ValueError ( "<STR_LIT>" % format ) <EOL> settings = option_parser . get_default_values ( ) <EOL> settings . _update_loose ( { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:6> , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> } ) <EOL> document = new_document ( '<STR_LIT>' , settings ) <EOL> if not isinstance ( source , unicode ) : <EOL> source = unicode ( source , encoding ) <EOL> source = replace_whitespace ( '<STR_LIT:U+0020>' , source ) <EOL> source_lines = [ s . expandtabs ( <NUM_LIT:4> ) . rstrip ( ) for s in source . splitlines ( ) ] <EOL> if with_props : <EOL> source_lines , props = parse_headers ( source_lines , { } , True ) <EOL> document . reporter . attach_observer ( document . note_parse_message ) <EOL> RSTStateMachine ( <EOL> state_classes = state_classes , <EOL> initial_state = '<STR_LIT>' , <EOL> ) . run ( source_lines , document ) <EOL> document . reporter . detach_observer ( document . note_parse_message ) <EOL> document . current_source = document . current_line = None <EOL> document . transformer . add_transforms ( transforms ) <EOL> document . transformer . apply_transforms ( ) <EOL> if not format : <EOL> return unicode ( document ) <EOL> visitor = translator ( document ) <EOL> document . walkabout ( visitor ) <EOL> if as_whole : <EOL> output = visitor . astext ( ) <EOL> else : <EOL> if format == '<STR_LIT:html>' and with_docinfo : <EOL> output = ( <EOL> u'<STR_LIT>' <EOL> % ( u'<STR_LIT>' . join ( visitor . docinfo ) , u'<STR_LIT>' . join ( visitor . body ) ) <EOL> ) <EOL> else : <EOL> output = u'<STR_LIT>' . join ( visitor . body ) <EOL> if format == '<STR_LIT:html>' : <EOL> output = escape_and_prettify ( output ) <EOL> output = replace_toc_attributes ( <EOL> '<STR_LIT>' , <EOL> output ) <EOL> output = replace_abstract_attributes ( <EOL> r'<STR_LIT>' , <EOL> output ) <EOL> output = replace_drop_shadows ( <EOL> r'<STR_LIT>' , <EOL> output ) <EOL> output = replace_comments ( '<STR_LIT>' , output ) <EOL> output = replace_title_headings ( '<STR_LIT>' , output ) <EOL> if with_props : <EOL> if format == '<STR_LIT:html>' : <EOL> props . setdefault ( u'<STR_LIT:title>' , visitor . title and visitor . title [ <NUM_LIT:0> ] or u'<STR_LIT>' ) <EOL> props . setdefault ( u'<STR_LIT>' , visitor . subtitle and visitor . subtitle [ <NUM_LIT:0> ] or u'<STR_LIT>' ) <EOL> return output , props <EOL> return output </s>
