<s> """<STR_LIT>""" <EOL> import inspect <EOL> import os <EOL> import re <EOL> import sys <EOL> from docutils import nodes <EOL> from sphinx import addnodes <EOL> def import_object ( modname , name ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> __import__ ( modname ) <EOL> mod = sys . modules [ modname ] <EOL> obj = mod <EOL> for part in name . split ( '<STR_LIT:.>' ) : <EOL> obj = getattr ( obj , part ) <EOL> return obj <EOL> except : <EOL> return None <EOL> def get_url_base ( app ) : <EOL> return '<STR_LIT>' % ( <EOL> app . config . edit_on_github_project , <EOL> app . config . edit_on_github_branch ) <EOL> def doctree_read ( app , doctree ) : <EOL> if app . config . edit_on_github_project == '<STR_LIT>' : <EOL> raise ValueError ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> source_root = app . config . edit_on_github_source_root <EOL> url = get_url_base ( app ) <EOL> docstring_message = app . config . edit_on_github_docstring_message <EOL> for objnode in doctree . traverse ( addnodes . desc ) : <EOL> if objnode . get ( '<STR_LIT>' ) != '<STR_LIT>' : <EOL> continue <EOL> names = set ( ) <EOL> for signode in objnode : <EOL> if not isinstance ( signode , addnodes . desc_signature ) : <EOL> continue <EOL> modname = signode . get ( '<STR_LIT>' ) <EOL> if not modname : <EOL> continue <EOL> fullname = signode . get ( '<STR_LIT>' ) <EOL> if fullname in names : <EOL> continue <EOL> names . add ( fullname ) <EOL> obj = import_object ( modname , fullname ) <EOL> anchor = None <EOL> if obj is not None : <EOL> try : <EOL> lines , lineno = inspect . getsourcelines ( obj ) <EOL> except : <EOL> pass <EOL> else : <EOL> anchor = '<STR_LIT>' % lineno <EOL> if anchor : <EOL> real_modname = inspect . getmodule ( obj ) . __name__ <EOL> path = '<STR_LIT>' % ( <EOL> url , source_root , real_modname . replace ( '<STR_LIT:.>' , '<STR_LIT:/>' ) , anchor ) <EOL> onlynode = addnodes . only ( expr = '<STR_LIT:html>' ) <EOL> onlynode += nodes . reference ( <EOL> reftitle = app . config . edit_on_github_help_message , <EOL> refuri = path ) <EOL> onlynode [ <NUM_LIT:0> ] += nodes . inline ( <EOL> '<STR_LIT>' , '<STR_LIT>' , nodes . raw ( '<STR_LIT>' , '<STR_LIT>' , format = '<STR_LIT:html>' ) , <EOL> nodes . Text ( docstring_message ) , <EOL> classes = [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> signode += onlynode <EOL> def html_page_context ( app , pagename , templatename , context , doctree ) : <EOL> if ( templatename == '<STR_LIT>' and <EOL> not re . match ( app . config . edit_on_github_skip_regex , pagename ) ) : <EOL> doc_root = app . config . edit_on_github_doc_root <EOL> if doc_root != '<STR_LIT>' and not doc_root . endswith ( '<STR_LIT:/>' ) : <EOL> doc_root += '<STR_LIT:/>' <EOL> doc_path = os . path . relpath ( doctree . get ( '<STR_LIT:source>' ) , app . builder . srcdir ) <EOL> url = get_url_base ( app ) <EOL> page_message = app . config . edit_on_github_page_message <EOL> context [ '<STR_LIT>' ] = url + doc_root + doc_path <EOL> context [ '<STR_LIT>' ] = ( <EOL> app . config . edit_on_github_page_message ) <EOL> def setup ( app ) : <EOL> app . add_config_value ( '<STR_LIT>' , '<STR_LIT>' , True ) <EOL> app . add_config_value ( '<STR_LIT>' , '<STR_LIT>' , True ) <EOL> app . add_config_value ( '<STR_LIT>' , '<STR_LIT>' , True ) <EOL> app . add_config_value ( '<STR_LIT>' , '<STR_LIT>' , True ) <EOL> app . add_config_value ( '<STR_LIT>' , <EOL> '<STR_LIT>' , True ) <EOL> app . add_config_value ( '<STR_LIT>' , <EOL> '<STR_LIT>' , True ) <EOL> app . add_config_value ( '<STR_LIT>' , <EOL> '<STR_LIT>' , True ) <EOL> app . add_config_value ( '<STR_LIT>' , <EOL> '<STR_LIT>' , True ) <EOL> app . connect ( '<STR_LIT>' , doctree_read ) <EOL> app . connect ( '<STR_LIT>' , html_page_context ) </s>
