Commit b58c1078 authored by Stavros Sachtouris's avatar Stavros Sachtouris
Browse files

Make pithos_rest_api method vars safe from None

Some vars that have not None as default value where vulnerable to None assignments
parent 06eccea2
...@@ -405,6 +405,7 @@ def spiner(size=None): ...@@ -405,6 +405,7 @@ def spiner(size=None):
i += 1 i += 1
sleep(0.1) sleep(0.1)
yield yield
yield
if __name__ == '__main__': if __name__ == '__main__':
examples = [ examples = [
......
...@@ -159,13 +159,14 @@ class PithosRestAPI(StorageClient): ...@@ -159,13 +159,14 @@ class PithosRestAPI(StorageClient):
self.set_param('update', iff=update) self.set_param('update', iff=update)
for group, usernames in groups.items(): if groups:
userstr = '' for group, usernames in groups.items():
dlm = '' userstr = ''
for user in usernames: dlm = ''
userstr = userstr + dlm + user for user in usernames:
dlm = ',' userstr = userstr + dlm + user
self.set_header('X-Account-Group-' + group, userstr) dlm = ','
self.set_header('X-Account-Group-' + group, userstr)
if metadata: if metadata:
for metaname, metaval in metadata.items(): for metaname, metaval in metadata.items():
self.set_header('X-Account-Meta-' + metaname, metaval) self.set_header('X-Account-Meta-' + metaname, metaval)
...@@ -275,8 +276,8 @@ class PithosRestAPI(StorageClient): ...@@ -275,8 +276,8 @@ class PithosRestAPI(StorageClient):
else: else:
self.set_param('path', path) self.set_param('path', path)
self.set_param('shared', iff=show_only_shared) self.set_param('shared', iff=show_only_shared)
print('la%sla' % 1 if meta else 2) if meta:
self.set_param('meta', ','.join(meta), iff=meta) self.set_param('meta', ','.join(meta))
self.set_param('until', until, iff=until) self.set_param('until', until, iff=until)
self.set_header('If-Modified-Since', if_modified_since) self.set_header('If-Modified-Since', if_modified_since)
...@@ -591,19 +592,16 @@ class PithosRestAPI(StorageClient): ...@@ -591,19 +592,16 @@ class PithosRestAPI(StorageClient):
self.set_header('Content-Encoding', content_encoding) self.set_header('Content-Encoding', content_encoding)
self.set_header('Content-Disposition', content_disposition) self.set_header('Content-Disposition', content_disposition)
self.set_header('X-Object-Manifest', manifest) self.set_header('X-Object-Manifest', manifest)
perms = None
if permissions: if permissions:
for permission_type, permission_list in permissions.items(): perms = None
if not perms: if permissions:
perms = '' # Remove permissions for perm_type, perm_list in permissions.items():
if len(permission_list) == 0: if not perms:
continue perms = '' # Remove permissions
if len(perms): if perm_list:
perms += ';' perms += ';' if perms else ''
perms += '%s=%s' % ( perms += '%s=%s' % (perm_type, ','.join(perm_list))
permission_type, self.set_header('X-Object-Sharing', perms)
','.join(permission_list, separator=','))
self.set_header('X-Object-Sharing', perms)
self.set_header('X-Object-Public', public) self.set_header('X-Object-Public', public)
if metadata: if metadata:
for key, val in metadata.items(): for key, val in metadata.items():
...@@ -687,19 +685,15 @@ class PithosRestAPI(StorageClient): ...@@ -687,19 +685,15 @@ class PithosRestAPI(StorageClient):
self.set_header('Content-Encoding', content_encoding) self.set_header('Content-Encoding', content_encoding)
self.set_header('Content-Disposition', content_disposition) self.set_header('Content-Disposition', content_disposition)
self.set_header('X-Source-Version', source_version) self.set_header('X-Source-Version', source_version)
perms = None
if permissions: if permissions:
for permission_type, permission_list in permissions.items(): perms = ''
for perm_type, perm_list in permissions.items():
if not perms: if not perms:
perms = '' # Remove permissions perms = '' # Remove permissions
if len(permission_list) == 0: if perm_list:
continue perms += ';' if perms else ''
if len(perms): perms += '%s=%s' % (perm_type, ','.join(perm_list))
perms += ';' self.set_header('X-Object-Sharing', perms)
perms += '%s=%s' % (
permission_type,
','.join(permission_list, separator=','))
self.set_header('X-Object-Sharing', perms)
self.set_header('X-Object-Public', public) self.set_header('X-Object-Public', public)
if metadata: if metadata:
for key, val in metadata.items(): for key, val in metadata.items():
...@@ -778,21 +772,19 @@ class PithosRestAPI(StorageClient): ...@@ -778,21 +772,19 @@ class PithosRestAPI(StorageClient):
self.set_header('Content-Type', content_type) self.set_header('Content-Type', content_type)
self.set_header('Content-Encoding', content_encoding) self.set_header('Content-Encoding', content_encoding)
self.set_header('Content-Disposition', content_disposition) self.set_header('Content-Disposition', content_disposition)
perms = None if permissions:
for permission_type, permission_list in permissions.items(): perms = ''
if not perms: for perm_type, perm_list in permissions.items():
perms = '' # Remove permissions if not perms:
if len(permission_list) == 0: perms = '' # Remove permissions
continue if perm_list:
if len(perms): perms += ';' if perms else ''
perms += ';' perms += '%s=%s' % (perm_type, ','.join(perm_list))
perms += '%s=%s' % ( self.set_header('X-Object-Sharing', perms)
permission_type,
','.join(permission_list, separator=','))
self.set_header('X-Object-Sharing', perms)
self.set_header('X-Object-Public', public) self.set_header('X-Object-Public', public)
for key, val in metadata.items(): if metadata:
self.set_header('X-Object-Meta-' + key, val) for key, val in metadata.items():
self.set_header('X-Object-Meta-' + key, val)
path = path4url(self.account, self.container, object) path = path4url(self.account, self.container, object)
success = kwargs.pop('success', 201) success = kwargs.pop('success', 201)
...@@ -893,18 +885,15 @@ class PithosRestAPI(StorageClient): ...@@ -893,18 +885,15 @@ class PithosRestAPI(StorageClient):
self.set_header('X-Source-Version', source_version) self.set_header('X-Source-Version', source_version)
self.set_header('X-Object-Bytes', object_bytes) self.set_header('X-Object-Bytes', object_bytes)
self.set_header('X-Object-Manifest', manifest) self.set_header('X-Object-Manifest', manifest)
perms = None if permissions:
for permission_type, permission_list in permissions.items(): perms = ''
if not perms: for perm_type, perm_list in permissions.items():
perms = '' # Remove permissions if not perms:
if len(permission_list) == 0: perms = '' # Remove permissions
continue if perm_list:
if len(perms): perms += ';' if perms else ''
perms += ';' perms += '%s=%s' % (perm_type, ','.join(perm_list))
perms += '%s=%s' % ( self.set_header('X-Object-Sharing', perms)
permission_type,
','.join(permission_list, separator=','))
self.set_header('X-Object-Sharing', perms)
self.set_header('X-Object-Public', public) self.set_header('X-Object-Public', public)
for key, val in metadata.items(): for key, val in metadata.items():
self.set_header('X-Object-Meta-' + key, val) self.set_header('X-Object-Meta-' + key, val)
......
...@@ -104,7 +104,7 @@ class Generic(TestCase): ...@@ -104,7 +104,7 @@ class Generic(TestCase):
try: try:
progress_bar.finish() progress_bar.finish()
except Exception: except Exception:
print(' DONE') print('\b DONE')
def do_with_progress_bar(self, action, msg, items): def do_with_progress_bar(self, action, msg, items):
if not items: if not items:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment