Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Small refactoring to generated code.
  • Loading branch information
dfugate committed May 29, 2012
commit a2a03513b6dac9fa019bb5567a164ffc8d2bc0c3
7 changes: 4 additions & 3 deletions src/windowsazure/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,10 +433,11 @@ def _dont_fail_not_exist(error):
return False
else:
raise error



def _parse_response_for_dict(service_instance):
http_headers = ['content-type', 'server', 'date', 'location', 'host']
http_headers = ['server', 'date', 'location', 'host',
'via', 'proxy-connection', 'x-ms-version', 'connection',
'content-length', 'x-ms-request-id']
if service_instance.respheader:
return_dict = {}
for name, value in service_instance.respheader:
Expand Down
2 changes: 1 addition & 1 deletion src/windowsazure/http/batchclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

class _BatchClient(_HTTPClient):

def __init__(self, service_instance, account_key, account_name, x_ms_version, protocol):
def __init__(self, service_instance, account_key, account_name, x_ms_version=None, protocol='http'):
_HTTPClient.__init__(self, service_instance, account_name=account_name, account_key=account_key, x_ms_version=x_ms_version, protocol=protocol)
self.is_batch = False
self.batch_requests = []
Expand Down
6 changes: 0 additions & 6 deletions src/windowsazure/http/httpclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,10 @@
import httplib
import ast
import sys
import logging
from xml.dom import minidom

from windowsazure import HTTPError

httpclientLogger = logging.getLogger("windowsazure.http.httpclient")

class _HTTPClient:
def __init__(self, service_instance, cert_file=None, account_name=None, account_key=None, service_namespace=None, issuer=None, x_ms_version=None, protocol='https'):
self.service_instance = service_instance
Expand Down Expand Up @@ -82,9 +79,6 @@ def perform_request(self, request):
elif resp.length > 0:
respbody = resp.read(resp.length)

httpclientLogger.debug(self.status)
#httpclientLogger.debug(self.message)
#httpclientLogger.debug(respbody)
if self.status >= 300:
raise HTTPError(self.status, self.message, self.respheader, respbody)

Expand Down
15 changes: 15 additions & 0 deletions src/windowsazure/servicebus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
HTTPError)

DEFAULT_RULE_NAME='$Default'
AZURE_SERVICEBUS_NAMESPACE = 'AZURE_SERVICEBUS_NAMESPACE'
AZURE_SERVICEBUS_ACCESS_KEY = 'AZURE_SERVICEBUS_ACCESS_KEY'
AZURE_SERVICEBUS_ISSUER = 'AZURE_SERVICEBUS_ISSUER'

class Queue(WindowsAzureData):
def __init__(self):
Expand Down Expand Up @@ -247,13 +250,18 @@ def convert_xml_to_queue(xmlstr):
xmldoc = minidom.parseString(xmlstr)
queue = Queue()

invalid_queue = True
for attr_name, attr_value in vars(queue).iteritems():
tag_name = attr_name.replace('_', '')
xml_attrs = xmldoc.getElementsByTagName(tag_name)
if xml_attrs:
xml_attr = xml_attrs[0]
if xml_attr.firstChild:
setattr(queue, attr_name, xml_attr.firstChild.nodeValue)
invalid_queue = False

if invalid_queue:
raise WindowsAzureError('Queue is not Found')

for name, value in get_entry_properties(xmlstr, ['id', 'updated', 'name']).iteritems():
setattr(queue, name, value)
Expand All @@ -265,13 +273,20 @@ def convert_xml_to_topic(xmlstr):
xmlstr = remove_xmltag_namespace(xmlstr, to_lower=True)
xmldoc = minidom.parseString(xmlstr)
topic = Topic()

invalid_topic = True
for attr_name, attr_value in vars(topic).iteritems():
tag_name = attr_name.replace('_', '')
xml_attrs = xmldoc.getElementsByTagName(tag_name)
if xml_attrs:
xml_attr = xml_attrs[0]
if xml_attr.firstChild:
setattr(topic, attr_name, xml_attr.firstChild.nodeValue)
invalid_topic = False

if invalid_topic:
raise WindowsAzureError('Topic is not Found')

for name, value in get_entry_properties(xmlstr, ['id', 'updated', 'name']).iteritems():
setattr(topic, name, value)
return topic
Expand Down
39 changes: 27 additions & 12 deletions src/windowsazure/servicebus/servicebusservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# You must not remove this notice, or any other, from this software.
#------------------------------------------------------------------------------
import base64
import os
import urllib2

