X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osm_common%2Fdbmemory.py;h=63c93c1bafc267f5aa2a65dfa87409581eead8b1;hb=b3e750be9c2768f16bcfdbf51eea374442f5bf0b;hp=c27f846ca7065d191e76faa4d67eebb1a19abd85;hpb=3054f783ac759b221233fd0a82424aa105e4ea2e;p=osm%2Fcommon.git diff --git a/osm_common/dbmemory.py b/osm_common/dbmemory.py index c27f846..63c93c1 100644 --- a/osm_common/dbmemory.py +++ b/osm_common/dbmemory.py @@ -33,10 +33,10 @@ class DbMemory(DbBase): def get_list(self, table, filter={}): try: - l = [] + result = [] for _, row in self._find(table, self._format_filter(filter)): - l.append(deepcopy(row)) - return l + result.append(deepcopy(row)) + return result except DbException: raise except Exception as e: # TODO refine @@ -44,17 +44,17 @@ class DbMemory(DbBase): def get_one(self, table, filter={}, fail_on_empty=True, fail_on_more=True): try: - l = None + result = None for _, row in self._find(table, self._format_filter(filter)): if not fail_on_more: return deepcopy(row) - if l: + if result: raise DbException("Found more than one entry with filter='{}'".format(filter), HTTPStatus.CONFLICT.value) - l = row - if not l and fail_on_empty: + result = row + if not result and fail_on_empty: raise DbException("Not found entry with filter='{}'".format(filter), HTTPStatus.NOT_FOUND) - return deepcopy(l) + return deepcopy(result) except Exception as e: # TODO refine raise DbException(str(e)) @@ -64,7 +64,7 @@ class DbMemory(DbBase): for i, _ in self._find(table, self._format_filter(filter)): id_list.append(i) deleted = len(id_list) - for i in id_list: + for i in reversed(id_list): del self.db[table][i] return {"deleted": deleted} except DbException: @@ -94,7 +94,7 @@ class DbMemory(DbBase): raise DbException("Not found entry with filter='{}'".format(filter), HTTPStatus.NOT_FOUND) return None self.db[table][i] = deepcopy(indata) - return {"upadted": 1} + return {"updated": 1} except Exception as e: # TODO refine raise DbException(str(e))