summaryrefslogtreecommitdiff
path: root/swiftclient
diff options
context:
space:
mode:
authorDaniel Wakefield <daniel.wakefield@hp.com>2014-11-06 18:48:17 +0000
committerDaniel Wakefield <daniel.wakefield@hp.com>2014-12-16 14:16:34 +0000
commit8fa6cc9b1b94c3f90eb02f1927b85e9987e65125 (patch)
treefa743bb4c9b451a1be0646a48b1762c019f6b6b7 /swiftclient
parentd59af8cc8b3f5ddf846046dd11029b84db4828ea (diff)
downloadpython-swiftclient-8fa6cc9b1b94c3f90eb02f1927b85e9987e65125.tar.gz
Fix misplaced check for None in SwiftUploadObject.
Check for None was being done after a method call which caused an attribute error if the value was None. The Method call was also a mistake and has been corrected to the hasattr function like intended. Added Tests. Closes-Bug: 1392651 Change-Id: Ifb1c84e26533bccbaddcce5738f434f36feca74e
Diffstat (limited to 'swiftclient')
-rw-r--r--swiftclient/service.py34
1 files changed, 13 insertions, 21 deletions
diff --git a/swiftclient/service.py b/swiftclient/service.py
index 55e6daa..dddb7db 100644
--- a/swiftclient/service.py
+++ b/swiftclient/service.py
@@ -258,30 +258,22 @@ class SwiftUploadObject(object):
"""
def __init__(self, source, object_name=None, options=None):
if isinstance(source, string_types):
- self.source = source
self.object_name = object_name or source
- self.options = options
+ elif source is None or hasattr(source, 'read'):
+ if not object_name or not isinstance(object_name, string_types):
+ raise SwiftError('Object names must be specified as '
+ 'strings for uploads from None or file '
+ 'like objects.')
+ self.object_name = object_name
else:
- if source.hasattr('read') or source is None:
- if object_name is None or \
- not isinstance(object_name, string_types):
- raise SwiftError(
- "Object names must be specified as strings for uploads"
- " from None or file like objects."
- )
- else:
- self.source = source
- self.object_name = object_name
- self.options = options
- else:
- raise SwiftError(
- "Unexpected source type for SwiftUploadObject: "
- "%s" % type(source)
- )
+ raise SwiftError('Unexpected source type for '
+ 'SwiftUploadObject: {0}'.format(type(source)))
+
if not self.object_name:
- raise SwiftError(
- "Object names must be specified as non-empty strings"
- )
+ raise SwiftError('Object names must not be empty strings')
+
+ self.options = options
+ self.source = source
class SwiftPostObject(object):