Skip to content

Commit

Permalink
Merge pull request #419 from huguesv/lap8
Browse files Browse the repository at this point in the history
Fix imports, fix test data path, remove unneeded fields on httpclient
  • Loading branch information
Hugues Valois committed Jul 10, 2015
2 parents 74ea54f + 5e4033e commit 1f84599
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 62 deletions.
22 changes: 9 additions & 13 deletions azure-servicebus/azure/servicebus/_http/httpclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@ def __init__(self, service_instance, cert_file=None, protocol='https',
user agent string to set in http header.
'''
self.service_instance = service_instance
self.status = None
self.respheader = None
self.message = None
self.cert_file = cert_file
self.protocol = protocol
self.proxy_host = None
Expand Down Expand Up @@ -215,13 +212,13 @@ def perform_request(self, request):
pass

resp = connection.getresponse()
self.status = int(resp.status)
self.message = resp.reason
self.respheader = headers = resp.getheaders()
status = int(resp.status)
message = resp.reason
respheaders = resp.getheaders()

# for consistency across platforms, make header names lowercase
for i, value in enumerate(headers):
headers[i] = (value[0].lower(), value[1])
for i, value in enumerate(respheaders):
respheaders[i] = (value[0].lower(), value[1])

respbody = None
if resp.length is None:
Expand All @@ -237,16 +234,15 @@ def perform_request(self, request):
pass

response = HTTPResponse(
int(resp.status), resp.reason, headers, respbody)
if self.status == 307:
status, resp.reason, respheaders, respbody)
if status == 307:
new_url = urlparse(dict(headers)['location'])
request.host = new_url.hostname
request.path = new_url.path
request.path, request.query = self._update_request_uri_query(request)
return self.perform_request(request)
if self.status >= 300:
raise HTTPError(self.status, self.message,
self.respheader, respbody)
if status >= 300:
raise HTTPError(status, message, respheaders, respbody)

return response
finally:
Expand Down
2 changes: 1 addition & 1 deletion azure-servicebus/tests/test_servicebus_eventhub.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
TestMode,
record,
)
from servicebus_testcase import ServiceBusTestCase
from tests.servicebus_testcase import ServiceBusTestCase
#------------------------------------------------------------------------------


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@ def __init__(self, service_instance, cert_file=None, protocol='https',
user agent string to set in http header.
'''
self.service_instance = service_instance
self.status = None
self.respheader = None
self.message = None
self.cert_file = cert_file
self.protocol = protocol
self.proxy_host = None
Expand Down Expand Up @@ -254,13 +251,13 @@ def perform_request(self, request):
pass

resp = connection.getresponse()
self.status = int(resp.status)
self.message = resp.reason
self.respheader = headers = resp.getheaders()
status = int(resp.status)
message = resp.reason
respheaders = resp.getheaders()

# for consistency across platforms, make header names lowercase
for i, value in enumerate(headers):
headers[i] = (value[0].lower(), value[1])
for i, value in enumerate(respheaders):
respheaders[i] = (value[0].lower(), value[1])

respbody = None
if resp.length is None:
Expand All @@ -276,16 +273,15 @@ def perform_request(self, request):
pass

response = HTTPResponse(
int(resp.status), resp.reason, headers, respbody)
if self.status == 307:
new_url = urlparse(dict(headers)['location'])
status, resp.reason, respheaders, respbody)
if status == 307:
new_url = urlparse(dict(respheaders)['location'])
request.host = new_url.hostname
request.path = new_url.path
request.path, request.query = self._update_request_uri_query(request)
return self.perform_request(request)
if self.status >= 300:
raise HTTPError(self.status, self.message,
self.respheader, respbody)
if status >= 300:
raise HTTPError(status, message, respheaders, respbody)

return response
finally:
Expand Down
7 changes: 5 additions & 2 deletions azure-servicemanagement-legacy/tests/test_legacy_mgmt_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#--------------------------------------------------------------------------

import os
import os.path
import requests
import unittest
from datetime import datetime, timedelta
Expand Down Expand Up @@ -327,10 +328,12 @@ def _upload_file_to_page_blob(self, file_path, blob_name):
return url

def _upload_default_package_to_storage_blob(self, blob_name):
return self._upload_file_to_block_blob(CSPKG_PATH, blob_name)
file_path = os.path.join(self.working_folder, CSPKG_PATH)
return self._upload_file_to_block_blob(file_path, blob_name)

