#NEWLINE# def send( self , response_decoder = None ) : #NEWLINE# #INDENT# '\n        Creates and sends a request to the OAuth server, decodes the response\n        and returns the resulting token object.\n\n            response_decoder - A custom callable can be supplied to override\n              the default method of extracting AccessToken parameters from the\n              response. This is necessary for server implementations which do\n              not conform to the more recent OAuth2 specification\n              (ex: Facebook). By default, this will assume the response is\n              encoded using JSON. The callable should return a dictionary with\n              keys and values as follows:\n\n                access_token - The access token\n\n                token_type - The token type\n\n                expires_in - The number of seconds in which the token expires\n\n                refresh_token - The refresh token\n\n                scope - The permission scope (as a space delimited string)\n        ' #NEWLINE# decoder = loads #NEWLINE# if ( ( response_decoder is not None ) and callable ( response_decoder ) ) : #NEWLINE# #INDENT# decoder = response_decoder #NEWLINE# #UNINDENT# request = self . build_url_request ( ) #NEWLINE# try : #NEWLINE# #INDENT# f = urlopen ( request ) #NEWLINE# #UNINDENT# except HTTPError as e : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# error_resp = e . read ( ) #NEWLINE# error_data = loads ( error_resp ) #NEWLINE# #UNINDENT# except Exception : #NEWLINE# #INDENT# raise AccessTokenResponseError ( ( 'Access request returned an error, but the response could not be read: %s ' % error_resp ) ) #NEWLINE# #UNINDENT# if ( error_data . get ( 'error' ) is None ) : #NEWLINE# #INDENT# raise AccessTokenResponseError ( 'Access request returned an error, but did not include an error code' ) #NEWLINE# #UNINDENT# raise AccessTokenRequestError ( error_data [ 'error' ] , error_data . get ( 'error_description' ) , error_data . get ( 'error_uri' ) ) #NEWLINE# #UNINDENT# token_data = decoder ( f . read ( ) ) #NEWLINE# return self . _create_access_token ( token_data )