<s> """<STR_LIT>""" <EOL> import httplib <EOL> import json <EOL> import logging <EOL> class DiscoveryApiProxy ( object ) : <EOL> """<STR_LIT>""" <EOL> _DISCOVERY_PROXY_HOST = '<STR_LIT>' <EOL> _STATIC_PROXY_HOST = '<STR_LIT>' <EOL> _DISCOVERY_API_PATH_PREFIX = '<STR_LIT>' <EOL> def _dispatch_request ( self , path , body ) : <EOL> """<STR_LIT>""" <EOL> full_path = self . _DISCOVERY_API_PATH_PREFIX + path <EOL> headers = { '<STR_LIT>' : '<STR_LIT:application/json>' } <EOL> connection = httplib . HTTPSConnection ( self . _DISCOVERY_PROXY_HOST ) <EOL> try : <EOL> connection . request ( '<STR_LIT:POST>' , full_path , body , headers ) <EOL> response = connection . getresponse ( ) <EOL> response_body = response . read ( ) <EOL> if response . status != <NUM_LIT:200> : <EOL> logging . error ( '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> full_path , response . status , body , response_body ) <EOL> return None <EOL> return response_body <EOL> finally : <EOL> connection . close ( ) <EOL> def generate_discovery_doc ( self , api_config , api_format ) : <EOL> """<STR_LIT>""" <EOL> if api_format not in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> path = '<STR_LIT>' + api_format <EOL> request_dict = { '<STR_LIT>' : json . dumps ( api_config ) } <EOL> request_body = json . dumps ( request_dict ) <EOL> return self . _dispatch_request ( path , request_body ) <EOL> def generate_directory ( self , api_configs ) : <EOL> """<STR_LIT>""" <EOL> request_dict = { '<STR_LIT>' : api_configs } <EOL> request_body = json . dumps ( request_dict ) <EOL> return self . _dispatch_request ( '<STR_LIT>' , request_body ) <EOL> def get_static_file ( self , path ) : <EOL> """<STR_LIT>""" <EOL> connection = httplib . HTTPSConnection ( self . _STATIC_PROXY_HOST ) <EOL> try : <EOL> connection . request ( '<STR_LIT:GET>' , path , None , { } ) <EOL> response = connection . getresponse ( ) <EOL> response_body = response . read ( ) <EOL> finally : <EOL> connection . close ( ) <EOL> return response , response_body </s>
