Commit 3ad2d844 authored by Sofia Papagiannaki's avatar Sofia Papagiannaki
Browse files

Eliminate mutable default arguments

parent 8a5cfda8
......@@ -2182,7 +2182,8 @@ class TestPermissions(BaseTestCase):
self.upload_random_data(self.container, self.object+'a/')
self.dir_content_types = ('application/directory', 'application/folder')
def assert_read(self, authorized=[], any=False, depth=0):
def assert_read(self, authorized=None, any=False, depth=0):
authorized = authorized or []
for token, account in OTHER_ACCOUNTS.items():
cl = Pithos_Client(get_url(), token, account)
if account in authorized or any:
......@@ -2213,7 +2214,8 @@ class TestPermissions(BaseTestCase):
self.assert_raises_fault(403, cl.retrieve_object_metadata,
self.container, o, account=get_user())
def assert_write(self, authorized=[], any=False):
def assert_write(self, authorized=None, any=False):
authorized = authorized or []
o_data = self.client.retrieve_object(self.container, self.object)
for token, account in OTHER_ACCOUNTS.items():
cl = Pithos_Client(get_url(), token, account)
......
......@@ -303,7 +303,9 @@ class SwissArmy():
return self.backend._lookup_account(account, create=True)
def create_update_object(self, account, container, name, content_type,
data, meta={}, permissions={}, request_user=None):
data, meta=None, permissions=None, request_user=None):
meta = meta or {}
permissions = permissions or {}
md5 = hashlib.md5()
size = 0
hashmap = []
......
......@@ -59,8 +59,9 @@ class SwissArmyTests(unittest.TestCase):
self.utils._delete_account(i)
self.utils.cleanup()
def _verify_object(self, account, container, object, expected={},
def _verify_object(self, account, container, object, expected=None,
strict=True):
expected = expected or {}
self._verify_object_metadata(account, container, object,
expected.get('meta'))
self._verify_object_history(account, container, object,
......
......@@ -176,7 +176,7 @@ class BaseBackend(object):
"""
return
def put_account(self, user, account, policy={}):
def put_account(self, user, account, policy=None):
"""Create a new account with the given name.
Raises:
......@@ -289,7 +289,7 @@ class BaseBackend(object):
"""
return
def put_container(self, user, account, container, policy={}, delimiter=None):
def put_container(self, user, account, container, policy=None, delimiter=None):
"""Create a new container with the given name.
Parameters:
......@@ -316,7 +316,7 @@ class BaseBackend(object):
"""
return
def list_objects(self, user, account, container, prefix='', delimiter=None, marker=None, limit=10000, virtual=True, domain=None, keys=[], shared=False, until=None, size_range=None, public=False):
def list_objects(self, user, account, container, prefix='', delimiter=None, marker=None, limit=10000, virtual=True, domain=None, keys=None, shared=False, until=None, size_range=None, public=False):
"""Return a list of object (name, version_id) tuples existing under a container.
Parameters:
......@@ -355,7 +355,7 @@ class BaseBackend(object):
"""
return []
def list_object_meta(self, user, account, container, prefix='', delimiter=None, marker=None, limit=10000, virtual=True, domain=None, keys=[], shared=False, until=None, size_range=None):
def list_object_meta(self, user, account, container, prefix='', delimiter=None, marker=None, limit=10000, virtual=True, domain=None, keys=None, shared=False, until=None, size_range=None):
"""Return a list of object metadata dicts existing under a container.
Same parameters with list_objects. Returned dicts have no user-defined
......@@ -497,7 +497,7 @@ class BaseBackend(object):
"""
return 0, []
def update_object_hashmap(self, user, account, container, name, size, type, hashmap, checksum, domain, meta={}, replace_meta=False, permissions=None):
def update_object_hashmap(self, user, account, container, name, size, type, hashmap, checksum, domain, meta=None, replace_meta=False, permissions=None):
"""Create/update an object with the specified size and partial hashes and return the new version.
Parameters:
......@@ -524,7 +524,7 @@ class BaseBackend(object):
"""Update an object's checksum."""
return
def copy_object(self, user, src_account, src_container, src_name, dest_account, dest_container, dest_name, type, domain, meta={}, replace_meta=False, permissions=None, src_version=None, delimiter=None):
def copy_object(self, user, src_account, src_container, src_name, dest_account, dest_container, dest_name, type, domain, meta=None, replace_meta=False, permissions=None, src_version=None, delimiter=None):
"""Copy an object's data and metadata and return the new version.
Parameters:
......@@ -553,7 +553,7 @@ class BaseBackend(object):
"""
return ''
def move_object(self, user, src_account, src_container, src_name, dest_account, dest_container, dest_name, type, domain, meta={}, replace_meta=False, permissions=None, delimiter=None):
def move_object(self, user, src_account, src_container, src_name, dest_account, dest_container, dest_name, type, domain, meta=None, replace_meta=False, permissions=None, delimiter=None):
"""Move an object's data and metadata and return the new version.
Parameters:
......
......@@ -868,12 +868,14 @@ class Node(DBWorker):
'key': k, 'value': v}
self.conn.execute(s, values).close()
def latest_attribute_keys(self, parent, domain, before=inf, except_cluster=0, pathq=[]):
def latest_attribute_keys(self, parent, domain, before=inf, except_cluster=0, pathq=None):
"""Return a list with all keys pairs defined
for all latest versions under parent that
do not belong to the cluster.
"""
pathq = pathq or []
# TODO: Use another table to store before=inf results.
a = self.attributes.alias('a')
v = self.versions.alias('v')
......
......@@ -804,12 +804,14 @@ class Node(DBWorker):
args += [before]
return q % where_cond, args
def latest_attribute_keys(self, parent, domain, before=inf, except_cluster=0, pathq=[]):
def latest_attribute_keys(self, parent, domain, before=inf, except_cluster=0, pathq=None):
"""Return a list with all keys pairs defined
for all latest versions under parent that
do not belong to the cluster.
"""
pathq = pathq or []
# TODO: Use another table to store before=inf results.
q = ("select distinct a.key "
"from attributes a, versions v, nodes n "
......
......@@ -351,10 +351,11 @@ class ModularBackend(BaseBackend):
self._put_policy(node, policy, replace)
@backend_method
def put_account(self, user, account, policy={}):
def put_account(self, user, account, policy=None):
"""Create a new account with the given name."""
logger.debug("put_account: %s %s %s", user, account, policy)
policy = policy or {}
if user != account:
raise NotAllowedError
node = self.node.node_lookup(account)
......@@ -502,11 +503,12 @@ class ModularBackend(BaseBackend):
self._put_policy(node, policy, replace)
@backend_method
def put_container(self, user, account, container, policy={}):
def put_container(self, user, account, container, policy=None):
"""Create a new container with the given name."""
logger.debug(
"put_container: %s %s %s %s", user, account, container, policy)
policy = policy or {}
if user != account:
raise NotAllowedError
try:
......@@ -669,17 +671,19 @@ class ModularBackend(BaseBackend):
return allowed
@backend_method
def list_objects(self, user, account, container, prefix='', delimiter=None, marker=None, limit=10000, virtual=True, domain=None, keys=[], shared=False, until=None, size_range=None, public=False):
def list_objects(self, user, account, container, prefix='', delimiter=None, marker=None, limit=10000, virtual=True, domain=None, keys=None, shared=False, until=None, size_range=None, public=False):
"""Return a list of object (name, version_id) tuples existing under a container."""
logger.debug("list_objects: %s %s %s %s %s %s %s %s %s %s %s %s %s %s", user, account, container, prefix, delimiter, marker, limit, virtual, domain, keys, shared, until, size_range, public)
keys = keys or []
return self._list_objects(user, account, container, prefix, delimiter, marker, limit, virtual, domain, keys, shared, until, size_range, False, public)
@backend_method
def list_object_meta(self, user, account, container, prefix='', delimiter=None, marker=None, limit=10000, virtual=True, domain=None, keys=[], shared=False, until=None, size_range=None, public=False):
def list_object_meta(self, user, account, container, prefix='', delimiter=None, marker=None, limit=10000, virtual=True, domain=None, keys=None, shared=False, until=None, size_range=None, public=False):
"""Return a list of object metadata dicts existing under a container."""
logger.debug("list_object_meta: %s %s %s %s %s %s %s %s %s %s %s %s %s %s", user, account, container, prefix, delimiter, marker, limit, virtual, domain, keys, shared, until, size_range, public)
keys = keys or []
props = self._list_objects(user, account, container, prefix, delimiter, marker, limit, virtual, domain, keys, shared, until, size_range, True, public)
objects = []
for p in props:
......@@ -893,11 +897,12 @@ class ModularBackend(BaseBackend):
return dest_version_id
@backend_method
def update_object_hashmap(self, user, account, container, name, size, type, hashmap, checksum, domain, meta={}, replace_meta=False, permissions=None):
def update_object_hashmap(self, user, account, container, name, size, type, hashmap, checksum, domain, meta=None, replace_meta=False, permissions=None):
"""Create/update an object with the specified size and partial hashes."""
logger.debug("update_object_hashmap: %s %s %s %s %s %s %s %s", user,
account, container, name, size, type, hashmap, checksum)
meta = meta or {}
if size == 0: # No such thing as an empty hashmap.
hashmap = [self.put_block('')]
map = HashMap(self.block_size, self.hash_algorithm)
......@@ -929,7 +934,8 @@ class ModularBackend(BaseBackend):
self.node.version_put_property(
x[self.SERIAL], 'checksum', checksum)
def _copy_object(self, user, src_account, src_container, src_name, dest_account, dest_container, dest_name, type, dest_domain=None, dest_meta={}, replace_meta=False, permissions=None, src_version=None, is_move=False, delimiter=None):
def _copy_object(self, user, src_account, src_container, src_name, dest_account, dest_container, dest_name, type, dest_domain=None, dest_meta=None, replace_meta=False, permissions=None, src_version=None, is_move=False, delimiter=None):
dest_meta = dest_meta or {}
dest_version_ids = []
self._can_read(user, src_account, src_container, src_name)
path, node = self._lookup_object(src_account, src_container, src_name)
......@@ -969,18 +975,20 @@ class ModularBackend(BaseBackend):
return dest_version_ids[0] if len(dest_version_ids) == 1 else dest_version_ids
@backend_method
def copy_object(self, user, src_account, src_container, src_name, dest_account, dest_container, dest_name, type, domain, meta={}, replace_meta=False, permissions=None, src_version=None, delimiter=None):
def copy_object(self, user, src_account, src_container, src_name, dest_account, dest_container, dest_name, type, domain, meta=None, replace_meta=False, permissions=None, src_version=None, delimiter=None):
"""Copy an object's data and metadata."""
logger.debug("copy_object: %s %s %s %s %s %s %s %s %s %s %s %s %s %s", user, src_account, src_container, src_name, dest_account, dest_container, dest_name, type, domain, meta, replace_meta, permissions, src_version, delimiter)
meta = meta or {}
dest_version_id = self._copy_object(user, src_account, src_container, src_name, dest_account, dest_container, dest_name, type, domain, meta, replace_meta, permissions, src_version, False, delimiter)
return dest_version_id
@backend_method
def move_object(self, user, src_account, src_container, src_name, dest_account, dest_container, dest_name, type, domain, meta={}, replace_meta=False, permissions=None, delimiter=None):
def move_object(self, user, src_account, src_container, src_name, dest_account, dest_container, dest_name, type, domain, meta=None, replace_meta=False, permissions=None, delimiter=None):
"""Move an object's data and metadata."""
logger.debug("move_object: %s %s %s %s %s %s %s %s %s %s %s %s %s", user, src_account, src_container, src_name, dest_account, dest_container, dest_name, type, domain, meta, replace_meta, permissions, delimiter)
meta = meta or {}
if user != src_account:
raise NotAllowedError
dest_version_id = self._copy_object(user, src_account, src_container, src_name, dest_account, dest_container, dest_name, type, domain, meta, replace_meta, permissions, None, True, delimiter)
......@@ -1281,7 +1289,9 @@ class ModularBackend(BaseBackend):
limit = 10000
return start, limit
def _list_object_properties(self, parent, path, prefix='', delimiter=None, marker=None, limit=10000, virtual=True, domain=None, keys=[], until=None, size_range=None, allowed=[], all_props=False):
def _list_object_properties(self, parent, path, prefix='', delimiter=None, marker=None, limit=10000, virtual=True, domain=None, keys=None, until=None, size_range=None, allowed=None, all_props=False):
keys = keys or []
allowed = allowed or []
cont_prefix = path + '/'
prefix = cont_prefix + prefix
start = cont_prefix + marker if marker else None
......@@ -1297,7 +1307,9 @@ class ModularBackend(BaseBackend):
# Reporting functions.
def _report_size_change(self, user, account, size, details={}):
def _report_size_change(self, user, account, size, details=None):
details = details or {}
if size == 0:
return
......@@ -1328,16 +1340,18 @@ class ModularBackend(BaseBackend):
else:
self.serials.append(serial)
def _report_object_change(self, user, account, path, details={}):
def _report_object_change(self, user, account, path, details=None):
details = details or {}
details.update({'user': user})
logger.debug("_report_object_change: %s %s %s %s", user,
account, path, details)
self.messages.append((QUEUE_MESSAGE_KEY_PREFIX % ('object',),
account, QUEUE_INSTANCE_ID, 'object', path, details))
def _report_sharing_change(self, user, account, path, details={}):
def _report_sharing_change(self, user, account, path, details=None):
logger.debug("_report_permissions_change: %s %s %s %s",
user, account, path, details)
details = details or {}
details.update({'user': user})
self.messages.append((QUEUE_MESSAGE_KEY_PREFIX % ('sharing',),
account, QUEUE_INSTANCE_ID, 'sharing', path, details))
......
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