<s> """<STR_LIT>""" <EOL> import os , re , pydoc <EOL> from docscrape_sphinx import get_doc_object , SphinxDocString <EOL> import inspect <EOL> def mangle_docstrings ( app , what , name , obj , options , lines , <EOL> reference_offset = [ <NUM_LIT:0> ] ) : <EOL> if what == '<STR_LIT>' : <EOL> title_re = re . compile ( r'<STR_LIT>' , <EOL> re . I | re . S ) <EOL> lines [ : ] = title_re . sub ( '<STR_LIT>' , "<STR_LIT:\n>" . join ( lines ) ) . split ( "<STR_LIT:\n>" ) <EOL> else : <EOL> doc = get_doc_object ( obj , what , "<STR_LIT:\n>" . join ( lines ) ) <EOL> lines [ : ] = str ( doc ) . split ( "<STR_LIT:\n>" ) <EOL> if app . config . numpydoc_edit_link and hasattr ( obj , '<STR_LIT>' ) and obj . __name__ : <EOL> if hasattr ( obj , '<STR_LIT>' ) : <EOL> v = dict ( full_name = "<STR_LIT>" % ( obj . __module__ , obj . __name__ ) ) <EOL> else : <EOL> v = dict ( full_name = obj . __name__ ) <EOL> lines += [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> lines += [ '<STR_LIT>' % x for x in <EOL> ( app . config . numpydoc_edit_link % v ) . split ( "<STR_LIT:\n>" ) ] <EOL> references = [ ] <EOL> for l in lines : <EOL> l = l . strip ( ) <EOL> if l . startswith ( '<STR_LIT>' ) : <EOL> try : <EOL> references . append ( int ( l [ len ( '<STR_LIT>' ) : l . index ( '<STR_LIT:]>' ) ] ) ) <EOL> except ValueError : <EOL> print "<STR_LIT>" % name <EOL> references . sort ( ) <EOL> if references : <EOL> for i , line in enumerate ( lines ) : <EOL> for r in references : <EOL> new_r = reference_offset [ <NUM_LIT:0> ] + r <EOL> lines [ i ] = lines [ i ] . replace ( '<STR_LIT>' % r , <EOL> '<STR_LIT>' % new_r ) <EOL> lines [ i ] = lines [ i ] . replace ( '<STR_LIT>' % r , <EOL> '<STR_LIT>' % new_r ) <EOL> reference_offset [ <NUM_LIT:0> ] += len ( references ) <EOL> def mangle_signature ( app , what , name , obj , options , sig , retann ) : <EOL> if ( inspect . isclass ( obj ) and <EOL> '<STR_LIT>' in pydoc . getdoc ( obj . __init__ ) ) : <EOL> return '<STR_LIT>' , '<STR_LIT>' <EOL> if not ( callable ( obj ) or hasattr ( obj , '<STR_LIT>' ) ) : return <EOL> if not hasattr ( obj , '<STR_LIT>' ) : return <EOL> doc = SphinxDocString ( pydoc . getdoc ( obj ) ) <EOL> if doc [ '<STR_LIT>' ] : <EOL> sig = re . sub ( "<STR_LIT>" , "<STR_LIT>" , doc [ '<STR_LIT>' ] ) <EOL> return sig , '<STR_LIT>' <EOL> def initialize ( app ) : <EOL> try : <EOL> app . connect ( '<STR_LIT>' , mangle_signature ) <EOL> except : <EOL> monkeypatch_sphinx_ext_autodoc ( ) <EOL> def setup ( app , get_doc_object_ = get_doc_object ) : <EOL> global get_doc_object <EOL> get_doc_object = get_doc_object_ <EOL> app . connect ( '<STR_LIT>' , mangle_docstrings ) <EOL> app . connect ( '<STR_LIT>' , initialize ) <EOL> app . add_config_value ( '<STR_LIT>' , None , True ) <EOL> def monkeypatch_sphinx_ext_autodoc ( ) : <EOL> global _original_format_signature <EOL> import sphinx . ext . autodoc <EOL> if sphinx . ext . autodoc . format_signature is our_format_signature : <EOL> return <EOL> print "<STR_LIT>" <EOL> _original_format_signature = sphinx . ext . autodoc . format_signature <EOL> sphinx . ext . autodoc . format_signature = our_format_signature <EOL> def our_format_signature ( what , obj ) : <EOL> r = mangle_signature ( None , what , None , obj , None , None , None ) <EOL> if r is not None : <EOL> return r [ <NUM_LIT:0> ] <EOL> else : <EOL> return _original_format_signature ( what , obj ) </s>
