Mercurial > libervia-backend
diff sat/bridge/bridge_constructor/constructors/pb/pb_frontend_template.py @ 4037:524856bd7b19
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.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 08 Apr 2023 13:54:42 +0200 |
parents | 3c7a64d6f49f |
children |
line wrap: on
line diff
--- a/sat/bridge/bridge_constructor/constructors/pb/pb_frontend_template.py Fri Apr 07 15:18:39 2023 +0200 +++ b/sat/bridge/bridge_constructor/constructors/pb/pb_frontend_template.py Sat Apr 08 13:54:42 2023 +0200 @@ -55,7 +55,7 @@ setattr(self, method_name, handler) -class Bridge(object): +class bridge(object): def __init__(self): self.signals_handler = SignalsHandler() @@ -75,7 +75,7 @@ ) ) - def remoteCallback(self, result, callback): + def remote_callback(self, result, callback): """call callback with argument or None if result is not None not argument is used, @@ -112,11 +112,11 @@ callback = args.pop() d = self.root.callRemote(name, *args, **kwargs) if callback is not None: - d.addCallback(self.remoteCallback, callback) + d.addCallback(self.remote_callback, callback) if errback is not None: d.addErrback(errback) - def _initBridgeEb(self, failure_): + def _init_bridge_eb(self, failure_): log.error("Can't init bridge: {msg}".format(msg=failure_)) return failure_ @@ -127,28 +127,28 @@ """ self.root = root d = root.callRemote("initBridge", self.signals_handler) - d.addErrback(self._initBridgeEb) + d.addErrback(self._init_bridge_eb) return d - def getRootObjectEb(self, failure_): + def get_root_object_eb(self, failure_): """Call errback with appropriate bridge error""" if failure_.check(ConnectionRefusedError, ConnectError): raise exceptions.BridgeExceptionNoService else: raise failure_ - def bridgeConnect(self, callback, errback): + def bridge_connect(self, callback, errback): factory = pb.PBClientFactory() - conf = config.parseMainConf() - getConf = partial(config.getConf, conf, "bridge_pb", "") - conn_type = getConf("connection_type", "unix_socket") + conf = config.parse_main_conf() + get_conf = partial(config.get_conf, conf, "bridge_pb", "") + conn_type = get_conf("connection_type", "unix_socket") if conn_type == "unix_socket": - local_dir = Path(config.getConfig(conf, "", "local_dir")).resolve() + local_dir = Path(config.config_get(conf, "", "local_dir")).resolve() socket_path = local_dir / "bridge_pb" reactor.connectUNIX(str(socket_path), factory) elif conn_type == "socket": - host = getConf("host", "localhost") - port = int(getConf("port", 8789)) + host = get_conf("host", "localhost") + port = int(get_conf("port", 8789)) reactor.connectTCP(host, port, factory) else: raise ValueError(f"Unknown pb connection type: {conn_type!r}") @@ -156,7 +156,7 @@ d.addCallback(self._set_root) if callback is not None: d.addCallback(lambda __: callback()) - d.addErrback(self.getRootObjectEb) + d.addErrback(self.get_root_object_eb) if errback is not None: d.addErrback(lambda failure_: errback(failure_.value)) return d @@ -175,7 +175,7 @@ return super().register_signal(name, async_handler, iface) -class AIOBridge(Bridge): +class AIOBridge(bridge): def __init__(self): self.signals_handler = AIOSignalsHandler() @@ -192,8 +192,8 @@ d.addErrback(self._errback) return d.asFuture(asyncio.get_event_loop()) - async def bridgeConnect(self): - d = super().bridgeConnect(callback=None, errback=None) + async def bridge_connect(self): + d = super().bridge_connect(callback=None, errback=None) return await d.asFuture(asyncio.get_event_loop()) ##ASYNC_METHODS_PART##