def _upload_disk_to_storage_blob(self, blob_name):
return self._upload_file_to_page_blob(DATA_VHD_PATH, blob_name)
file_path = os.path.join(self.working_folder, DATA_VHD_PATH)
return self._upload_file_to_page_blob(file_path, blob_name)

def _add_deployment(self, service_name, deployment_name,
deployment_slot='Production'):
Expand Down
22 changes: 9 additions & 13 deletions azure-storage/azure/storage/_http/httpclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@ def __init__(self, service_instance, cert_file=None, protocol='https',
user agent string to set in http header.
'''
self.service_instance = service_instance
self.status = None
self.respheader = None
self.message = None
self.cert_file = cert_file
self.protocol = protocol
self.proxy_host = None
Expand Down Expand Up @@ -215,13 +212,13 @@ def perform_request(self, request):
pass

resp = connection.getresponse()
self.status = int(resp.status)
self.message = resp.reason
self.respheader = headers = resp.getheaders()
status = int(resp.status)
message = resp.reason
respheaders = resp.getheaders()

# for consistency across platforms, make header names lowercase
for i, value in enumerate(headers):
headers[i] = (value[0].lower(), value[1])
for i, value in enumerate(respheaders):
respheaders[i] = (value[0].lower(), value[1])

respbody = None
if resp.length is None:
Expand All @@ -237,16 +234,15 @@ def perform_request(self, request):
pass

response = HTTPResponse(
int(resp.status), resp.reason, headers, respbody)
if self.status == 307:
status, resp.reason, respheaders, respbody)
if status == 307:
new_url = urlparse(dict(headers)['location'])
request.host = new_url.hostname
request.path = new_url.path
request.path, request.query = self._update_request_uri_query(request)
return self.perform_request(request)
if self.status >= 300:
raise HTTPError(self.status, self.message,
self.respheader, respbody)
if status >= 300:
raise HTTPError(status, message, respheaders, respbody)

return response
finally:
Expand Down
44 changes: 25 additions & 19 deletions doc/storage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ To ensure a table exists, call **create\_table**:

.. code:: python
from azure.storage import TableService
from azure.storage.table import TableService
table_service = TableService(account_name, account_key)
table_service.create_table('tasktable')
Expand Down Expand Up @@ -46,7 +46,8 @@ To generate a shared access signature, use:

.. code:: python
from azure.storage import TableService, AccessPolicy, SharedAccessPolicy, TableSharedAccessPermissions
from azure.storage import AccessPolicy, SharedAccessPolicy
from azure.storage.table import TableService, TableSharedAccessPermissions
table_service = TableService(account_name, account_key)
ap = AccessPolicy(
expiry='2016-10-12',
Expand All @@ -61,7 +62,8 @@ Alternatively, you can define a named access policy on the server:

.. code:: python
from azure.storage import TableService, SharedAccessPolicy, TableSharedAccessPermissions, SignedIdentifier
from azure.storage import SharedAccessPolicy, SignedIdentifier
from azure.storage.table import TableService, TableSharedAccessPermissions
table_service = TableService(account_name, account_key)
policy_name = 'readonlyvaliduntilnextyear'
Expand Down Expand Up @@ -104,7 +106,7 @@ authenticate, instead of an account key:

.. code:: python
from azure.storage import TableService
from azure.storage.table import TableService
table_service = TableService(account_name, sas_token=sas_token)
entity = table_service.get_entity('tasktable', 'tasksSeattle', '1')
Expand All @@ -117,7 +119,7 @@ which to store a blob:

.. code:: python
from azure.storage import BlobService
from azure.storage.blob import BlobService
blob_service = BlobService(account_name, account_key)
blob_service.create_container('images')
Expand All @@ -126,7 +128,7 @@ To upload a file 'uploads/image.png' from disk to a blob named

.. code:: python
from azure.storage import BlobService
from azure.storage.blob import BlobService
blob_service = BlobService(account_name, account_key)
blob_service.put_block_blob_from_path(
'images',
Expand Down Expand Up @@ -166,7 +168,7 @@ To download a blob named 'image.png' to a file on disk

.. code:: python
from azure.storage import BlobService
from azure.storage.blob import BlobService
blob_service = BlobService(account_name, account_key)
blob = blob_service.get_blob_to_path(
'images',
Expand Down Expand Up @@ -221,7 +223,7 @@ omitting the ``account_key`` parameter:

.. code:: python
from azure.storage import BlobService
from azure.storage.blob import BlobService
blob_service = BlobService(account_name)
blob = blob_service.get_blob_to_path(
'images',
Expand All @@ -234,7 +236,7 @@ You can get a full URL for the blob (for use in a web browser, etc):

.. code:: python
from azure.storage import BlobService
from azure.storage.blob import BlobService
blob_service = BlobService(account_name)
url = blob_service.make_blob_url(
container_name='images',
Expand All @@ -252,7 +254,8 @@ To generate a shared access signature, use:

.. code:: python
from azure.storage import BlobService, AccessPolicy, SharedAccessPolicy, BlobSharedAccessPermissions
from azure.storage import AccessPolicy, SharedAccessPolicy
from azure.storage.blob import BlobService, BlobSharedAccessPermissions
blob_service = BlobService(account_name, account_key)
ap = AccessPolicy(
expiry='2016-10-12',
Expand All @@ -271,7 +274,8 @@ Alternatively, you can define a named access policy on the server:

.. code:: python
from azure.storage import BlobService, AccessPolicy, SharedAccessPolicy, BlobSharedAccessPermissions, SignedIdentifier
from azure.storage import AccessPolicy, SharedAccessPolicy, SignedIdentifier
from azure.storage.blob import BlobService, BlobSharedAccessPermissions
blob_service = BlobService(account_name, account_key)
policy_name = 'readonlyvaliduntilnextyear'
Expand Down Expand Up @@ -315,7 +319,7 @@ authenticate, instead of an account key:

.. code:: python
from azure.storage import BlobService
from azure.storage.blob import BlobService
blob_service = BlobService(account_name, sas_token=sas_token)
blob = blob_service.get_blob_to_path(
'images',
Expand All @@ -328,7 +332,7 @@ You can get a full URL for the blob (for use in a web browser, etc):

.. code:: python
from azure.storage import BlobService
from azure.storage.blob import BlobService
blob_service = BlobService(account_name)
url = blob_service.make_blob_url(
container_name='images',
Expand All @@ -344,7 +348,7 @@ The **create\_queue** method can be used to ensure a queue exists:

.. code:: python
from azure.storage import QueueService
from azure.storage.queue import QueueService
queue_service = QueueService(account_name, account_key)
queue_service.create_queue('taskqueue')
Expand All @@ -353,7 +357,7 @@ into the queue:

.. code:: python
from azure.storage import QueueService
from azure.storage.queue import QueueService
queue_service = QueueService(account_name, account_key)
queue_service.put_message('taskqueue', 'Hello world!')
Expand All @@ -364,7 +368,7 @@ are removed from the queue.

.. code:: python
from azure.storage import QueueService
from azure.storage.queue import QueueService
queue_service = QueueService(account_name, account_key)
messages = queue_service.get_messages('taskqueue')
queue_service.delete_message('taskqueue', messages[0].message_id, messages[0].pop_receipt)
Expand All @@ -378,7 +382,8 @@ To generate a shared access signature, use:

.. code:: python
from azure.storage import QueueService, AccessPolicy, SharedAccessPolicy, QueueSharedAccessPermissions
from azure.storage import AccessPolicy, SharedAccessPolicy
from azure.storage.queue import QueueService, QueueSharedAccessPermissions
queue_service = QueueService(account_name, account_key)
ap = AccessPolicy(
expiry='2016-10-12',
Expand All @@ -393,7 +398,8 @@ Alternatively, you can define a named access policy on the server:

.. code:: python
from azure.storage import QueueService, SharedAccessPolicy, QueueSharedAccessPermissions, SignedIdentifier
from azure.storage import SharedAccessPolicy, SignedIdentifier
from azure.storage.queue import QueueService, QueueSharedAccessPermissions
queue_service = QueueService(account_name, account_key)
policy_name = 'readonlyvaliduntilnextyear'
Expand Down Expand Up @@ -436,7 +442,7 @@ authenticate, instead of an account key:

.. code:: python
from azure.storage import QueueService
from azure.storage.queue import QueueService
queue_service = QueueService(account_name, sas_token=sas_token)
messages = queue_service.peek_messages('taskqueue')
Expand Down

0 comments on commit 1f84599

Please sign in to comment.