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:
parent
d50412c7f7
commit
6a6f15707a
11 changed files with 9945 additions and 9945 deletions
|
|
@ -38,9 +38,9 @@ class DbusXmlConstructor(base_constructor.Constructor):
|
|||
"a{sa{s(sia{ss})}}": "PresenceStatusT",
|
||||
}
|
||||
|
||||
def generateCoreSide(self):
|
||||
def generate_core_side(self):
|
||||
try:
|
||||
doc = minidom.parse(self.getTemplatePath(self.template))
|
||||
doc = minidom.parse(self.get_template_path(self.template))
|
||||
interface_elt = doc.getElementsByTagName("interface")[0]
|
||||
except IOError:
|
||||
print("Can't access template")
|
||||
|
|
@ -60,8 +60,8 @@ class DbusXmlConstructor(base_constructor.Constructor):
|
|||
new_elt.setAttribute("name", section)
|
||||
|
||||
idx = 0
|
||||
args_doc = self.getArgumentsDoc(section)
|
||||
for arg in self.argumentsParser(function["sig_in"] or ""):
|
||||
args_doc = self.get_arguments_doc(section)
|
||||
for arg in self.arguments_parser(function["sig_in"] or ""):
|
||||
arg_elt = doc.createElement("arg")
|
||||
arg_elt.setAttribute(
|
||||
"name", args_doc[idx][0] if idx in args_doc else "arg_%i" % idx
|
||||
|
|
@ -99,4 +99,4 @@ class DbusXmlConstructor(base_constructor.Constructor):
|
|||
interface_elt.appendChild(new_elt)
|
||||
|
||||
# now we write to final file
|
||||
self.finalWrite(self.core_dest, [doc.toprettyxml()])
|
||||
self.final_write(self.core_dest, [doc.toprettyxml()])
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ class DbusConstructor(base_constructor.Constructor):
|
|||
"debug": ""
|
||||
if not self.args.debug
|
||||
else 'log.debug ("%s")\n%s' % (completion["name"], 8 * " "),
|
||||
"args_result": self.getArguments(function["sig_in"], name=arg_doc),
|
||||
"args_result": self.get_arguments(function["sig_in"], name=arg_doc),
|
||||
"async_args": "callback=None, errback=None",
|
||||
"async_comma": ", " if function["sig_in"] else "",
|
||||
"error_handler": """if callback is None:
|
||||
|
|
|
|||
|
|
@ -30,8 +30,8 @@ from txdbus.interface import DBusInterface, Method, Signal
|
|||
log = getLogger(__name__)
|
||||
|
||||
# Interface prefix
|
||||
const_INT_PREFIX = config.getConfig(
|
||||
config.parseMainConf(),
|
||||
const_INT_PREFIX = config.config_get(
|
||||
config.parse_main_conf(),
|
||||
"",
|
||||
"bridge_dbus_int_prefix",
|
||||
"org.libervia.Libervia")
|
||||
|
|
@ -118,13 +118,13 @@ class DBusObject(objects.DBusObject):
|
|||
|
||||
##METHODS_PART##
|
||||
|
||||
class Bridge:
|
||||
class bridge:
|
||||
|
||||
def __init__(self):
|
||||
log.info("Init DBus...")
|
||||
self._obj = DBusObject(const_OBJ_PATH)
|
||||
|
||||
async def postInit(self):
|
||||
async def post_init(self):
|
||||
try:
|
||||
conn = await client.connect(reactor)
|
||||
except error.DBusException as e:
|
||||
|
|
@ -145,13 +145,13 @@ class Bridge:
|
|||
log.debug(f"registering DBus bridge method [{name}]")
|
||||
self._obj.register_method(name, callback)
|
||||
|
||||
def emitSignal(self, name, *args):
|
||||
def emit_signal(self, name, *args):
|
||||
self._obj.emitSignal(name, *args)
|
||||
|
||||
def addMethod(
|
||||
def add_method(
|
||||
self, name, int_suffix, in_sign, out_sign, method, async_=False, doc={}
|
||||
):
|
||||
"""Dynamically add a method to D-Bus Bridge"""
|
||||
"""Dynamically add a method to D-Bus bridge"""
|
||||
# FIXME: doc parameter is kept only temporary, the time to remove it from calls
|
||||
log.debug(f"Adding method {name!r} to D-Bus bridge")
|
||||
self._obj.plugin_iface.addMethod(
|
||||
|
|
@ -164,8 +164,8 @@ class Bridge:
|
|||
setattr(self._obj, f"dbus_{name}", MethodType(caller, self._obj))
|
||||
self.register_method(name, method)
|
||||
|
||||
def addSignal(self, name, int_suffix, signature, doc={}):
|
||||
"""Dynamically add a signal to D-Bus Bridge"""
|
||||
def add_signal(self, name, int_suffix, signature, doc={}):
|
||||
"""Dynamically add a signal to D-Bus bridge"""
|
||||
log.debug(f"Adding signal {name!r} to D-Bus bridge")
|
||||
self._obj.plugin_iface.addSignal(Signal(name, signature))
|
||||
setattr(Bridge, name, partialmethod(Bridge.emitSignal, name))
|
||||
setattr(bridge, name, partialmethod(bridge.emit_signal, name))
|
||||
|
|
|
|||
|
|
@ -32,8 +32,8 @@ log = getLogger(__name__)
|
|||
|
||||
|
||||
# Interface prefix
|
||||
const_INT_PREFIX = config.getConfig(
|
||||
config.parseMainConf(),
|
||||
const_INT_PREFIX = config.config_get(
|
||||
config.parse_main_conf(),
|
||||
"",
|
||||
"bridge_dbus_int_prefix",
|
||||
"org.libervia.Libervia")
|
||||
|
|
@ -66,9 +66,9 @@ def dbus_to_bridge_exception(dbus_e):
|
|||
return BridgeException(name, message, condition)
|
||||
|
||||
|
||||
class Bridge:
|
||||
class bridge:
|
||||
|
||||
def bridgeConnect(self, callback, errback):
|
||||
def bridge_connect(self, callback, errback):
|
||||
try:
|
||||
self.sessions_bus = dbus.SessionBus()
|
||||
self.db_object = self.sessions_bus.get_object(const_INT_PREFIX,
|
||||
|
|
@ -105,7 +105,7 @@ class Bridge:
|
|||
except AttributeError:
|
||||
# The attribute is not found, we try the plugin proxy to find the requested method
|
||||
|
||||
def getPluginMethod(*args, **kwargs):
|
||||
def get_plugin_method(*args, **kwargs):
|
||||
# We first check if we have an async call. We detect this in two ways:
|
||||
# - if we have the 'callback' and 'errback' keyword arguments
|
||||
# - or if the last two arguments are callable
|
||||
|
|
@ -156,11 +156,11 @@ class Bridge:
|
|||
return self.db_plugin_iface.get_dbus_method(name)(*args, **kwargs)
|
||||
raise e
|
||||
|
||||
return getPluginMethod
|
||||
return get_plugin_method
|
||||
|
||||
##METHODS_PART##
|
||||
|
||||
class AIOBridge(Bridge):
|
||||
class AIOBridge(bridge):
|
||||
|
||||
def register_signal(self, functionName, handler, iface="core"):
|
||||
loop = asyncio.get_running_loop()
|
||||
|
|
@ -173,7 +173,7 @@ class AIOBridge(Bridge):
|
|||
return object.__getattribute__(self, name)
|
||||
except AttributeError:
|
||||
# The attribute is not found, we try the plugin proxy to find the requested method
|
||||
def getPluginMethod(*args, **kwargs):
|
||||
def get_plugin_method(*args, **kwargs):
|
||||
loop = asyncio.get_running_loop()
|
||||
fut = loop.create_future()
|
||||
method = getattr(self.db_plugin_iface, name)
|
||||
|
|
@ -191,7 +191,7 @@ class AIOBridge(Bridge):
|
|||
)
|
||||
except ValueError as e:
|
||||
if e.args[0].startswith("Unable to guess signature"):
|
||||
# same hack as for Bridge.__getattribute__
|
||||
# same hack as for bridge.__getattribute__
|
||||
log.warning("using hack to work around inspection issue")
|
||||
proxy = self.db_plugin_iface.proxy_object
|
||||
IN_PROGRESS = proxy.INTROSPECT_STATE_INTROSPECT_IN_PROGRESS
|
||||
|
|
@ -209,12 +209,12 @@ class AIOBridge(Bridge):
|
|||
raise e
|
||||
return fut
|
||||
|
||||
return getPluginMethod
|
||||
return get_plugin_method
|
||||
|
||||
def bridgeConnect(self):
|
||||
def bridge_connect(self):
|
||||
loop = asyncio.get_running_loop()
|
||||
fut = loop.create_future()
|
||||
super().bridgeConnect(
|
||||
super().bridge_connect(
|
||||
callback=lambda: loop.call_soon_threadsafe(fut.set_result, None),
|
||||
errback=lambda e: loop.call_soon_threadsafe(fut.set_exception, e)
|
||||
)
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ class EmbeddedConstructor(base_constructor.Constructor):
|
|||
"debug": ""
|
||||
if not self.args.debug
|
||||
else 'log.debug ("%s")\n%s' % (completion["name"], 8 * " "),
|
||||
"args_result": self.getArguments(function["sig_in"], name=arg_doc),
|
||||
"args_result": self.get_arguments(function["sig_in"], name=arg_doc),
|
||||
"args_comma": ", " if function["sig_in"] else "",
|
||||
}
|
||||
)
|
||||
|
|
@ -96,5 +96,5 @@ class EmbeddedConstructor(base_constructor.Constructor):
|
|||
|
||||
def core_completion_signal(self, completion, function, default, arg_doc, async_):
|
||||
completion.update(
|
||||
{"args_result": self.getArguments(function["sig_in"], name=arg_doc)}
|
||||
{"args_result": self.get_arguments(function["sig_in"], name=arg_doc)}
|
||||
)
|
||||
|
|
|
|||
|
|
@ -17,4 +17,4 @@
|
|||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from sat.bridge.embedded import Bridge
|
||||
from sat.bridge.embedded import bridge
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ class _Bridge(object):
|
|||
self._methods_cbs = {}
|
||||
self._signals_cbs = {"core": {}, "plugin": {}}
|
||||
|
||||
def bridgeConnect(self, callback, errback):
|
||||
def bridge_connect(self, callback, errback):
|
||||
callback()
|
||||
|
||||
def register_method(self, name, callback):
|
||||
|
|
@ -85,7 +85,7 @@ class _Bridge(object):
|
|||
else:
|
||||
cb(*args, **kwargs)
|
||||
|
||||
def addMethod(self, name, int_suffix, in_sign, out_sign, method, async_=False, doc={}):
|
||||
def add_method(self, name, int_suffix, in_sign, out_sign, method, async_=False, doc={}):
|
||||
# FIXME: doc parameter is kept only temporary, the time to remove it from calls
|
||||
log.debug("Adding method [{}] to embedded bridge".format(name))
|
||||
self.register_method(name, method)
|
||||
|
|
@ -97,7 +97,7 @@ class _Bridge(object):
|
|||
),
|
||||
)
|
||||
|
||||
def addSignal(self, name, int_suffix, signature, doc={}):
|
||||
def add_signal(self, name, int_suffix, signature, doc={}):
|
||||
setattr(
|
||||
self.__class__,
|
||||
name,
|
||||
|
|
@ -116,7 +116,7 @@ class _Bridge(object):
|
|||
bridge = None
|
||||
|
||||
|
||||
def Bridge():
|
||||
def bridge():
|
||||
global bridge
|
||||
if bridge is None:
|
||||
bridge = _Bridge()
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ class MediawikiConstructor(base_constructor.Constructor):
|
|||
self.core_template = "mediawiki_template.tpl"
|
||||
self.core_dest = "mediawiki.wiki"
|
||||
|
||||
def _addTextDecorations(self, text):
|
||||
def _add_text_decorations(self, text):
|
||||
"""Add text decorations like coloration or shortcuts"""
|
||||
|
||||
def anchor_link(match):
|
||||
|
|
@ -42,43 +42,43 @@ class MediawikiConstructor(base_constructor.Constructor):
|
|||
|
||||
return re.sub(r"\[(\w+)\]", anchor_link, text)
|
||||
|
||||
def _wikiParameter(self, name, sig_in):
|
||||
def _wiki_parameter(self, name, sig_in):
|
||||
"""Format parameters with the wiki syntax
|
||||
@param name: name of the function
|
||||
@param sig_in: signature in
|
||||
@return: string of the formated parameters"""
|
||||
arg_doc = self.getArgumentsDoc(name)
|
||||
arg_default = self.getDefault(name)
|
||||
args_str = self.getArguments(sig_in)
|
||||
arg_doc = self.get_arguments_doc(name)
|
||||
arg_default = self.get_default(name)
|
||||
args_str = self.get_arguments(sig_in)
|
||||
args = args_str.split(", ") if args_str else [] # ugly but it works :)
|
||||
wiki = []
|
||||
for i in range(len(args)):
|
||||
if i in arg_doc:
|
||||
name, doc = arg_doc[i]
|
||||
doc = "\n:".join(doc.rstrip("\n").split("\n"))
|
||||
wiki.append("; %s: %s" % (name, self._addTextDecorations(doc)))
|
||||
wiki.append("; %s: %s" % (name, self._add_text_decorations(doc)))
|
||||
else:
|
||||
wiki.append("; arg_%d: " % i)
|
||||
if i in arg_default:
|
||||
wiki.append(":''DEFAULT: %s''" % arg_default[i])
|
||||
return "\n".join(wiki)
|
||||
|
||||
def _wikiReturn(self, name):
|
||||
def _wiki_return(self, name):
|
||||
"""Format return doc with the wiki syntax
|
||||
@param name: name of the function
|
||||
"""
|
||||
arg_doc = self.getArgumentsDoc(name)
|
||||
arg_doc = self.get_arguments_doc(name)
|
||||
wiki = []
|
||||
if "return" in arg_doc:
|
||||
wiki.append("\n|-\n! scope=row | return value\n|")
|
||||
wiki.append(
|
||||
"<br />\n".join(
|
||||
self._addTextDecorations(arg_doc["return"]).rstrip("\n").split("\n")
|
||||
self._add_text_decorations(arg_doc["return"]).rstrip("\n").split("\n")
|
||||
)
|
||||
)
|
||||
return "\n".join(wiki)
|
||||
|
||||
def generateCoreSide(self):
|
||||
def generate_core_side(self):
|
||||
signals_part = []
|
||||
methods_part = []
|
||||
sections = self.bridge_template.sections()
|
||||
|
|
@ -114,13 +114,13 @@ class MediawikiConstructor(base_constructor.Constructor):
|
|||
"sig_out": function["sig_out"] or "",
|
||||
"category": function["category"],
|
||||
"name": section,
|
||||
"doc": self.getDoc(section) or "FIXME: No description available",
|
||||
"doc": self.get_doc(section) or "FIXME: No description available",
|
||||
"async": async_msg if "async" in self.getFlags(section) else "",
|
||||
"deprecated": deprecated_msg
|
||||
if "deprecated" in self.getFlags(section)
|
||||
else "",
|
||||
"parameters": self._wikiParameter(section, function["sig_in"]),
|
||||
"return": self._wikiReturn(section)
|
||||
"parameters": self._wiki_parameter(section, function["sig_in"]),
|
||||
"return": self._wiki_return(section)
|
||||
if function["type"] == "method"
|
||||
else "",
|
||||
}
|
||||
|
|
@ -148,7 +148,7 @@ class MediawikiConstructor(base_constructor.Constructor):
|
|||
# at this point, signals_part, and methods_part should be filled,
|
||||
# we just have to place them in the right part of the template
|
||||
core_bridge = []
|
||||
template_path = self.getTemplatePath(self.core_template)
|
||||
template_path = self.get_template_path(self.core_template)
|
||||
try:
|
||||
with open(template_path) as core_template:
|
||||
for line in core_template:
|
||||
|
|
@ -165,4 +165,4 @@ class MediawikiConstructor(base_constructor.Constructor):
|
|||
sys.exit(1)
|
||||
|
||||
# now we write to final file
|
||||
self.finalWrite(self.core_dest, core_bridge)
|
||||
self.final_write(self.core_dest, core_bridge)
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ class pbConstructor(base_constructor.Constructor):
|
|||
CORE_FORMATS = {
|
||||
"signals": """\
|
||||
def {name}(self, {args}):
|
||||
{debug}self.sendSignal("{name}", {args_no_def})\n"""
|
||||
{debug}self.send_signal("{name}", {args_no_def})\n"""
|
||||
}
|
||||
|
||||
FRONTEND_TEMPLATE = "pb_frontend_template.py"
|
||||
|
|
@ -49,7 +49,7 @@ class pbConstructor(base_constructor.Constructor):
|
|||
}
|
||||
|
||||
def core_completion_signal(self, completion, function, default, arg_doc, async_):
|
||||
completion["args_no_def"] = self.getArguments(function["sig_in"], name=arg_doc)
|
||||
completion["args_no_def"] = self.get_arguments(function["sig_in"], name=arg_doc)
|
||||
completion["debug"] = (
|
||||
""
|
||||
if not self.args.debug
|
||||
|
|
@ -60,7 +60,7 @@ class pbConstructor(base_constructor.Constructor):
|
|||
completion.update(
|
||||
{
|
||||
"args_comma": ", " if function["sig_in"] else "",
|
||||
"args_no_def": self.getArguments(function["sig_in"], name=arg_doc),
|
||||
"args_no_def": self.get_arguments(function["sig_in"], name=arg_doc),
|
||||
"callback": "callback"
|
||||
if function["sig_out"]
|
||||
else "lambda __: callback()",
|
||||
|
|
|
|||
|
|
@ -55,17 +55,17 @@ class PBRoot(pb.Root):
|
|||
def __init__(self):
|
||||
self.signals_handlers = []
|
||||
|
||||
def remote_initBridge(self, signals_handler):
|
||||
def remote_init_bridge(self, signals_handler):
|
||||
self.signals_handlers.append(HandlerWrapper(signals_handler))
|
||||
log.info("registered signal handler")
|
||||
|
||||
def sendSignalEb(self, failure_, signal_name):
|
||||
def send_signal_eb(self, failure_, signal_name):
|
||||
if not failure_.check(pb.PBConnectionLost):
|
||||
log.error(
|
||||
f"Error while sending signal {signal_name}: {failure_}",
|
||||
)
|
||||
|
||||
def sendSignal(self, name, args, kwargs):
|
||||
def send_signal(self, name, args, kwargs):
|
||||
to_remove = []
|
||||
for wrapper in self.signals_handlers:
|
||||
handler = wrapper.handler
|
||||
|
|
@ -74,13 +74,13 @@ class PBRoot(pb.Root):
|
|||
except pb.DeadReferenceError:
|
||||
to_remove.append(wrapper)
|
||||
else:
|
||||
d.addErrback(self.sendSignalEb, name)
|
||||
d.addErrback(self.send_signal_eb, name)
|
||||
if to_remove:
|
||||
for wrapper in to_remove:
|
||||
log.debug("Removing signal handler for dead frontend")
|
||||
self.signals_handlers.remove(wrapper)
|
||||
|
||||
def _bridgeDeactivateSignals(self):
|
||||
def _bridge_deactivate_signals(self):
|
||||
if hasattr(self, "signals_paused"):
|
||||
log.warning("bridge signals already deactivated")
|
||||
if self.signals_handler:
|
||||
|
|
@ -90,7 +90,7 @@ class PBRoot(pb.Root):
|
|||
self.signals_handlers = []
|
||||
log.debug("bridge signals have been deactivated")
|
||||
|
||||
def _bridgeReactivateSignals(self):
|
||||
def _bridge_reactivate_signals(self):
|
||||
try:
|
||||
self.signals_handlers = self.signals_paused
|
||||
except AttributeError:
|
||||
|
|
@ -102,31 +102,31 @@ class PBRoot(pb.Root):
|
|||
##METHODS_PART##
|
||||
|
||||
|
||||
class Bridge(object):
|
||||
class bridge(object):
|
||||
def __init__(self):
|
||||
log.info("Init Perspective Broker...")
|
||||
self.root = PBRoot()
|
||||
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"
|
||||
log.info(f"using UNIX Socket at {socket_path}")
|
||||
reactor.listenUNIX(
|
||||
str(socket_path), pb.PBServerFactory(self.root), mode=0o600
|
||||
)
|
||||
elif conn_type == "socket":
|
||||
port = int(getConf("port", 8789))
|
||||
port = int(get_conf("port", 8789))
|
||||
log.info(f"using TCP Socket at port {port}")
|
||||
reactor.listenTCP(port, pb.PBServerFactory(self.root))
|
||||
else:
|
||||
raise ValueError(f"Unknown pb connection type: {conn_type!r}")
|
||||
|
||||
def sendSignal(self, name, *args, **kwargs):
|
||||
self.root.sendSignal(name, args, kwargs)
|
||||
def send_signal(self, name, *args, **kwargs):
|
||||
self.root.send_signal(name, args, kwargs)
|
||||
|
||||
def remote_initBridge(self, signals_handler):
|
||||
def remote_init_bridge(self, signals_handler):
|
||||
self.signals_handlers.append(signals_handler)
|
||||
log.info("registered signal handler")
|
||||
|
||||
|
|
@ -135,32 +135,32 @@ class Bridge(object):
|
|||
setattr(self.root, "remote_" + name, callback)
|
||||
# self.root.register_method(name, callback)
|
||||
|
||||
def addMethod(
|
||||
def add_method(
|
||||
self, name, int_suffix, in_sign, out_sign, method, async_=False, doc={}
|
||||
):
|
||||
"""Dynamically add a method to PB Bridge"""
|
||||
"""Dynamically add a method to PB bridge"""
|
||||
# FIXME: doc parameter is kept only temporary, the time to remove it from calls
|
||||
log.debug("Adding method {name} to PB bridge".format(name=name))
|
||||
self.register_method(name, method)
|
||||
|
||||
def addSignal(self, name, int_suffix, signature, doc={}):
|
||||
def add_signal(self, name, int_suffix, signature, doc={}):
|
||||
log.debug("Adding signal {name} to PB bridge".format(name=name))
|
||||
setattr(
|
||||
self, name, lambda *args, **kwargs: self.sendSignal(name, *args, **kwargs)
|
||||
self, name, lambda *args, **kwargs: self.send_signal(name, *args, **kwargs)
|
||||
)
|
||||
|
||||
def bridgeDeactivateSignals(self):
|
||||
def bridge_deactivate_signals(self):
|
||||
"""Stop sending signals to bridge
|
||||
|
||||
Mainly used for mobile frontends, when the frontend is paused
|
||||
"""
|
||||
self.root._bridgeDeactivateSignals()
|
||||
self.root._bridge_deactivate_signals()
|
||||
|
||||
def bridgeReactivateSignals(self):
|
||||
def bridge_reactivate_signals(self):
|
||||
"""Send again signals to bridge
|
||||
|
||||
Should only be used after bridgeDeactivateSignals has been called
|
||||
Should only be used after bridge_deactivate_signals has been called
|
||||
"""
|
||||
self.root._bridgeReactivateSignals()
|
||||
self.root._bridge_reactivate_signals()
|
||||
|
||||
##SIGNALS_PART##
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ class SignalsHandler(pb.Referenceable):
|
|||
setattr(self, method_name, handler)
|
||||
|
||||
|
||||
class Bridge(object):
|
||||
class bridge(object):
|
||||
|
||||
def __init__(self):
|
||||
self.signals_handler = SignalsHandler()
|
||||
|
|
@ -75,7 +75,7 @@ class Bridge(object):
|
|||
)
|
||||
)
|
||||
|
||||
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 @@ class Bridge(object):
|
|||
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 @@ class Bridge(object):
|
|||
"""
|
||||
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 @@ class Bridge(object):
|
|||
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 @@ class AIOSignalsHandler(SignalsHandler):
|
|||
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 @@ class AIOBridge(Bridge):
|
|||
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##
|
||||
|
|
|
|||
Loading…
Reference in a new issue