 """<STR_LIT>""" <EOL> class UnsupportedVersion ( Exception ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class UnsupportedAttribute ( AttributeError ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , argument_name , start_version , end_version = None ) : <EOL> if end_version : <EOL> self . message = ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % { "<STR_LIT:name>" : argument_name , <EOL> "<STR_LIT:start>" : start_version , <EOL> "<STR_LIT:end>" : end_version } ) <EOL> else : <EOL> self . message = ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % { "<STR_LIT:name>" : argument_name , "<STR_LIT:start>" : start_version } ) <EOL> class CommandError ( Exception ) : <EOL> pass <EOL> class AuthorizationFailure ( Exception ) : <EOL> pass <EOL> class NoUniqueMatch ( Exception ) : <EOL> pass <EOL> class AuthSystemNotFound ( Exception ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , auth_system ) : <EOL> self . auth_system = auth_system <EOL> def __str__ ( self ) : <EOL> return "<STR_LIT>" % repr ( self . auth_system ) <EOL> class NoTokenLookupException ( Exception ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class EndpointNotFound ( Exception ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class AmbiguousEndpoints ( Exception ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , endpoints = None ) : <EOL> self . endpoints = endpoints <EOL> def __str__ ( self ) : <EOL> return "<STR_LIT>" % repr ( self . endpoints ) <EOL> class ConnectionRefused ( Exception ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , response = None ) : <EOL> self . response = response <EOL> def __str__ ( self ) : <EOL> return "<STR_LIT>" % repr ( self . response ) <EOL> class ResourceInErrorState ( Exception ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , obj ) : <EOL> msg = "<STR_LIT>" % obj . __class__ . __name__ <EOL> fault_msg = getattr ( obj , "<STR_LIT>" , { } ) . get ( "<STR_LIT:message>" ) <EOL> if fault_msg : <EOL> msg += "<STR_LIT>" % fault_msg <EOL> self . message = "<STR_LIT>" % msg <EOL> class VersionNotFoundForAPIMethod ( Exception ) : <EOL> msg_fmt = "<STR_LIT>" <EOL> def __init__ ( self , version , method ) : <EOL> self . version = version <EOL> self . method = method <EOL> def __str__ ( self ) : <EOL> return self . msg_fmt % { "<STR_LIT>" : self . version , "<STR_LIT>" : self . method } <EOL> class InstanceInDeletedState ( Exception ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class ClientException ( Exception ) : <EOL> """<STR_LIT>""" <EOL> message = '<STR_LIT>' <EOL> def __init__ ( self , code , message = None , details = None , request_id = None , <EOL> url = None , method = None ) : <EOL> self . code = code <EOL> self . message = message or self . __class__ . message <EOL> self . details = details <EOL> self . request_id = request_id <EOL> self . url = url <EOL> self . method = method <EOL> def __str__ ( self ) : <EOL> formatted_string = "<STR_LIT>" % ( self . message , self . code ) <EOL> if self . request_id : <EOL> formatted_string += "<STR_LIT>" % self . request_id <EOL> return formatted_string <EOL> class RetryAfterException ( ClientException ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> try : <EOL> self . retry_after = int ( kwargs . pop ( '<STR_LIT>' ) ) <EOL> except ( KeyError , ValueError ) : <EOL> self . retry_after = <NUM_LIT:0> <EOL> super ( RetryAfterException , self ) . __init__ ( * args , ** kwargs ) <EOL> class BadRequest ( ClientException ) : <EOL> """<STR_LIT>""" <EOL> http_status = <NUM_LIT> <EOL> message = "<STR_LIT>" <EOL> class Unauthorized ( ClientException ) : <EOL> """<STR_LIT>""" <EOL> http_status = <NUM_LIT> <EOL> message = "<STR_LIT>" <EOL> class Forbidden ( ClientException ) : <EOL> """<STR_LIT>""" <EOL> http_status = <NUM_LIT> <EOL> message = "<STR_LIT>" <EOL> class NotFound ( ClientException ) : <EOL> """<STR_LIT>""" <EOL> http_status = <NUM_LIT> <EOL> message = "<STR_LIT>" <EOL> class MethodNotAllowed ( ClientException ) : <EOL> """<STR_LIT>""" <EOL> http_status = <NUM_LIT> 
 message = "<STR_LIT>" 
 """<STR_LIT>""" <EOL> class UnsupportedVersion ( Exception ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class UnsupportedAttribute ( AttributeError ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , argument_name , start_version , end_version = None ) : <EOL> if end_version : <EOL> self . message = ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % { "<STR_LIT:name>" : argument_name , <EOL> "<STR_LIT:start>" : start_version , <EOL> "<STR_LIT:end>" : end_version } ) <EOL> else : <EOL> self . message = ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % { "<STR_LIT:name>" : argument_name , "<STR_LIT:start>" : start_version } ) <EOL> class CommandError ( Exception ) : <EOL> pass <EOL> class AuthorizationFailure ( Exception ) : <EOL> pass <EOL> class NoUniqueMatch ( Exception ) : <EOL> pass <EOL> class AuthSystemNotFound ( Exception ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , auth_system ) : <EOL> self . auth_system = auth_system <EOL> def __str__ ( self ) : <EOL> return "<STR_LIT>" % repr ( self . auth_system ) <EOL> class NoTokenLookupException ( Exception ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class EndpointNotFound ( Exception ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class AmbiguousEndpoints ( Exception ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , endpoints = None ) : <EOL> self . endpoints = endpoints <EOL> def __str__ ( self ) : <EOL> return "<STR_LIT>" % repr ( self . endpoints ) <EOL> class ConnectionRefused ( Exception ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , response = None ) : <EOL> self . response = response <EOL> def __str__ ( self ) : <EOL> return "<STR_LIT>" % repr ( self . response ) <EOL> class ResourceInErrorState ( Exception ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , obj ) : <EOL> msg = "<STR_LIT>" % obj . __class__ . __name__ <EOL> fault_msg = getattr ( obj , "<STR_LIT>" , { } ) . get ( "<STR_LIT:message>" ) <EOL> if fault_msg : <EOL> msg += "<STR_LIT>" % fault_msg <EOL> self . message = "<STR_LIT>" % msg <EOL> class VersionNotFoundForAPIMethod ( Exception ) : <EOL> msg_fmt = "<STR_LIT>" <EOL> def __init__ ( self , version , method ) : <EOL> self . version = version <EOL> self . method = method <EOL> def __str__ ( self ) : <EOL> return self . msg_fmt % { "<STR_LIT>" : self . version , "<STR_LIT>" : self . method } <EOL> class InstanceInDeletedState ( Exception ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class ClientException ( Exception ) : <EOL> """<STR_LIT>""" <EOL> message = '<STR_LIT>' <EOL> def __init__ ( self , code , message = None , details = None , request_id = None , <EOL> url = None , method = None ) : <EOL> self . code = code <EOL> self . message = message or self . __class__ . message <EOL> self . details = details <EOL> self . request_id = request_id <EOL> self . url = url <EOL> self . method = method <EOL> def __str__ ( self ) : <EOL> formatted_string = "<STR_LIT>" % ( self . message , self . code ) <EOL> if self . request_id : <EOL> formatted_string += "<STR_LIT>" % self . request_id <EOL> return formatted_string <EOL> class RetryAfterException ( ClientException ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> try : <EOL> self . retry_after = int ( kwargs . pop ( '<STR_LIT>' ) ) <EOL> except ( KeyError , ValueError ) : <EOL> self . retry_after = <NUM_LIT:0> <EOL> super ( RetryAfterException , self ) . __init__ ( * args , ** kwargs ) <EOL> class BadRequest ( ClientException ) : <EOL> """<STR_LIT>""" <EOL> http_status = <NUM_LIT> <EOL> message = "<STR_LIT>" <EOL> class Unauthorized ( ClientException ) : <EOL> """<STR_LIT>""" <EOL> http_status = <NUM_LIT> <EOL> message = "<STR_LIT>" <EOL> class Forbidden ( ClientException ) : <EOL> """<STR_LIT>""" <EOL> http_status = <NUM_LIT> <EOL> message = "<STR_LIT>" <EOL> class NotFound ( ClientException ) : <EOL> """<STR_LIT>""" <EOL> http_status = <NUM_LIT> <EOL> message = "<STR_LIT>" <EOL> class MethodNotAllowed ( ClientException ) : <EOL> """<STR_LIT>""" <EOL> http_status = <NUM_LIT> <EOL> message = "<STR_LIT>" <EOL> class NotAcceptable ( ClientException ) : <EOL> """<STR_LIT>""" <EOL> http_status = <NUM_LIT> <EOL> message = "<STR_LIT>" <EOL> class Conflict ( ClientException ) : <EOL> """<STR_LIT>""" <EOL> http_status = <NUM_LIT> <EOL> message = "<STR_LIT>" <EOL> class OverLimit ( RetryAfterException ) : <EOL> """<STR_LIT>""" <EOL> http_status = <NUM_LIT> <EOL> message = "<STR_LIT>" <EOL> class RateLimit ( RetryAfterException ) : <EOL> """<STR_LIT>""" <EOL> http_status = <NUM_LIT> <EOL> message = "<STR_LIT>" <EOL> class HTTPNotImplemented ( ClientException ) : <EOL> """<STR_LIT>""" <EOL> http_status = <NUM_LIT> <EOL> message = "<STR_LIT>" <EOL> _error_classes = [ BadRequest , Unauthorized , Forbidden , NotFound , <EOL> MethodNotAllowed , NotAcceptable , Conflict , OverLimit , <EOL> RateLimit , HTTPNotImplemented ] <EOL> _code_map = dict ( ( c . http_status , c ) for c in _error_classes ) <EOL> class InvalidUsage ( RuntimeError ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def from_response ( response , body , url , method = None ) : <EOL> """<STR_LIT>""" <EOL> cls = _code_map . get ( response . status_code , ClientException ) <EOL> kwargs = { <EOL> '<STR_LIT:code>' : response . status_code , <EOL> '<STR_LIT>' : method , <EOL> '<STR_LIT:url>' : url , <EOL> '<STR_LIT>' : None , <EOL> } <EOL> if response . headers : <EOL> kwargs [ '<STR_LIT>' ] = response . headers . get ( '<STR_LIT>' ) <EOL> if ( issubclass ( cls , RetryAfterException ) and <EOL> '<STR_LIT>' in response . headers ) : <EOL> kwargs [ '<STR_LIT>' ] = response . headers . get ( '<STR_LIT>' ) <EOL> if body : <EOL> message = "<STR_LIT>" <EOL> details = "<STR_LIT>" <EOL> if hasattr ( body , '<STR_LIT>' ) : <EOL> if '<STR_LIT:message>' in body : <EOL> message = body . get ( '<STR_LIT:message>' ) <EOL> details = body . get ( '<STR_LIT>' ) <EOL> else : <EOL> error = body [ list ( body ) [ <NUM_LIT:0> ] ] <EOL> message = error . get ( '<STR_LIT:message>' ) <EOL> details = error . get ( '<STR_LIT>' ) <EOL> kwargs [ '<STR_LIT:message>' ] = message <EOL> kwargs [ '<STR_LIT>' ] = details <EOL> return cls ( ** kwargs ) <EOL> class ResourceNotFound ( Exception ) : <EOL> """<STR_LIT>""" <EOL> pass </s>
