<s> """<STR_LIT>""" <EOL> from xml . dom import minidom <EOL> from pythonzimbra . tools . xmlserializer import dom_to_dict <EOL> from . response import Response <EOL> class ResponseXml ( Response ) : <EOL> response_doc = None <EOL> """<STR_LIT>""" <EOL> response_type = "<STR_LIT>" <EOL> def clean ( self ) : <EOL> super ( ResponseXml , self ) . clean ( ) <EOL> self . response_doc = None <EOL> def set_response ( self , response_text ) : <EOL> if not isinstance ( response_text , str ) : <EOL> response_text = response_text . encode ( "<STR_LIT:utf-8>" ) <EOL> self . response_doc = minidom . parseString ( response_text ) <EOL> def get_body ( self ) : <EOL> return self . _filter_response ( <EOL> dom_to_dict ( <EOL> self . response_doc . getElementsByTagNameNS ( <EOL> "<STR_LIT:*>" , "<STR_LIT>" <EOL> ) . item ( <NUM_LIT:0> ) . firstChild <EOL> ) <EOL> ) <EOL> def get_header ( self ) : <EOL> return self . _filter_response ( <EOL> dom_to_dict ( <EOL> self . response_doc . getElementsByTagNameNS ( <EOL> "<STR_LIT:*>" , "<STR_LIT>" <EOL> ) . item ( <NUM_LIT:0> ) . firstChild <EOL> ) <EOL> ) <EOL> def is_batch ( self ) : <EOL> if self . response_doc . getElementsByTagName ( "<STR_LIT>" ) . length > <NUM_LIT:0> : <EOL> return True <EOL> return False <EOL> def get_batch ( self ) : <EOL> if not self . is_batch ( ) : <EOL> return None <EOL> ret_dict = { <EOL> '<STR_LIT>' : { } , <EOL> '<STR_LIT>' : { } <EOL> } <EOL> has_fault = False <EOL> search_node = self . response_doc . getElementsByTagNameNS ( <EOL> "<STR_LIT:*>" , "<STR_LIT>" <EOL> ) . item ( <NUM_LIT:0> ) <EOL> for child in search_node . childNodes : <EOL> tag = child . tagName <EOL> if "<STR_LIT::>" in tag : <EOL> tag = tag . split ( "<STR_LIT::>" ) [ <NUM_LIT:1> ] <EOL> if tag == '<STR_LIT>' : <EOL> has_fault = True <EOL> continue <EOL> request_id = child . getAttribute ( "<STR_LIT>" ) <EOL> ret_dict [ '<STR_LIT>' ] [ request_id ] = tag <EOL> if tag not in list ( ret_dict [ '<STR_LIT>' ] . keys ( ) ) : <EOL> ret_dict [ '<STR_LIT>' ] [ tag ] = [ ] <EOL> ret_dict [ '<STR_LIT>' ] [ tag ] . append ( request_id ) <EOL> ret_dict [ '<STR_LIT>' ] = has_fault <EOL> return ret_dict <EOL> def get_response ( self , request_id = <NUM_LIT:0> ) : <EOL> if self . is_batch ( ) : <EOL> search_node = self . response_doc . getElementsByTagNameNS ( <EOL> "<STR_LIT:*>" , "<STR_LIT>" <EOL> ) . item ( <NUM_LIT:0> ) <EOL> for child in search_node . childNodes : <EOL> if int ( child . getAttribute ( "<STR_LIT>" ) ) == request_id : <EOL> return self . _filter_response ( dom_to_dict ( child ) ) <EOL> return None <EOL> else : <EOL> search_node = self . response_doc . getElementsByTagNameNS ( <EOL> "<STR_LIT:*>" , "<STR_LIT>" <EOL> ) . item ( <NUM_LIT:0> ) <EOL> return self . _filter_response ( dom_to_dict ( search_node . firstChild ) ) <EOL> def get_fault_code ( self ) : <EOL> if self . is_batch ( ) : <EOL> ret_dict = { } <EOL> search_node = self . response_doc . getElementsByTagNameNS ( <EOL> "<STR_LIT:*>" , "<STR_LIT>" <EOL> ) . item ( <NUM_LIT:0> ) <EOL> for child in search_node . childNodes : <EOL> ret_dict [ child . getAttribute ( "<STR_LIT>" ) ] = self . get_response ( <EOL> int ( child . getAttribute ( "<STR_LIT>" ) ) <EOL> ) [ "<STR_LIT>" ] [ "<STR_LIT>" ] [ "<STR_LIT>" ] [ "<STR_LIT>" ] <EOL> return ret_dict <EOL> else : <EOL> return self . get_response ( ) [ "<STR_LIT>" ] [ "<STR_LIT>" ] [ "<STR_LIT>" ] [ <EOL> "<STR_LIT>" ] <EOL> def get_fault_message ( self ) : <EOL> if self . is_batch ( ) : <EOL> ret_dict = { } <EOL> search_node = self . response_doc . getElementsByTagNameNS ( <EOL> "<STR_LIT:*>" , "<STR_LIT>" <EOL> ) . item ( <NUM_LIT:0> ) <EOL> for child in search_node . childNodes : <EOL> ret_dict [ child . getAttribute ( "<STR_LIT>" ) ] = self . get_response ( <EOL> int ( child . getAttribute ( "<STR_LIT>" ) ) <EOL> ) [ "<STR_LIT>" ] [ "<STR_LIT>" ] [ "<STR_LIT>" ] <EOL> return ret_dict <EOL> else : <EOL> return self . get_response ( ) [ "<STR_LIT>" ] [ "<STR_LIT>" ] [ "<STR_LIT>" ] </s>
