<s> """<STR_LIT>""" <EOL> __docformat__ = '<STR_LIT>' <EOL> import tempfile , re , os , os . path , textwrap , sys <EOL> from epydoc . docbuilder import build_doc , build_doc_index <EOL> from epydoc . docparser import parse_docs <EOL> from epydoc . docintrospecter import introspect_docs <EOL> from epydoc . apidoc import ClassDoc , RoutineDoc <EOL> from epydoc . markup import ParsedDocstring <EOL> from epydoc . docwriter . html import HTMLWriter <EOL> def buildvaluedoc ( s ) : <EOL> """<STR_LIT>""" <EOL> tmp_dir = write_pystring_to_tmp_dir ( s ) <EOL> val_doc = build_doc ( os . path . join ( tmp_dir , '<STR_LIT>' ) ) <EOL> cleanup_tmp_dir ( tmp_dir ) <EOL> return val_doc <EOL> def runbuilder ( s , attribs = '<STR_LIT>' , build = None , exclude = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> tmp_dir = write_pystring_to_tmp_dir ( s ) <EOL> val_doc = build_doc ( os . path . join ( tmp_dir , '<STR_LIT>' ) ) <EOL> if build : val_doc = val_doc . variables [ build ] . value <EOL> if isinstance ( val_doc , ClassDoc ) : <EOL> for val in val_doc . variables . values ( ) : <EOL> if isinstance ( val . value , RoutineDoc ) : <EOL> fun_to_plain ( val . value ) <EOL> s = val_doc . pp ( include = attribs . split ( ) , exclude = exclude . split ( ) ) <EOL> s = re . sub ( r"<STR_LIT>" , r"<STR_LIT>" , s ) <EOL> s = re . sub ( r"<STR_LIT>" , r'<STR_LIT>' , s ) <EOL> s = re . sub ( r"<STR_LIT>" , r"<STR_LIT>" , s ) <EOL> s = re . sub ( r"<STR_LIT>" , r"<STR_LIT>" , s ) <EOL> print s <EOL> cleanup_tmp_dir ( tmp_dir ) <EOL> def runparser ( s , attribs = '<STR_LIT>' , show = None , exclude = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> tmp_dir = write_pystring_to_tmp_dir ( s ) <EOL> val_doc = parse_docs ( os . path . join ( tmp_dir , '<STR_LIT>' ) ) <EOL> if show is not None : <EOL> for name in show . split ( '<STR_LIT:.>' ) : <EOL> if isinstance ( val_doc , ClassDoc ) : <EOL> val_doc = val_doc . local_variables [ name ] . value <EOL> else : <EOL> val_doc = val_doc . variables [ name ] . value <EOL> s = val_doc . pp ( include = attribs . split ( ) , exclude = exclude . split ( ) ) <EOL> s = re . sub ( r"<STR_LIT>" , "<STR_LIT>" , s ) <EOL> print s <EOL> cleanup_tmp_dir ( tmp_dir ) <EOL> def runintrospecter ( s , attribs = '<STR_LIT>' , introspect = None , exclude = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> tmp_dir = write_pystring_to_tmp_dir ( s ) <EOL> sys . path . insert ( <NUM_LIT:0> , tmp_dir ) <EOL> if introspect is None : <EOL> import epydoc_test as val <EOL> else : <EOL> exec ( "<STR_LIT>" % introspect ) <EOL> del sys . path [ <NUM_LIT:0> ] <EOL> val_doc = introspect_docs ( val ) <EOL> s = val_doc . pp ( include = attribs . split ( ) , exclude = exclude . split ( ) ) <EOL> s = re . sub ( r"<STR_LIT>" , r"<STR_LIT>" , s ) <EOL> s = re . sub ( r"<STR_LIT>" , r'<STR_LIT>' , s ) <EOL> s = re . sub ( r"<STR_LIT>" , r"<STR_LIT>" , s ) <EOL> s = re . sub ( r"<STR_LIT>" , r"<STR_LIT>" , s ) <EOL> print s <EOL> cleanup_tmp_dir ( tmp_dir ) <EOL> def print_warnings ( ) : <EOL> """<STR_LIT>""" <EOL> from epydoc import log <EOL> del log . _loggers [ : ] <EOL> log . register_logger ( log . SimpleLogger ( log . DOCSTRING_WARNING ) ) <EOL> def testencoding ( s , introspect = True , parse = True , debug = False ) : <EOL> """<STR_LIT>""" <EOL> original_docstring_to_html = HTMLWriter . docstring_to_html <EOL> HTMLWriter . docstring_to_html = print_docstring_as_html <EOL> tmp_dir = tempfile . mkdtemp ( ) <EOL> path = os . path . join ( tmp_dir , '<STR_LIT>' ) <EOL> out = open ( path , '<STR_LIT:w>' ) <EOL> out . write ( textwrap . dedent ( s ) ) <EOL> out . close ( ) <EOL> docindex = build_doc_index ( [ path ] , introspect , parse ) <EOL> if docindex is None : return <EOL> sys . modules . pop ( '<STR_LIT>' , None ) <EOL> writer = HTMLWriter ( docindex , mark_docstrings = True ) <EOL> writer . write ( tmp_dir ) <EOL> for file in os . listdir ( tmp_dir ) : <EOL> os . unlink ( os . path . join ( tmp_dir , file ) ) <EOL> os . rmdir ( tmp_dir ) <EOL> HTMLWriter . docstring_to_html = original_docstring_to_html <EOL> def write_pystring_to_tmp_dir ( s ) : <EOL> tmp_dir = tempfile . mkdtemp ( ) <EOL> out = open ( os . path . join ( tmp_dir , '<STR_LIT>' ) , '<STR_LIT:w>' ) <EOL> out . write ( textwrap . dedent ( s ) ) <EOL> out . close ( ) <EOL> return tmp_dir <EOL> def cleanup_tmp_dir ( tmp_dir ) : <EOL> os . unlink ( os . path . join ( tmp_dir , '<STR_LIT>' ) ) <EOL> try : os . unlink ( os . path . join ( tmp_dir , '<STR_LIT>' ) ) <EOL> except OSError : pass <EOL> os . rmdir ( tmp_dir ) <EOL> sys . modules . pop ( '<STR_LIT>' , None ) <EOL> def to_plain ( docstring ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( docstring , ParsedDocstring ) : <EOL> docstring = docstring . to_plaintext ( None ) <EOL> return docstring . rstrip ( ) <EOL> def fun_to_plain ( val_doc ) : <EOL> """<STR_LIT>""" <EOL> for k , v in val_doc . arg_types . items ( ) : <EOL> val_doc . arg_types [ k ] = to_plain ( v ) <EOL> for i , ( k , v ) in enumerate ( val_doc . arg_descrs ) : <EOL> val_doc . arg_descrs [ i ] = ( k , to_plain ( v ) ) <EOL> def print_docstring_as_html ( self , parsed_docstring , * varargs , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> s = parsed_docstring . to_html ( None ) . strip ( ) <EOL> s = s . encode ( '<STR_LIT:ascii>' , '<STR_LIT>' ) <EOL> s = remove_surrogates ( s ) <EOL> print s <EOL> return '<STR_LIT>' <EOL> def remove_surrogates ( s ) : <EOL> """<STR_LIT>""" <EOL> pieces = re . split ( '<STR_LIT>' , s ) <EOL> for i in range ( <NUM_LIT:3> , len ( pieces ) - <NUM_LIT:1> , <NUM_LIT:2> ) : <EOL> if pieces [ i - <NUM_LIT:1> ] != '<STR_LIT>' : continue <EOL> high , low = int ( pieces [ i - <NUM_LIT:2> ] [ <NUM_LIT:2> : - <NUM_LIT:1> ] ) , int ( pieces [ i ] [ <NUM_LIT:2> : - <NUM_LIT:1> ] ) <EOL> if <NUM_LIT> <= high <= <NUM_LIT> and <NUM_LIT> <= low <= <NUM_LIT> : <EOL> pieces [ i - <NUM_LIT:2> ] = '<STR_LIT>' % ( ( ( high & <NUM_LIT> ) << <NUM_LIT:10> ) + <EOL> ( low & <NUM_LIT> ) + <NUM_LIT> ) <EOL> pieces [ i ] = '<STR_LIT>' <EOL> return '<STR_LIT>' . join ( pieces ) </s>
