diff --git a/src/azure/__init__.py b/src/azure/__init__.py index bb0f4ad116c8..e23bd9069fc3 100644 --- a/src/azure/__init__.py +++ b/src/azure/__init__.py @@ -276,7 +276,7 @@ def _convert_response_to_feeds(response, convert_func): xml_entries = _get_children_from_path(xmldoc, 'entry') #in some cases, response contains only entry but no feed for xml_entry in xml_entries: new_node = _clone_node_with_namespaces(xml_entry, xmldoc) - feeds.append(convert_func(new_node.toxml())) + feeds.append(convert_func(new_node.toxml('utf-8'))) return feeds @@ -286,7 +286,7 @@ def _validate_not_none(param_name, param): def _fill_list_of(xmldoc, element_type): xmlelements = _get_child_nodes(xmldoc, element_type.__name__) - return [_parse_response_body(xmlelement.toxml(), element_type) for xmlelement in xmlelements] + return [_parse_response_body(xmlelement.toxml('utf-8'), element_type) for xmlelement in xmlelements] def _fill_dict(xmldoc, element_name): xmlelements = _get_child_nodes(xmldoc, element_name) @@ -312,7 +312,7 @@ def _fill_instance_child(xmldoc, element_name, return_type): def _fill_instance_element(element, return_type): """Converts a DOM element into the specified object""" - return _parse_response_body(element.toxml(), return_type) + return _parse_response_body(element.toxml('utf-8'), return_type) def _fill_data_minidom(xmldoc, element_name, data_member): diff --git a/src/azure/storage/__init__.py b/src/azure/storage/__init__.py index 85767d895789..73eccc93b2f2 100644 --- a/src/azure/storage/__init__.py +++ b/src/azure/storage/__init__.py @@ -564,6 +564,9 @@ def convert_entity_to_xml(source): properties_str += ''.join([' m:type="', mtype, '"']) properties_str += ''.join(['>', xml_escape(value), '']) + if isinstance(properties_str, unicode): + properties_str = properties_str.encode(encoding='utf-8') + #generate the entity_body entity_body = entity_body.format(properties=properties_str) xmlstr = _create_entry(entity_body) diff --git a/test/azuretest/test_tableservice.py b/test/azuretest/test_tableservice.py index 009304cd27d8..3c29c15e2c06 100644 --- a/test/azuretest/test_tableservice.py +++ b/test/azuretest/test_tableservice.py @@ -1,4 +1,4 @@ -#------------------------------------------------------------------------- +#------------------------------------------------------------------------- # Copyright 2011 Microsoft Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,7 +17,6 @@ from azure.storage import EntityProperty, Entity, StorageServiceProperties from azure import WindowsAzureError - from azuretest.util import (credentials, getUniqueTestRunID, STATUS_OK, @@ -1039,8 +1038,18 @@ def test_batch_different_table_operations_fail(self): self.tc.cancel_batch() + def test_unicode_xml_encoding(self): + ''' regression test for github issue #57''' + # Act + self._create_table(self.table_name) + self.tc.insert_entity(self.table_name, {'PartitionKey': 'test', 'RowKey': 'test1', 'Description': u'ꀕ'}) + self.tc.insert_entity(self.table_name, {'PartitionKey': 'test', 'RowKey': 'test2', 'Description': 'ꀕ'}) + resp = self.tc.query_entities(self.table_name, "PartitionKey eq 'test'") # Assert - + self.assertEquals(len(resp), 2) + self.assertEquals(resp[0].Description, u'ꀕ') + self.assertEquals(resp[1].Description, u'ꀕ') + #------------------------------------------------------------------------------ if __name__ == '__main__': unittest.main()