<s> from six . moves import urllib <EOL> class ClientException ( Exception ) : <EOL> def __init__ ( self , msg , http_scheme = '<STR_LIT>' , http_host = '<STR_LIT>' , http_port = '<STR_LIT>' , <EOL> http_path = '<STR_LIT>' , http_query = '<STR_LIT>' , http_status = None , http_reason = '<STR_LIT>' , <EOL> http_device = '<STR_LIT>' , http_response_content = '<STR_LIT>' , <EOL> http_response_headers = None ) : <EOL> super ( ClientException , self ) . __init__ ( msg ) <EOL> self . msg = msg <EOL> self . http_scheme = http_scheme <EOL> self . http_host = http_host <EOL> self . http_port = http_port <EOL> self . http_path = http_path <EOL> self . http_query = http_query <EOL> self . http_status = http_status <EOL> self . http_reason = http_reason <EOL> self . http_device = http_device <EOL> self . http_response_content = http_response_content <EOL> self . http_response_headers = http_response_headers <EOL> @ classmethod <EOL> def from_response ( cls , resp , msg = None , body = None ) : <EOL> msg = msg or '<STR_LIT>' % ( resp . status_code , resp . reason ) <EOL> body = body or resp . content <EOL> parsed_url = urllib . parse . urlparse ( resp . request . url ) <EOL> return cls ( msg , parsed_url . scheme , parsed_url . hostname , <EOL> parsed_url . port , parsed_url . path , parsed_url . query , <EOL> resp . status_code , resp . reason , '<STR_LIT>' , body , resp . headers ) <EOL> def __str__ ( self ) : <EOL> a = self . msg <EOL> b = '<STR_LIT>' <EOL> if self . http_scheme : <EOL> b += '<STR_LIT>' % self . http_scheme <EOL> if self . http_host : <EOL> b += self . http_host <EOL> if self . http_port : <EOL> b += '<STR_LIT>' % self . http_port <EOL> if self . http_path : <EOL> b += self . http_path <EOL> if self . http_query : <EOL> b += '<STR_LIT>' % self . http_query <EOL> if self . http_status : <EOL> if b : <EOL> b = '<STR_LIT>' % ( b , self . http_status ) <EOL> else : <EOL> b = str ( self . http_status ) <EOL> if self . http_reason : <EOL> if b : <EOL> b = '<STR_LIT>' % ( b , self . http_reason ) <EOL> else : <EOL> b = '<STR_LIT>' % self . http_reason <EOL> if self . http_device : <EOL> if b : <EOL> b = '<STR_LIT>' % ( b , self . http_device ) <EOL> else : <EOL> b = '<STR_LIT>' % self . http_device <EOL> if self . http_response_content : <EOL> if len ( self . http_response_content ) <= <NUM_LIT> : <EOL> b += '<STR_LIT>' % self . http_response_content <EOL> else : <EOL> b += '<STR_LIT>' % self . http_response_content [ : <NUM_LIT> ] <EOL> return b and '<STR_LIT>' % ( a , b ) or a </s>
