summaryrefslogtreecommitdiff
path: root/swiftclient
diff options
context:
space:
mode:
authorChristian Schwede <christian.schwede@enovance.com>2014-05-20 11:41:03 +0000
committeranc <alistair.coles@hp.com>2014-05-21 14:54:18 +0100
commit258420f41049d92fc0b59b9263c8381bfe513432 (patch)
treed7be5cd0a9b8eb8997ee3ef8388fa135f6af500e /swiftclient
parente7dc8542575a613f80aeeeb1014269039940a7f0 (diff)
downloadpython-swiftclient-2.1.0.tar.gz
Fix Python3 bugs2.1.0
This patch fixes three issues that were found running functional tests with Python 3: 1. python-requests sets 'application/x-www-form-urlencoded' as content-type if the input is not a string object and no content-type is given. 2. Encoding of the headers is now only done if required. This prevents comparisons between unencoded headers and encoded prefixes and avoids unnecessary forloop-iterations. One unittest was extended to ensure it works for unencoded and encoded headers with or without the prefix. 3. Functional tests recently switched to using byte data for testing, thus the comparison needs to be a byte object as well. Change-Id: I035f8b4b9c9ccdc79820b907770a48f86d0343b4
Diffstat (limited to 'swiftclient')
-rw-r--r--swiftclient/client.py17
1 files changed, 10 insertions, 7 deletions
diff --git a/swiftclient/client.py b/swiftclient/client.py
index 5494f34..a7d0daf 100644
--- a/swiftclient/client.py
+++ b/swiftclient/client.py
@@ -186,10 +186,12 @@ class HTTPConnection:
for header, value in items:
value = encode_utf8(value)
header = header.lower()
- for target_type in 'container', 'account', 'object':
- prefix = 'x-%s-meta-' % target_type
- if header.startswith(prefix):
- header = encode_utf8(header)
+ if isinstance(header, six.string_types):
+ for target_type in 'container', 'account', 'object':
+ prefix = 'x-%s-meta-' % target_type
+ if header.startswith(prefix):
+ header = encode_utf8(header)
+ break
ret[header] = value
return ret
@@ -899,9 +901,8 @@ def put_object(url, token=None, container=None, name=None, contents=None,
:param chunk_size: chunk size of data to write; it defaults to 65536;
used only if the contents object has a 'read'
method, e.g. file-like objects, ignored otherwise
- :param content_type: value to send as content-type header; if None, no
- content-type will be set (remote end will likely try
- to auto-detect it)
+ :param content_type: value to send as content-type header; if None, an
+ empty string value will be sent
:param headers: additional headers to include in the request, if any
:param http_conn: HTTP connection object (If None, it will create the
conn object)
@@ -940,6 +941,8 @@ def put_object(url, token=None, container=None, name=None, contents=None,
content_length = int(v)
if content_type is not None:
headers['Content-Type'] = content_type
+ else: # python-requests sets application/x-www-form-urlencoded otherwise
+ headers['Content-Type'] = ''
if not contents:
headers['Content-Length'] = '0'
if hasattr(contents, 'read'):