<s> """<STR_LIT>""" <EOL> import inspect <EOL> import sys <EOL> import six <EOL> from magnumclient . openstack . common . _i18n import _ <EOL> class ClientException ( Exception ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class ValidationError ( ClientException ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class UnsupportedVersion ( ClientException ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class CommandError ( ClientException ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class AuthorizationFailure ( ClientException ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class ConnectionError ( ClientException ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class ConnectionRefused ( ConnectionError ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class AuthPluginOptionsMissing ( AuthorizationFailure ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , opt_names ) : <EOL> super ( AuthPluginOptionsMissing , self ) . __init__ ( <EOL> _ ( "<STR_LIT>" ) % <EOL> "<STR_LIT:U+002CU+0020>" . join ( opt_names ) ) <EOL> self . opt_names = opt_names <EOL> class AuthSystemNotFound ( AuthorizationFailure ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , auth_system ) : <EOL> super ( AuthSystemNotFound , self ) . __init__ ( <EOL> _ ( "<STR_LIT>" ) % auth_system ) <EOL> self . auth_system = auth_system <EOL> class NoUniqueMatch ( ClientException ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class EndpointException ( ClientException ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class EndpointNotFound ( EndpointException ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class AmbiguousEndpoints ( EndpointException ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , endpoints = None ) : <EOL> super ( AmbiguousEndpoints , self ) . __init__ ( <EOL> _ ( "<STR_LIT>" ) % endpoints ) <EOL> self . endpoints = endpoints <EOL> class HttpError ( ClientException ) : <EOL> """<STR_LIT>""" <EOL> http_status = <NUM_LIT:0> <EOL> message = _ ( "<STR_LIT>" ) <EOL> def __init__ ( self , message = None , details = None , <EOL> response = None , request_id = None , <EOL> url = None , method = None , http_status = None ) : <EOL> self . http_status = http_status or self . http_status <EOL> self . message = message or self . message <EOL> self . details = details <EOL> self . request_id = request_id <EOL> self . response = response <EOL> self . url = url <EOL> self . method = method <EOL> formatted_string = "<STR_LIT>" % ( self . message , self . http_status ) <EOL> if request_id : <EOL> formatted_string += "<STR_LIT>" % request_id <EOL> super ( HttpError , self ) . __init__ ( formatted_string ) <EOL> class HTTPRedirection ( HttpError ) : <EOL> """<STR_LIT>""" <EOL> message = _ ( "<STR_LIT>" ) <EOL> class HTTPClientError ( HttpError ) : <EOL> """<STR_LIT>""" <EOL> message = _ ( "<STR_LIT>" ) <EOL> class HttpServerError ( HttpError ) : <EOL> """<STR_LIT>""" <EOL> message = _ ( "<STR_LIT>" ) <EOL> class MultipleChoices ( HTTPRedirection ) : <EOL> """<STR_LIT>""" <EOL> http_status = <NUM_LIT> <EOL> message = _ ( "<STR_LIT>" ) <EOL> class BadRequest ( HTTPClientError ) : <EOL> """<STR_LIT>""" <EOL> http_status = <NUM_LIT> <EOL> message = _ ( "<STR_LIT>" ) <EOL> class Unauthorized ( HTTPClientError ) : <EOL> """<STR_LIT>""" <EOL> http_status = <NUM_LIT> <EOL> message = _ ( "<STR_LIT>" ) <EOL> class PaymentRequired ( HTTPClientError ) : <EOL> """<STR_LIT>""" <EOL> http_status = <NUM_LIT> <EOL> message = _ ( "<STR_LIT>" ) <EOL> class Forbidden ( HTTPClientError ) : <EOL> """<STR_LIT>""" <EOL> http_status = <NUM_LIT> <EOL> message = _ ( "<STR_LIT>" ) <EOL> class NotFound ( HTTPClientError ) : <EOL> """<STR_LIT>""" <EOL> http_status = <NUM_LIT> <EOL> message = _ ( "<STR_LIT>" ) <EOL> class MethodNotAllowed ( HTTPClientError ) : <EOL> """<STR_LIT>""" <EOL> http_status = <NUM_LIT> <EOL> message = _ ( "<STR_LIT>" ) <EOL> class NotAcceptable ( HTTPClientError ) : <EOL> """<STR_LIT>""" <EOL> http_status = <NUM_LIT> <EOL> message = _ ( "<STR_LIT>" ) <EOL> class ProxyAuthenticationRequired ( HTTPClientError ) : <EOL> """<STR_LIT>""" <EOL> http_status = <NUM_LIT> <EOL> message = _ ( "<STR_LIT>" ) <EOL> class RequestTimeout ( HTTPClientError ) : <EOL> """<STR_LIT>""" <EOL> http_status = <NUM_LIT> <EOL> message = _ ( "<STR_LIT>" ) <EOL> class Conflict ( HTTPClientError ) : <EOL> """<STR_LIT>""" <EOL> http_status = <NUM_LIT> <EOL> message = _ ( "<STR_LIT>" ) <EOL> class Gone ( HTTPClientError ) : <EOL> """<STR_LIT>""" <EOL> http_status = <NUM_LIT> <EOL> message = _ ( "<STR_LIT>" ) <EOL> class LengthRequired ( HTTPClientError ) : <EOL> """<STR_LIT>""" <EOL> http_status = <NUM_LIT> <EOL> message = _ ( "<STR_LIT>" ) <EOL> class PreconditionFailed ( HTTPClientError ) : <EOL> """<STR_LIT>""" <EOL> http_status = <NUM_LIT> <EOL> message = _ ( "<STR_LIT>" ) <EOL> class RequestEntityTooLarge ( HTTPClientError ) : <EOL> """<STR_LIT>""" <EOL> http_status = <NUM_LIT> <EOL> message = _ ( "<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 ( RequestEntityTooLarge , self ) . __init__ ( * args , ** kwargs ) <EOL> class RequestUriTooLong ( HTTPClientError ) : <EOL> """<STR_LIT>""" <EOL> http_status = <NUM_LIT> <EOL> message = _ ( "<STR_LIT>" ) <EOL> class UnsupportedMediaType ( HTTPClientError ) : <EOL> """<STR_LIT>""" <EOL> http_status = <NUM_LIT> <EOL> message = _ ( "<STR_LIT>" ) <EOL> class RequestedRangeNotSatisfiable ( HTTPClientError ) : <EOL> """<STR_LIT>""" <EOL> http_status = <NUM_LIT> <EOL> message = _ ( "<STR_LIT>" ) <EOL> class ExpectationFailed ( HTTPClientError ) : <EOL> """<STR_LIT>""" <EOL> http_status = <NUM_LIT> <EOL> message = _ ( "<STR_LIT>" ) <EOL> class UnprocessableEntity ( HTTPClientError ) : <EOL> """<STR_LIT>""" <EOL> http_status = <NUM_LIT> <EOL> message = _ ( "<STR_LIT>" ) <EOL> class InternalServerError ( HttpServerError ) : <EOL> """<STR_LIT>""" <EOL> http_status = <NUM_LIT> <EOL> message = _ ( "<STR_LIT>" ) <EOL> class HttpNotImplemented ( HttpServerError ) : <EOL> """<STR_LIT>""" <EOL> http_status = <NUM_LIT> <EOL> message = _ ( "<STR_LIT>" ) <EOL> class BadGateway ( HttpServerError ) : <EOL> """<STR_LIT>""" <EOL> http_status = <NUM_LIT> <EOL> message = _ ( "<STR_LIT>" ) <EOL> class ServiceUnavailable ( HttpServerError ) : <EOL> """<STR_LIT>""" <EOL> http_status = <NUM_LIT> <EOL> message = _ ( "<STR_LIT>" ) <EOL> class GatewayTimeout ( HttpServerError ) : <EOL> """<STR_LIT>""" <EOL> http_status = <NUM_LIT> <EOL> message = _ ( "<STR_LIT>" ) <EOL> class HttpVersionNotSupported ( HttpServerError ) : <EOL> """<STR_LIT>""" <EOL> http_status = <NUM_LIT> <EOL> message = _ ( "<STR_LIT>" ) <EOL> _code_map = dict ( <EOL> ( getattr ( obj , '<STR_LIT>' , None ) , obj ) <EOL> for name , obj in vars ( sys . modules [ __name__ ] ) . items ( ) <EOL> if inspect . isclass ( obj ) and getattr ( obj , '<STR_LIT>' , False ) <EOL> ) <EOL> def from_response ( response , method , url ) : <EOL> """<STR_LIT>""" <EOL> req_id = response . headers . get ( "<STR_LIT>" ) <EOL> if not req_id : <EOL> req_id = response . headers . get ( "<STR_LIT>" ) <EOL> kwargs = { <EOL> "<STR_LIT>" : response . status_code , <EOL> "<STR_LIT>" : response , <EOL> "<STR_LIT>" : method , <EOL> "<STR_LIT:url>" : url , <EOL> "<STR_LIT>" : req_id , <EOL> } <EOL> if "<STR_LIT>" in response . headers : <EOL> kwargs [ "<STR_LIT>" ] = response . headers [ "<STR_LIT>" ] <EOL> content_type = response . headers . get ( "<STR_LIT:Content-Type>" , "<STR_LIT>" ) <EOL> if content_type . startswith ( "<STR_LIT:application/json>" ) : <EOL> try : <EOL> body = response . json ( ) <EOL> except ValueError : <EOL> pass <EOL> else : <EOL> if isinstance ( body , dict ) : <EOL> error = body . get ( list ( body ) [ <NUM_LIT:0> ] ) <EOL> if isinstance ( error , dict ) : <EOL> kwargs [ "<STR_LIT:message>" ] = ( error . get ( "<STR_LIT:message>" ) or <EOL> error . get ( "<STR_LIT>" ) ) <EOL> kwargs [ "<STR_LIT>" ] = ( error . get ( "<STR_LIT>" ) or <EOL> six . text_type ( body ) ) <EOL> elif content_type . startswith ( "<STR_LIT>" ) : <EOL> kwargs [ "<STR_LIT>" ] = getattr ( response , '<STR_LIT:text>' , '<STR_LIT>' ) <EOL> try : <EOL> cls = _code_map [ response . status_code ] <EOL> except KeyError : <EOL> if <NUM_LIT> <= response . status_code < <NUM_LIT> : <EOL> cls = HttpServerError <EOL> elif <NUM_LIT> <= response . status_code < <NUM_LIT> : <EOL> cls = HTTPClientError <EOL> else : <EOL> cls = HttpError <EOL> return cls ( ** kwargs ) </s>
