#NEWLINE# def _try_services( self , method_name , * args , **kwargs ) : #NEWLINE# #INDENT# '\n        Try each service until one returns a response. This function only\n        catches the bare minimum of exceptions from the service class. We want\n        exceptions to be raised so the service classes can be debugged and\n        fixed quickly.\n        ' #NEWLINE# if ( self . random_wait_seconds > 0 ) : #NEWLINE# #INDENT# pause_time = ( random . random ( ) * self . random_wait_seconds ) #NEWLINE# if self . verbose : #NEWLINE# #INDENT# print ( ( 'Pausing for: %.2f seconds' % pause_time ) ) #NEWLINE# #UNINDENT# time . sleep ( pause_time ) #NEWLINE# #UNINDENT# for service in self . services : #NEWLINE# #INDENT# crypto = ( ( args and args [ 0 ] ) or kwargs [ 'crypto' ] ) . lower ( ) #NEWLINE# address = kwargs . get ( 'address' , '' ) . lower ( ) #NEWLINE# fiat = kwargs . get ( 'fiat' , '' ) . lower ( ) #NEWLINE# if ( service . supported_cryptos and ( crypto not in service . supported_cryptos ) ) : #NEWLINE# #INDENT# if self . verbose : #NEWLINE# #INDENT# print ( 'SKIP:' , ( '%s not supported for %s' % ( crypto , service . __class__ . __name__ ) ) ) #NEWLINE# #UNINDENT# continue #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# if self . verbose : #NEWLINE# #INDENT# print ( '* Trying:' , service , crypto , ( '%s%s' % ( address , fiat ) ) ) #NEWLINE# #UNINDENT# ret = getattr ( service , method_name ) ( * args , ** kwargs ) #NEWLINE# self . _successful_service = service #NEWLINE# return ret #NEWLINE# #UNINDENT# except ( KeyError , IndexError , TypeError , ValueError , requests . exceptions . Timeout , requests . exceptions . SSLError ) as exc : #NEWLINE# #INDENT# if self . verbose : #NEWLINE# #INDENT# print ( 'FAIL:' , service , exc . __class__ . __name__ , exc ) #NEWLINE# #UNINDENT# self . _failed_services . append ( { #NEWLINE# #INDENT# 'service' : service , #NEWLINE# 'error' : ( '%s %s' % ( exc . __class__ . __name__ , exc ) ) , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# except SkipThisService as exc : #NEWLINE# #INDENT# if self . verbose : #NEWLINE# #INDENT# print ( 'SKIP:' , exc . __class__ . __name__ , exc ) #NEWLINE# #UNINDENT# self . _failed_services . append ( { #NEWLINE# #INDENT# 'service' : service , #NEWLINE# 'error' : 'Skipped' , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# except NotImplementedError as exc : #NEWLINE# #INDENT# if self . verbose : #NEWLINE# #INDENT# print ( 'SKIP:' , exc . __class__ . __name__ , exc ) #NEWLINE# #UNINDENT# self . _failed_services . append ( { #NEWLINE# #INDENT# 'service' : service , #NEWLINE# 'error' : 'Not Implemented' , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# #UNINDENT# if ( not self . _failed_services ) : #NEWLINE# #INDENT# raise NotImplementedError ( ( 'No Services defined for %s and %s' % ( crypto , method_name ) ) ) #NEWLINE# #UNINDENT# failed_msg = ', ' . join ( [ '{service.name} -> {error}' . format ( ** x ) for x in self . _failed_services ] ) #NEWLINE# raise NoService ( ( ( self . no_service_msg ( * args , ** kwargs ) + '! Tried: ' ) + failed_msg ) )