from windowsazure.http.httpclient import _HTTPClient
Expand All @@ -19,7 +20,8 @@
convert_queue_to_xml, convert_xml_to_queue,
convert_subscription_to_xml, convert_xml_to_subscription,
convert_rule_to_xml, convert_xml_to_rule,
_service_bus_error_handler)
_service_bus_error_handler, AZURE_SERVICEBUS_NAMESPACE,
AZURE_SERVICEBUS_ACCESS_KEY, AZURE_SERVICEBUS_ISSUER)
from windowsazure import (validate_length, validate_values, validate_not_none, Feed, _Request,
convert_xml_to_feeds, to_right_type,
_get_request_body, _update_request_uri_query, get_host,
Expand All @@ -31,17 +33,6 @@

class ServiceBusService:

def __init__(self, service_namespace, account_key, issuer, x_ms_version='2011-06-01'):
self.status = None
self.message = None
self.respheader = None
self.requestid = None
self.service_namespace = service_namespace
self.account_key = account_key
self.issuer = issuer
self.x_ms_version = x_ms_version
self._httpclient = _HTTPClient(service_instance=self, service_namespace=service_namespace, account_key=account_key, issuer=issuer, x_ms_version=self.x_ms_version)

def create_queue(self, queue_name, queue=None, fail_on_exist=False):
'''
Creates a new queue. Once created, this queue's resource manifest is immutable.
Expand Down Expand Up @@ -653,6 +644,30 @@ def receive_subscription_message(self, topic_name, subscription_name, peek_lock=
else:
return self.read_delete_subscription_message(topic_name, subscription_name, timeout)

def __init__(self, service_namespace=None, account_key=None, issuer=None, x_ms_version='2011-06-01'):
self.status = None
self.message = None
self.respheader = None
self.requestid = None
self.service_namespace = service_namespace
self.account_key = account_key
self.issuer = issuer
if not service_namespace:
if os.environ.has_key(AZURE_SERVICEBUS_NAMESPACE):
self.service_namespace = os.environ[AZURE_SERVICEBUS_NAMESPACE]
if not account_key:
if os.environ.has_key(AZURE_SERVICEBUS_ACCESS_KEY):
self.account_key = os.environ[AZURE_SERVICEBUS_ACCESS_KEY]
if not issuer:
if os.environ.has_key(AZURE_SERVICEBUS_ISSUER):
self.issuer = os.environ[AZURE_SERVICEBUS_ISSUER]

if not self.service_namespace or not self.account_key or not self.issuer:
raise WindowsAzureError('You need to provide servicebus namespace, access key and Issuer')

self.x_ms_version = x_ms_version
self._httpclient = _HTTPClient(service_instance=self, service_namespace=service_namespace, account_key=account_key, issuer=issuer, x_ms_version=self.x_ms_version)

def _perform_request(self, request):
try:
resp = self._httpclient.perform_request(request)
Expand Down
34 changes: 25 additions & 9 deletions src/windowsazure/storage/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,25 @@
# You must not remove this notice, or any other, from this software.
#------------------------------------------------------------------------------

import logging

from windowsazure import WindowsAzureData, DEV_ACCOUNT_NAME

storageLogger = logging.getLogger("windowsazure.storage")

class EnumResultsBase:
def __int__(self):
def __init__(self):
self.prefix = ''
self.marker = ''
self.max_results = 0
self.next_marker = ''

class ContainerEnumResults(EnumResultsBase):
def __init__(self):
EnumResultsBase.__init__(self)
self.containers = []
def __iter__(self):
return iter(self.containers)
def __len__(self):
return len(self.containers)
def __getitem__(self, index):
return self.containers[index]

class Container(WindowsAzureData):
def __init__(self):
Expand Down Expand Up @@ -128,9 +129,14 @@ def __iter__(self):

class BlobEnumResults(EnumResultsBase):
def __init__(self):
EnumResultsBase.__init__(self)
self.blobs = []
def __iter__(self):
return iter(self.blobs)
def __len__(self):
return len(self.blobs)
def __getitem__(self, index):
return self.blobs[index]

class Blob(WindowsAzureData):
def __init__(self):
Expand Down Expand Up @@ -187,9 +193,14 @@ def __iter__(self):

class QueueEnumResults(EnumResultsBase):
def __init__(self):
EnumResultsBase.__init__(self)
self.queues = []
def __iter__(self):
return iter(self.queues)
def __len__(self):
return len(self.queues)
def __getitem__(self, index):
return self.queues[index]

class Queue(WindowsAzureData):
def __init__(self):
Expand All @@ -202,6 +213,10 @@ def __init__(self):
self.queue_messages = []
def __iter__(self):
return iter(self.queue_messages)
def __len__(self):
return len(self.queue_messages)
def __getitem__(self, index):
return self.queue_messages[index]

class QueueMessage(WindowsAzureData):
def __init__(self):
Expand All @@ -215,9 +230,14 @@ def __init__(self):

class TableEnumResult(EnumResultsBase):
def __init__():
EnumResultsBase.__init__(self)
self.tables = []
def __iter__(self):
return iter(self.tables)
def __len__(self):
return len(self.tables)
def __getitem__(self, index):
return self.tables[index]

class Entity(WindowsAzureData):
pass
Expand Down Expand Up @@ -323,8 +343,6 @@ def _sign_storage_blob_request(request, account_name, account_key):
else:
string_to_sign += '\n' + ',' + value

storageLogger.debug("sign string: " + string_to_sign)

#sign the request
decode_account_key = base64.b64decode(account_key)
signed_hmac_sha256 = hmac.HMAC(decode_account_key, string_to_sign, hashlib.sha256)
Expand Down Expand Up @@ -352,8 +370,6 @@ def _sign_storage_table_request(request, account_name, account_key):
string_to_sign += '?comp=' + value
break

storageLogger.debug("sign string: " + string_to_sign)

#sign the request
decode_account_key = base64.b64decode(account_key)
signed_hmac_sha256 = hmac.HMAC(decode_account_key, string_to_sign, hashlib.sha256)
Expand Down
Loading