<s> from solumclient . openstack . common . apiclient import exceptions <EOL> class CommandException ( Exception ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , message = None ) : <EOL> self . message = message <EOL> def __str__ ( self ) : <EOL> return self . message or self . __class__ . __doc__ <EOL> class CommandError ( CommandException ) : <EOL> """<STR_LIT>""" <EOL> class NotUnique ( CommandException ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , resource = '<STR_LIT>' ) : <EOL> message = "<STR_LIT>" <EOL> self . message = message % resource <EOL> def from_response ( response , method , url ) : <EOL> """<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>" : response . headers . get ( "<STR_LIT>" ) , <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> kwargs [ "<STR_LIT:message>" ] = body . get ( "<STR_LIT>" ) <EOL> kwargs [ "<STR_LIT>" ] = body . get ( "<STR_LIT>" ) <EOL> elif content_type . startswith ( "<STR_LIT>" ) : <EOL> kwargs [ "<STR_LIT>" ] = response . text <EOL> try : <EOL> cls = exceptions . _code_map [ response . status_code ] <EOL> except KeyError : <EOL> if <NUM_LIT> <= response . status_code < <NUM_LIT> : <EOL> cls = exceptions . HttpServerError <EOL> elif <NUM_LIT> <= response . status_code < <NUM_LIT> : <EOL> cls = exceptions . HTTPClientError <EOL> else : <EOL> cls = exceptions . HttpError <EOL> return cls ( ** kwargs ) </s>
