massive refactoring to switch from camelCase to snake_case:

historically, Libervia (SàT before) was using camelCase as allowed by PEP8 when using a
pre-PEP8 code, to use the same coding style as in Twisted.

However, snake_case is more readable and it's better to follow PEP8 best practices, so it
has been decided to move on full snake_case. Because Libervia has a huge codebase, this
ended with a ugly mix of camelCase and snake_case.

To fix that, this patch does a big refactoring by renaming every function and method
(including bridge) that are not coming from Twisted or Wokkel, to use fully snake_case.

This is a massive change, and may result in some bugs.
This commit is contained in:
Goffi 2023-04-08 13:54:42 +02:00
commit 6a6f15707a

View file

@ -51,7 +51,7 @@ class PersistentDict:
self.namespace = namespace
self.profile = profile
def _setCache(self, data):
def _set_cache(self, data):
self._cache = data
def load(self):
@ -60,10 +60,10 @@ class PersistentDict:
need to be called before any other operation
@return: defers the PersistentDict instance itself
"""
d = defer.ensureDeferred(self.storage.getPrivates(
d = defer.ensureDeferred(self.storage.get_privates(
self.namespace, binary=self.binary, profile=self.profile
))
d.addCallback(self._setCache)
d.addCallback(self._set_cache)
d.addCallback(lambda __: self)
return d
@ -117,20 +117,20 @@ class PersistentDict:
def __setitem__(self, key, value):
defer.ensureDeferred(
self.storage.setPrivateValue(
self.storage.set_private_value(
self.namespace, key, value, self.binary, self.profile
)
)
return self._cache.__setitem__(key, value)
def __delitem__(self, key):
self.storage.delPrivateValue(self.namespace, key, self.binary, self.profile)
self.storage.del_private_value(self.namespace, key, self.binary, self.profile)
return self._cache.__delitem__(key)
def clear(self):
"""Delete all values from this namespace"""
self._cache.clear()
return self.storage.delPrivateNamespace(self.namespace, self.binary, self.profile)
return self.storage.del_private_namespace(self.namespace, self.binary, self.profile)
def get(self, key, default=None):
return self._cache.get(key, default)
@ -139,7 +139,7 @@ class PersistentDict:
"""Async set, return a Deferred fired when value is actually stored"""
self._cache.__setitem__(key, value)
return defer.ensureDeferred(
self.storage.setPrivateValue(
self.storage.set_private_value(
self.namespace, key, value, self.binary, self.profile
)
)
@ -147,7 +147,7 @@ class PersistentDict:
def adel(self, key):
"""Async del, return a Deferred fired when value is actually deleted"""
self._cache.__delitem__(key)
return self.storage.delPrivateValue(
return self.storage.del_private_value(
self.namespace, key, self.binary, self.profile)
def setdefault(self, key, default):
@ -163,7 +163,7 @@ class PersistentDict:
@return: deferred fired when data is actually saved
"""
return defer.ensureDeferred(
self.storage.setPrivateValue(
self.storage.set_private_value(
self.namespace, name, self._cache[name], self.binary, self.profile
)
)
@ -192,14 +192,14 @@ class LazyPersistentBinaryDict(PersistentBinaryDict):
raise NotImplementedError
def items(self):
d = defer.ensureDeferred(self.storage.getPrivates(
d = defer.ensureDeferred(self.storage.get_privates(
self.namespace, binary=self.binary, profile=self.profile
))
d.addCallback(lambda data_dict: data_dict.items())
return d
def all(self):
return defer.ensureDeferred(self.storage.getPrivates(
return defer.ensureDeferred(self.storage.get_privates(
self.namespace, binary=self.binary, profile=self.profile
))
@ -252,7 +252,7 @@ class LazyPersistentBinaryDict(PersistentBinaryDict):
def __getitem__(self, key):
"""get the value as a Deferred"""
d = defer.ensureDeferred(self.storage.getPrivates(
d = defer.ensureDeferred(self.storage.get_privates(
self.namespace, keys=[key], binary=self.binary, profile=self.profile
))
d.addCallback(self._data2value, key)
@ -260,21 +260,21 @@ class LazyPersistentBinaryDict(PersistentBinaryDict):
def __setitem__(self, key, value):
defer.ensureDeferred(
self.storage.setPrivateValue(
self.storage.set_private_value(
self.namespace, key, value, self.binary, self.profile
)
)
def __delitem__(self, key):
self.storage.delPrivateValue(self.namespace, key, self.binary, self.profile)
self.storage.del_private_value(self.namespace, key, self.binary, self.profile)
def _defaultOrException(self, failure_, default):
def _default_or_exception(self, failure_, default):
failure_.trap(KeyError)
return default
def get(self, key, default=None):
d = self.__getitem__(key)
d.addErrback(self._defaultOrException, default=default)
d.addErrback(self._default_or_exception, default=default)
return d
def aset(self, key, value):
@ -282,7 +282,7 @@ class LazyPersistentBinaryDict(PersistentBinaryDict):
# FIXME: redundant with force, force must be removed
# XXX: similar as PersistentDict.aset, but doesn't use cache
return defer.ensureDeferred(
self.storage.setPrivateValue(
self.storage.set_private_value(
self.namespace, key, value, self.binary, self.profile
)
)
@ -290,7 +290,7 @@ class LazyPersistentBinaryDict(PersistentBinaryDict):
def adel(self, key):
"""Async del, return a Deferred fired when value is actually deleted"""
# XXX: similar as PersistentDict.adel, but doesn't use cache
return self.storage.delPrivateValue(
return self.storage.del_private_value(
self.namespace, key, self.binary, self.profile)
def setdefault(self, key, default):
@ -303,7 +303,7 @@ class LazyPersistentBinaryDict(PersistentBinaryDict):
@return: deferred fired when data is actually saved
"""
return defer.ensureDeferred(
self.storage.setPrivateValue(
self.storage.set_private_value(
self.namespace, name, value, self.binary, self.profile
)
)
@ -314,4 +314,4 @@ class LazyPersistentBinaryDict(PersistentBinaryDict):
@param key(unicode): key to delete
@return (D): A deferred fired when delete is done
"""
return self.storage.delPrivateValue(self.namespace, key, self.binary, self.profile)
return self.storage.del_private_value(self.namespace, key, self.binary, self.profile)