Skip to content

Fixed the github issue #57: query_entities() doesn't work for retrieving data in unicode #61

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 29, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/azure/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand All @@ -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):
Expand Down
3 changes: 3 additions & 0 deletions src/azure/storage/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,9 @@ def convert_entity_to_xml(source):
properties_str += ''.join([' m:type="', mtype, '"'])
properties_str += ''.join(['>', xml_escape(value), '</d:', name, '>'])

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)
Expand Down
15 changes: 12 additions & 3 deletions test/azuretest/test_tableservice.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#-------------------------------------------------------------------------
#-------------------------------------------------------------------------
# Copyright 2011 Microsoft Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -17,7 +17,6 @@
from azure.storage import EntityProperty, Entity, StorageServiceProperties
from azure import WindowsAzureError


from azuretest.util import (credentials,
getUniqueTestRunID,
STATUS_OK,
Expand Down Expand Up @@ -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()