Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
| Arguments:
| ``collection_name`` -- the name of the collection to return
| Keyword arguments:
| ``reset_collection`` -- when True any existant data in the collection is deleted before it is returned
| ``create_if_missing`` -- when False a ValueError is raised if the collection doesn't exist
| ``error_if_exists`` -- When True a ValueError is raised if the collection already exists
"""
if collection_name not in self.collections_cache:
data = self.collections_set.get(collection_name.encode())
if data == None:
if create_if_missing == False:
raise ValueError("Collection '{0}' does not exist".format(collection_name))
self.collections_set.put(collection_name.encode(), b'true')
self.collections_cache[collection_name] = Collection(self, self.collection_items_set, collection_name)
elif error_if_exists:
raise ValueError("Collection '{0}' already exists".format(collection_name))
if reset_collection:
self.collections_cache[collection_name].delete_all()
return self.collections_cache[collection_name]