diff options
author | jola-mirecka <jola.mirecka@hp.com> | 2013-03-05 16:56:02 +0000 |
---|---|---|
committer | jola-mirecka <jola.mirecka@hp.com> | 2013-03-06 15:38:50 +0000 |
commit | d90b768e509e41a2ab4f8d26b1093fd329167102 (patch) | |
tree | bfbcef8b04924980a1ad72374a43a3f5d51b5564 /swiftclient/client.py | |
parent | 999e1c0f02ab4f697a0bf66c95f1744c86dc4523 (diff) | |
download | python-swiftclient-d90b768e509e41a2ab4f8d26b1093fd329167102.tar.gz |
Enhance put_object to inform when chunk is ignored
Changed documentation for chunk_size parameter to indicate
that it can be used only with file like objects.
Also added a UserWarning when using a string contents to inform
that chunk_size will be ignored.
Added a unit test to check whether the warning is working
correctly.
Fixes: bug #1147232
Change-Id: I618ec45520ba81905ce2ead4d61f192d21ae3489
Diffstat (limited to 'swiftclient/client.py')
-rw-r--r-- | swiftclient/client.py | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/swiftclient/client.py b/swiftclient/client.py index 1ffd1b4..3005a57 100644 --- a/swiftclient/client.py +++ b/swiftclient/client.py @@ -21,6 +21,7 @@ import socket import os import sys import logging +import warnings from functools import wraps from urllib import quote as _quote @@ -764,7 +765,7 @@ def head_object(url, token, container, name, http_conn=None): def put_object(url, token=None, container=None, name=None, contents=None, - content_length=None, etag=None, chunk_size=65536, + content_length=None, etag=None, chunk_size=None, content_type=None, headers=None, http_conn=None, proxy=None): """ Put an object @@ -782,7 +783,9 @@ def put_object(url, token=None, container=None, name=None, contents=None, computed via the contents or chunked transfer encoding will be used :param etag: etag of contents; if None, no etag will be sent - :param chunk_size: chunk size of data to write; default 65536 + :param chunk_size: chunk size of data to write; it defaults to 65536; + used only if the the contents object has a 'read' + method, eg. 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) @@ -822,6 +825,8 @@ def put_object(url, token=None, container=None, name=None, contents=None, if not contents: headers['Content-Length'] = '0' if hasattr(contents, 'read'): + if chunk_size is None: + chunk_size = 65536 conn.putrequest('PUT', path) for header, value in headers.iteritems(): conn.putheader(header, value) @@ -844,6 +849,10 @@ def put_object(url, token=None, container=None, name=None, contents=None, conn.send(chunk) left -= len(chunk) else: + if chunk_size is not None: + warn_msg = '%s object has no \"read\" method, ignoring chunk_size'\ + % type(contents).__name__ + warnings.warn(warn_msg, stacklevel=2) conn.request('PUT', path, contents, headers) resp = conn.getresponse() body = resp.read() @@ -1082,7 +1091,7 @@ class Connection(object): resp_chunk_size=resp_chunk_size) def put_object(self, container, obj, contents, content_length=None, - etag=None, chunk_size=65536, content_type=None, + etag=None, chunk_size=None, content_type=None, headers=None): """Wrapper for :func:`put_object`""" |