def add_request(self, request_name, request_dict, namespace=None): super(RequestXml, self).add_request( request_name, request_dict, namespace ) request_node = self.request_doc.createElement(request_name) xmlserializer.dict_to_dom(request_node, request_dict) if not self.batch_request: request_node.setAttribute('xmlns', namespace) self.body_node.appendChild(request_node) return None request_id = self.batch_request_id request_node.setAttribute('requestId', str(request_id)) self.batch_node.appendChild(request_node) self.batch_request_id += 1 return request_id
def add_request(self, request_name, request_dict, namespace): super(RequestXml, self).add_request(request_name, request_dict, namespace) request_node = self.request_doc.createElement(request_name) xmlserializer.dict_to_dom(request_node, request_dict) request_node.setAttribute('xmlns', namespace) if not self.batch_request: self.body_node.appendChild(request_node) return None request_id = self.batch_request_id request_node.setAttribute('requestId', str(request_id)) self.batch_node.appendChild(request_node) self.batch_request_id += 1 return request_id
def set_context_params(self, params): # Call parent method super(RequestXml, self).set_context_params(params) for key, value in params.iteritems(): tmp_node = self.request_doc.createElement(key) xmlserializer.dict_to_dom(tmp_node, value) self.context_node.appendChild(tmp_node)
def set_context_params(self, params): # Call parent method super(RequestXml, self).set_context_params(params) for key, value in params.items(): tmp_node = self.request_doc.createElement(key) xmlserializer.dict_to_dom(tmp_node, value) self.context_node.appendChild(tmp_node)
def test_dict_to_dom_unicode(self): """ Test xml serialization using dict_to_dom method. """ test_doc = minidom.Document() test_node = test_doc.createElement("test") test_dict = { 'attr1': 'value1', 'attr2': 'value2', 'subnode1': { '_content': 'testcontent' }, 'subnode2': { 'subnode2attr1': 'value1', 'subnode2attr2': 'value2', '_content': 'testcontent2' }, 'subnode3': { 'subnode3attr1': 'value1', 'subnode3attr2': 'value2\xf6', 'subnode31': { '_content': 'testcontent3\xf6' } }, 'listsubnode': [ { "_content": "value1" }, { "_content": "value2" }, { "_content": "value3" } ] } xmlserializer.dict_to_dom(test_node, test_dict) self.assertEqual( xmlserializer.dom_to_dict(test_node), { "test": test_dict } )
def test_dict_to_dom(self): """ Test xml serialization using dict_to_dom method. """ test_doc = minidom.Document() test_node = test_doc.createElement("test") test_dict = { 'attr1': 'value1', 'attr2': 'value2', 'subnode1': { '_content': 'testcontent' }, 'subnode2': { 'subnode2attr1': 'value1', 'subnode2attr2': 'value2', '_content': 'testcontent2' }, 'subnode3': { 'subnode3attr1': 'value1', 'subnode3attr2': 'value2', 'subnode31': { '_content': 'testcontent3' } } } xmlserializer.dict_to_dom(test_node, test_dict) expected_result = '<test attr1="value1" attr2="value2"><subnode2 ' \ 'subnode2attr1="value1" ' \ 'subnode2attr2="value2">testcontent2</subnode2' \ '><subnode1>testcontent</subnode1><subnode3 ' \ 'subnode3attr1="value1" ' \ 'subnode3attr2="value2"><subnode31>testcontent3' \ '</subnode31></subnode3></test>' self.assertEqual( expected_result, test_node.toxml() )
def test_dict_to_dom(self): """ Test xml serialization using dict_to_dom method. """ test_doc = minidom.Document() test_node = test_doc.createElement("test") test_dict = { 'attr1': 'value1', 'attr2': 'value2', 'subnode1': { '_content': 'testcontent' }, 'subnode2': { 'subnode2attr1': 'value1', 'subnode2attr2': 'value2', '_content': 'testcontent2' }, 'subnode3': { 'subnode3attr1': 'value1', 'subnode3attr2': 'value2', 'subnode31': { '_content': 'testcontent3' } }, 'listsubnode': [{ "_content": "value1" }, { "_content": "value2" }, { "_content": "value3" }] } xmlserializer.dict_to_dom(test_node, test_dict) self.assertEqual(xmlserializer.dom_to_dict(test_node), {"test": test_dict})
def test_dict_to_dom_unicode(self): """ Test xml serialization using dict_to_dom method. """ test_doc = minidom.Document() test_node = test_doc.createElement("test") test_dict = { 'attr1': 'value1', 'attr2': 'value2', 'subnode1': { '_content': 'testcontent' }, 'subnode2': { 'subnode2attr1': 'value1', 'subnode2attr2': 'value2', '_content': 'testcontent2' }, 'subnode3': { 'subnode3attr1': 'value1', 'subnode3attr2': u'value2\xf6', 'subnode31': { '_content': u'testcontent3\xf6' } } } xmlserializer.dict_to_dom(test_node, test_dict) expected_result = '<test attr1="value1" attr2="value2"><subnode2 ' \ 'subnode2attr1="value1" ' \ 'subnode2attr2="value2">testcontent2</subnode2' \ '><subnode1>testcontent</subnode1><subnode3 ' \ 'subnode3attr1="value1" ' \ u'subnode3attr2="value2\xf6"><subnode31' \ u'>testcontent3\xf6' \ '</subnode31></subnode3></test>' self.assertEqual(expected_result, test_node.toxml())