<s> from lxml import etree , objectify <EOL> CODE_MAJOR_CODES = [ <EOL> '<STR_LIT:success>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] <EOL> SEVERITY_CODES = [ <EOL> '<STR_LIT:status>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:error>' <EOL> ] <EOL> accessors = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:description>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] <EOL> class OutcomeResponse ( ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , ** kwargs ) : <EOL> for opt in accessors : <EOL> setattr ( self , opt , None ) <EOL> for ( key , val ) in kwargs . iteritems ( ) : <EOL> setattr ( self , key , val ) <EOL> @ staticmethod <EOL> def from_post_response ( post_response , content ) : <EOL> '''<STR_LIT>''' <EOL> response = OutcomeResponse ( ) <EOL> response . post_response = post_response <EOL> response . response_code = post_response . status <EOL> response . process_xml ( content ) <EOL> return response <EOL> def is_success ( self ) : <EOL> return self . code_major == '<STR_LIT:success>' <EOL> def is_processing ( self ) : <EOL> return self . code_major == '<STR_LIT>' <EOL> def is_failure ( self ) : <EOL> return self . code_major == '<STR_LIT>' <EOL> def is_unsupported ( self ) : <EOL> return self . code_major == '<STR_LIT>' <EOL> def has_warning ( self ) : <EOL> return self . severity == '<STR_LIT>' <EOL> def has_error ( self ) : <EOL> return self . severity == '<STR_LIT:error>' <EOL> def process_xml ( self , xml ) : <EOL> '''<STR_LIT>''' <EOL> try : <EOL> root = objectify . fromstring ( xml ) <EOL> self . message_identifier = root . imsx_POXHeader . imsx_POXResponseHeaderInfo . imsx_messageIdentifier <EOL> status_node = root . imsx_POXHeader . imsx_POXResponseHeaderInfo . imsx_statusInfo <EOL> self . code_major = status_node . imsx_codeMajor <EOL> self . severity = status_node . imsx_severity <EOL> self . description = status_node . imsx_description <EOL> self . message_ref_identifier = str ( <EOL> status_node . imsx_messageRefIdentifier ) <EOL> self . operation = status_node . imsx_operationRefIdentifier <EOL> try : <EOL> self . score = str ( root . imsx_POXBody . readResultResponse . <EOL> result . resultScore . textString ) <EOL> except AttributeError : <EOL> pass <EOL> except : <EOL> pass <EOL> def generate_response_xml ( self ) : <EOL> '''<STR_LIT>''' <EOL> root = etree . Element ( <EOL> '<STR_LIT>' , <EOL> xmlns = '<STR_LIT>' ) <EOL> header = etree . SubElement ( root , '<STR_LIT>' ) <EOL> header_info = etree . SubElement ( header , '<STR_LIT>' ) <EOL> version = etree . SubElement ( header_info , '<STR_LIT>' ) <EOL> version . text = '<STR_LIT>' <EOL> message_identifier = etree . SubElement ( header_info , <EOL> '<STR_LIT>' ) <EOL> message_identifier . text = str ( self . message_identifier ) <EOL> status_info = etree . SubElement ( header_info , '<STR_LIT>' ) <EOL> code_major = etree . SubElement ( status_info , '<STR_LIT>' ) <EOL> code_major . text = str ( self . code_major ) <EOL> severity = etree . SubElement ( status_info , '<STR_LIT>' ) <EOL> severity . text = str ( self . severity ) <EOL> description = etree . SubElement ( status_info , '<STR_LIT>' ) <EOL> description . text = str ( self . description ) <EOL> message_ref_identifier = etree . SubElement ( <EOL> status_info , <EOL> '<STR_LIT>' ) <EOL> message_ref_identifier . text = str ( self . message_ref_identifier ) <EOL> operation_ref_identifier = etree . SubElement ( <EOL> status_info , <EOL> '<STR_LIT>' ) <EOL> operation_ref_identifier . text = str ( self . operation ) <EOL> body = etree . SubElement ( root , '<STR_LIT>' ) <EOL> response = etree . SubElement ( body , '<STR_LIT>' % ( self . operation , <EOL> '<STR_LIT>' ) ) <EOL> if self . score : <EOL> result = etree . SubElement ( response , '<STR_LIT:result>' ) <EOL> result_score = etree . SubElement ( result , '<STR_LIT>' ) <EOL> language = etree . SubElement ( result_score , '<STR_LIT>' ) <EOL> language . text = '<STR_LIT>' <EOL> text_string = etree . SubElement ( result_score , '<STR_LIT>' ) <EOL> text_string . text = str ( self . score ) <EOL> return '<STR_LIT>' + etree . tostring ( root ) </s>
