#NEWLINE# def get_graph_reference( ) : #NEWLINE# #INDENT# '\n    Attempts to load local copy of graph reference or makes GET request if DNE.\n\n    :return: (dict) The graph reference.\n    :raises: (PlotlyError) When graph reference DNE and GET request fails.\n\n    ' #NEWLINE# default_config = files . FILE_CONTENT [ files . CONFIG_FILE ] #NEWLINE# if files . check_file_permissions ( ) : #NEWLINE# #INDENT# graph_reference = utils . load_json_dict ( files . GRAPH_REFERENCE_FILE ) #NEWLINE# config = utils . load_json_dict ( files . CONFIG_FILE ) #NEWLINE# plotly_api_domain = config . get ( 'plotly_api_domain' , default_config [ 'plotly_api_domain' ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# graph_reference = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# plotly_api_domain = default_config [ 'plotly_api_domain' ] #NEWLINE# #UNINDENT# sha1 = hashlib . sha1 ( six . b ( str ( graph_reference ) ) ) . hexdigest ( ) #NEWLINE# graph_reference_url = '{}{}?sha1={}' . format ( plotly_api_domain , GRAPH_REFERENCE_PATH , sha1 ) #NEWLINE# try : #NEWLINE# #INDENT# response = requests . get ( graph_reference_url , timeout = GRAPH_REFERENCE_DOWNLOAD_TIMEOUT ) #NEWLINE# response . raise_for_status ( ) #NEWLINE# #UNINDENT# except requests . exceptions . RequestException : #NEWLINE# #INDENT# if ( not graph_reference ) : #NEWLINE# #INDENT# path = os . path . join ( 'graph_reference' , 'default-schema.json' ) #NEWLINE# s = resource_string ( 'plotly' , path ) . decode ( 'utf-8' ) #NEWLINE# graph_reference = json . loads ( s ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if six . PY3 : #NEWLINE# #INDENT# content = str ( response . content , encoding = 'utf-8' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# content = response . content #NEWLINE# #UNINDENT# data = json . loads ( content ) #NEWLINE# if data [ 'modified' ] : #NEWLINE# #INDENT# graph_reference = data [ 'schema' ] #NEWLINE# #UNINDENT# #UNINDENT# return utils . decode_unicode ( graph_reference )