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
3 changes: 3 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

## Version 0.32.0:

### All:
- request_callback and response_callback functions may be set on the service clients. These callbacks will be run before the request is executed and after the response is received, respectively. They maybe used to add custom headers to the request and for logging, among other purposes.

### Blob:
- Get requests taking the start_range parameter incorrectly sent an x-ms-range header when start_range was not specified.
- get_blob_to_* will do an initial get request of size 32 MB. If it then finds the blob is larger than this size, it will parallelize by default.
Expand Down
2 changes: 2 additions & 0 deletions azure/storage/_http/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class HTTPError(Exception):
the status code of the response
:ivar str message:
the message
:ivar list headers:
the returned headers, as a list of (name, value) pairs
:ivar bytes body:
the body of the response
'''
Expand Down
8 changes: 1 addition & 7 deletions azure/storage/_http/httpclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,4 @@ def perform_request(self, request):
for key, name in response.headers.items():
respheaders.append((key.lower(), name))

# Construct an error or a response based on status code
if status >= 300:
# This exception will be caught by the general error handler
# and raised as an azure http exception
raise HTTPError(status, response.reason, respheaders, response.content)
else:
return HTTPResponse(status, response.reason, respheaders, response.content)
return HTTPResponse(status, response.reason, respheaders, response.content)
21 changes: 11 additions & 10 deletions azure/storage/_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,9 @@ def _update_request(request):
request.headers.append(('Content-Length', str(len(request.body))))

# append addtional headers based on the service
current_time = format_date_time(time())
request.headers.append(('x-ms-date', current_time))
request.headers.append(('x-ms-version', X_MS_VERSION))
request.headers.append(('User-Agent', _USER_AGENT_STRING))

# append x-ms-meta name, values to header
for name, value in request.headers:
if 'x-ms-meta-name-values' in name and value:
for meta_name, meta_value in value.items():
request.headers.append(('x-ms-meta-' + meta_name, meta_value))
request.headers.remove((name, value))
break

# If the host has a path component (ex local storage), move it
path = request.host.split('/', 1)
if len(path) == 2:
Expand All @@ -85,6 +75,17 @@ def _update_request(request):
# Encode and optionally add local storage prefix to path
request.path = url_quote(request.path, '/()$=\',~')

def _add_metadata_headers(metadata, request):
if metadata:
if not request.headers:
request.headers = []
for name, value in metadata.items():
request.headers.append(('x-ms-meta-' + name, value))

def _add_date_header(request):
current_time = format_date_time(time())
request.headers.append(('x-ms-date', current_time))

def _get_request_body_bytes_only(param_name, param_value):
'''Validates the request body passed in and converts it to bytes
if our policy allows it.'''
Expand Down
3 changes: 2 additions & 1 deletion azure/storage/blob/appendblobservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
)
from .._serialization import (
_get_request_body_bytes_only,
_add_metadata_headers,
)
from .._http import HTTPRequest
from ._upload_chunking import (
Expand Down Expand Up @@ -172,13 +173,13 @@ def create_blob(self, container_name, blob_name, content_settings=None,
request.query = [('timeout', _int_to_str(timeout))]
request.headers = [
('x-ms-blob-type', _to_str(self.blob_type)),
('x-ms-meta-name-values', metadata),
('x-ms-lease-id', _to_str(lease_id)),
('If-Modified-Since', _datetime_to_utc_string(if_modified_since)),
('If-Unmodified-Since', _datetime_to_utc_string(if_unmodified_since)),
('If-Match', _to_str(if_match)),
('If-None-Match', _to_str(if_none_match))
]
_add_metadata_headers(metadata, request)
if content_settings is not None:
request.headers += content_settings._to_headers()

Expand Down
11 changes: 6 additions & 5 deletions azure/storage/blob/baseblobservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
_get_request_body,
_convert_signed_identifiers_to_xml,
_convert_service_properties_to_xml,
_add_metadata_headers,
)
from .._http import HTTPRequest
from ._download_chunking import _download_blob_chunks
Expand Down Expand Up @@ -550,9 +551,9 @@ def create_container(self, container_name, metadata=None,
('restype', 'container'),
('timeout', _int_to_str(timeout)),]
request.headers = [
('x-ms-meta-name-values', metadata),
('x-ms-blob-public-access', _to_str(public_access))
]
_add_metadata_headers(metadata, request)

if not fail_on_exist:
try:
Expand Down Expand Up @@ -663,10 +664,10 @@ def set_container_metadata(self, container_name, metadata=None,
('timeout', _int_to_str(timeout)),
]
request.headers = [
('x-ms-meta-name-values', metadata),
('If-Modified-Since', _datetime_to_utc_string(if_modified_since)),
('x-ms-lease-id', _to_str(lease_id)),
]
_add_metadata_headers(metadata, request)

response = self._perform_request(request)
return _parse_base_properties(response)
Expand Down Expand Up @@ -2333,13 +2334,13 @@ def set_blob_metadata(self, container_name, blob_name,
('timeout', _int_to_str(timeout)),
]
request.headers = [
('x-ms-meta-name-values', metadata),
('If-Modified-Since', _datetime_to_utc_string(if_modified_since)),
('If-Unmodified-Since', _datetime_to_utc_string(if_unmodified_since)),
('If-Match', _to_str(if_match)),
('If-None-Match', _to_str(if_none_match)),
('x-ms-lease-id', _to_str(lease_id)),
]
_add_metadata_headers(metadata, request)

response = self._perform_request(request)
return _parse_base_properties(response)
Expand Down Expand Up @@ -2809,13 +2810,13 @@ def snapshot_blob(self, container_name, blob_name,
('timeout', _int_to_str(timeout)),
]
request.headers = [
('x-ms-meta-name-values', metadata),
('If-Modified-Since', _datetime_to_utc_string(if_modified_since)),
('If-Unmodified-Since', _datetime_to_utc_string(if_unmodified_since)),
('If-Match', _to_str(if_match)),
('If-None-Match', _to_str(if_none_match)),
('x-ms-lease-id', _to_str(lease_id))
]
_add_metadata_headers(metadata, request)

response = self._perform_request(request)
return _parse_snapshot_blob(blob_name, response)
Expand Down Expand Up @@ -2974,7 +2975,6 @@ def copy_blob(self, container_name, blob_name, copy_source,
request.query = [('timeout', _int_to_str(timeout))]
request.headers = [
('x-ms-copy-source', _to_str(copy_source)),
('x-ms-meta-name-values', metadata),
('x-ms-source-if-modified-since',
_to_str(source_if_modified_since)),
('x-ms-source-if-unmodified-since',
Expand All @@ -2989,6 +2989,7 @@ def copy_blob(self, container_name, blob_name, copy_source,
('x-ms-lease-id', _to_str(destination_lease_id)),
('x-ms-source-lease-id', _to_str(source_lease_id))
]
_add_metadata_headers(metadata, request)

response = self._perform_request(request)
props = _parse_properties(response, BlobProperties)
Expand Down
4 changes: 2 additions & 2 deletions azure/storage/blob/blockblobservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,13 @@ def _put_blob(self, container_name, blob_name, blob, content_settings=None,
request.query = [('timeout', _int_to_str(timeout))]
request.headers = [
('x-ms-blob-type', _to_str(self.blob_type)),
('x-ms-meta-name-values', metadata),
('x-ms-lease-id', _to_str(lease_id)),
('If-Modified-Since', _datetime_to_utc_string(if_modified_since)),
('If-Unmodified-Since', _datetime_to_utc_string(if_unmodified_since)),
('If-Match', _to_str(if_match)),
('If-None-Match', _to_str(if_none_match))
]
_metadata_to_headers(metadata, request)
if content_settings is not None:
request.headers += content_settings._to_headers()
request.body = _get_request_body_bytes_only('blob', blob)
Expand Down Expand Up @@ -338,13 +338,13 @@ def put_block_list(
('timeout', _int_to_str(timeout)),
]
request.headers = [
('x-ms-meta-name-values', metadata),
('x-ms-lease-id', _to_str(lease_id)),
('If-Modified-Since', _datetime_to_utc_string(if_modified_since)),
('If-Unmodified-Since', _datetime_to_utc_string(if_unmodified_since)),
('If-Match', _to_str(if_match)),
('If-None-Match', _to_str(if_none_match)),
]
_metadata_to_headers(metadata, request)
if content_settings is not None:
request.headers += content_settings._to_headers()
request.body = _get_request_body(
Expand Down
2 changes: 1 addition & 1 deletion azure/storage/blob/pageblobservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ def create_blob(
request.query = [('timeout', _int_to_str(timeout))]
request.headers = [
('x-ms-blob-type', _to_str(self.blob_type)),
('x-ms-meta-name-values', metadata),
('x-ms-blob-content-length', _to_str(content_length)),
('x-ms-lease-id', _to_str(lease_id)),
('x-ms-blob-sequence-number', _to_str(sequence_number)),
Expand All @@ -201,6 +200,7 @@ def create_blob(
('If-Match', _to_str(if_match)),
('If-None-Match', _to_str(if_none_match))
]
_metadata_to_headers(metadata, request)
if content_settings is not None:
request.headers += content_settings._to_headers()

Expand Down
15 changes: 8 additions & 7 deletions azure/storage/file/fileservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
_get_request_body_bytes_only,
_convert_signed_identifiers_to_xml,
_convert_service_properties_to_xml,
_add_metadata_headers,
)
from .._deserialization import (
_convert_xml_to_service_properties,
Expand Down Expand Up @@ -630,8 +631,8 @@ def create_share(self, share_name, metadata=None, quota=None,
('timeout', _int_to_str(timeout)),
]
request.headers = [
('x-ms-meta-name-values', metadata),
('x-ms-share-quota', _int_to_str(quota))]
_add_metadata_headers(metadata, request)

if not fail_on_exist:
try:
Expand Down Expand Up @@ -749,7 +750,7 @@ def set_share_metadata(self, share_name, metadata=None, timeout=None):
('comp', 'metadata'),
('timeout', _int_to_str(timeout)),
]
request.headers = [('x-ms-meta-name-values', metadata)]
_add_metadata_headers(metadata, request)

self._perform_request(request)

Expand Down Expand Up @@ -910,7 +911,7 @@ def create_directory(self, share_name, directory_name, metadata=None,
('restype', 'directory'),
('timeout', _int_to_str(timeout)),
]
request.headers = [('x-ms-meta-name-values', metadata)]
_add_metadata_headers(metadata, request)

if not fail_on_exist:
try:
Expand Down Expand Up @@ -1056,7 +1057,7 @@ def set_directory_metadata(self, share_name, directory_name, metadata=None, time
('comp', 'metadata'),
('timeout', _int_to_str(timeout)),
]
request.headers = [('x-ms-meta-name-values', metadata)]
_add_metadata_headers(metadata, request)

self._perform_request(request)

Expand Down Expand Up @@ -1325,7 +1326,7 @@ def set_file_metadata(self, share_name, directory_name,
('comp', 'metadata'),
('timeout', _int_to_str(timeout)),
]
request.headers = [('x-ms-meta-name-values', metadata)]
_add_metadata_headers(metadata, request)

self._perform_request(request)

Expand Down Expand Up @@ -1378,8 +1379,8 @@ def copy_file(self, share_name, directory_name, file_name, copy_source,
request.query = [('timeout', _int_to_str(timeout))]
request.headers = [
('x-ms-copy-source', _to_str(copy_source)),
('x-ms-meta-name-values', metadata),
]
_add_metadata_headers(metadata, request)

response = self._perform_request(request)
props = _parse_properties(response, FileProperties)
Expand Down Expand Up @@ -1479,10 +1480,10 @@ def create_file(self, share_name, directory_name, file_name,
request.path = _get_path(share_name, directory_name, file_name)
request.query = [('timeout', _int_to_str(timeout))]
request.headers = [
('x-ms-meta-name-values', metadata),
('x-ms-content-length', _to_str(content_length)),
('x-ms-type', 'file')
]
_add_metadata_headers(metadata, request)
if content_settings is not None:
request.headers += content_settings._to_headers()

Expand Down
7 changes: 5 additions & 2 deletions azure/storage/queue/queueservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
)
from .._serialization import (
_get_request_body,
_add_metadata_headers,
)
from .._common_conversion import (
_int_to_str,
Expand Down Expand Up @@ -484,7 +485,8 @@ def create_queue(self, queue_name, metadata=None, fail_on_exist=False, timeout=N
request.host = self._get_host()
request.path = _get_path(queue_name)
request.query = [('timeout', _int_to_str(timeout))]
request.headers = [('x-ms-meta-name-values', metadata)]
_add_metadata_headers(metadata, request)

if not fail_on_exist:
try:
response = self._perform_request(request)
Expand Down Expand Up @@ -591,7 +593,8 @@ def set_queue_metadata(self, queue_name, metadata=None, timeout=None):
('comp', 'metadata'),
('timeout', _int_to_str(timeout)),
]
request.headers = [('x-ms-meta-name-values', metadata)]
_add_metadata_headers(metadata, request)

self._perform_request(request)

def exists(self, queue_name, timeout=None):
Expand Down
Loading