<s> class CloudServersException ( Exception ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , code , message = None , details = None ) : <EOL> self . code = code <EOL> self . message = message or self . __class__ . message <EOL> self . details = details <EOL> def __str__ ( self ) : <EOL> return "<STR_LIT>" % ( self . message , self . code ) <EOL> class BadRequest ( CloudServersException ) : <EOL> """<STR_LIT>""" <EOL> http_status = <NUM_LIT> <EOL> message = "<STR_LIT>" <EOL> class Unauthorized ( CloudServersException ) : <EOL> """<STR_LIT>""" <EOL> http_status = <NUM_LIT> <EOL> message = "<STR_LIT>" <EOL> class Forbidden ( CloudServersException ) : <EOL> """<STR_LIT>""" <EOL> http_status = <NUM_LIT> <EOL> message = "<STR_LIT>" <EOL> class NotFound ( CloudServersException ) : <EOL> """<STR_LIT>""" <EOL> http_status = <NUM_LIT> <EOL> message = "<STR_LIT>" <EOL> class OverLimit ( CloudServersException ) : <EOL> """<STR_LIT>""" <EOL> http_status = <NUM_LIT> <EOL> message = "<STR_LIT>" <EOL> _code_map = dict ( ( c . http_status , c ) for c in [ BadRequest , Unauthorized , Forbidden , NotFound , OverLimit ] ) <EOL> def from_response ( response , body ) : <EOL> """<STR_LIT>""" <EOL> cls = _code_map . get ( response . status , CloudServersException ) <EOL> if body : <EOL> error = body [ body . keys ( ) [ <NUM_LIT:0> ] ] <EOL> return cls ( code = response . status , <EOL> message = error . get ( '<STR_LIT:message>' , None ) , <EOL> details = error . get ( '<STR_LIT>' , None ) ) <EOL> else : <EOL> return cls ( code = response . status ) </s>
