Skip to content
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
7 changes: 7 additions & 0 deletions ChangeLog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
2012-12-17 Version 0.6.1
* Fixes for bugs:
#69 _get_readable_id doesn't support queues with slashes in their names
#68 Service bus cache of tokens doesn't support multiple creds in same app
#66 Need to change the default timeout for httprequest on windows
* Improved support for unicode data

2012-10-16 Version 0.6.0
* Added service management API
* Added ability to specify custom hosts
Expand Down
3 changes: 1 addition & 2 deletions src/azure.pyproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
<ProjectGuid>{25b2c65a-0553-4452-8907-8b5b17544e68}</ProjectGuid>
<ProjectHome>
</ProjectHome>
<StartupFile>
</StartupFile>
<StartupFile>azure\storage\blobservice.py</StartupFile>
<SearchPath>..</SearchPath>
<WorkingDirectory>.</WorkingDirectory>
<OutputPath>.</OutputPath>
Expand Down
43 changes: 31 additions & 12 deletions src/azure/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,23 @@ class HeaderDict(dict):
def __getitem__(self, index):
return super(HeaderDict, self).__getitem__(index.lower())

def _get_readable_id(id_name):
def _get_readable_id(id_name, id_prefix_to_skip):
"""simplified an id to be more friendly for us people"""
pos = id_name.rfind('/')
# id_name is in the form 'https://namespace.host.suffix/name'
# where name may contain a forward slash!
pos = id_name.find('//')
if pos != -1:
return id_name[pos+1:]
else:
return id_name

def _get_entry_properties(xmlstr, include_id):
pos += 2
if id_prefix_to_skip:
pos = id_name.find(id_prefix_to_skip, pos)
if pos != -1:
pos += len(id_prefix_to_skip)
pos = id_name.find('/', pos)
if pos != -1:
return id_name[pos+1:]
return id_name

def _get_entry_properties(xmlstr, include_id, id_prefix_to_skip=None):
''' get properties from entry xml '''
xmldoc = minidom.parseString(xmlstr)
properties = {}
Expand All @@ -120,7 +128,7 @@ def _get_entry_properties(xmlstr, include_id):

if include_id:
for id in _get_child_nodes(entry, 'id'):
properties['name'] = _get_readable_id(id.firstChild.nodeValue)
properties['name'] = _get_readable_id(id.firstChild.nodeValue, id_prefix_to_skip)

return properties

Expand Down Expand Up @@ -207,7 +215,16 @@ def _get_serialization_name(element_name):

return ''.join(name.capitalize() for name in element_name.split('_'))

def _str(value):
if isinstance(value, unicode):
return value.encode('utf-8')

return str(value)

def _str_or_none(value):
if isinstance(value, unicode):
return value.encode('utf-8')

if value is None:
return None

Expand Down Expand Up @@ -375,9 +392,8 @@ def _fill_dict_of(xmldoc, parent_xml_element_name, pair_xml_element_name, key_xm
keys = _get_child_nodes(pair, key_xml_element_name)
values = _get_child_nodes(pair, value_xml_element_name)
if keys and values:
key = str(keys[0].firstChild.nodeValue)
value = str(values[0].firstChild.nodeValue)

key = keys[0].firstChild.nodeValue
value = values[0].firstChild.nodeValue
return_obj[key] = value

return return_obj
Expand Down Expand Up @@ -436,7 +452,7 @@ def _get_request_body(request_body):
elif isinstance(request_body, WindowsAzureData):
return _convert_class_to_xml(request_body)

return request_body
return _str(request_body)

def _parse_enum_results_list(response, return_type, resp_type, item_type):
"""resp_body is the XML we received
Expand Down Expand Up @@ -514,6 +530,9 @@ def _fill_data_to_return_object(node, return_obj):
value = _fill_data_minidom(node, name, '')
if value is not None:
value = base64.b64decode(value)
try:
value = value.decode('utf-8')
except: pass
#always set the attribute, so we don't end up returning an object with type _Base64String
setattr(return_obj, name, value)
else:
Expand Down
6 changes: 4 additions & 2 deletions src/azure/http/winhttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ def open(self, method, url):
method: the request VERB 'GET', 'POST', etc.
url: the url to connect
'''
_WinHttpRequest._SetTimeouts(self, 0, 65000, 65000, 65000)

flag = VARIANT()
flag.vt = VT_BOOL
Expand Down Expand Up @@ -321,11 +322,12 @@ def putrequest(self, method, uri):

#sets certificate for the connection if cert_file is set.
if self.cert_file is not None:
self._httprequest.set_client_certificate(BSTR(unicode(self.cert_file)))
self._httprequest.set_client_certificate(unicode(self.cert_file))

def putheader(self, name, value):
''' Sends the headers of request. '''
self._httprequest.set_request_header(unicode(name), unicode(value))
self._httprequest.set_request_header(str(name).decode('utf-8'),
str(value).decode('utf-8'))

def endheaders(self):
''' No operation. Exists only to provide the same interface of httplib HTTPConnection.'''
Expand Down
12 changes: 7 additions & 5 deletions src/azure/servicebus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,9 @@ def add_headers(self, request):
# Adds custom properties
if self.custom_properties:
for name, value in self.custom_properties.iteritems():
if isinstance(value, str):
if isinstance(value, unicode):
request.headers.append((name, '"' + value.encode('utf-8') + '"'))
elif isinstance(value, str):
request.headers.append((name, '"' + str(value) + '"'))
elif isinstance(value, datetime):
request.headers.append((name, '"' + value.strftime('%a, %d %b %Y %H:%M:%S GMT') + '"'))
Expand Down Expand Up @@ -248,8 +250,8 @@ def _get_token(request, account_key, issuer):
account_key: service bus access key
issuer: service bus issuer
'''
wrap_scope = 'http://' + request.host + request.path
wrap_scope = 'http://' + request.host + request.path + issuer + account_key

# Check whether has unexpired cache, return cached token if it is still usable.
if _tokens.has_key(wrap_scope):
token = _tokens[wrap_scope]
Expand Down Expand Up @@ -371,7 +373,7 @@ def _convert_xml_to_rule(xmlstr):
setattr(rule, 'action_expression', action_expression.nodeValue)

#extract id, updated and name value from feed entry and set them of rule.
for name, value in _get_entry_properties(xmlstr, True).iteritems():
for name, value in _get_entry_properties(xmlstr, True, '/rules').iteritems():
setattr(rule, name, value)

return rule
Expand Down Expand Up @@ -565,7 +567,7 @@ def _convert_xml_to_subscription(xmlstr):
if node_value is not None:
subscription.message_count = int(node_value)

for name, value in _get_entry_properties(xmlstr, True).iteritems():
for name, value in _get_entry_properties(xmlstr, True, '/subscriptions').iteritems():
setattr(subscription, name, value)

return subscription
Expand Down
Loading