comparison libervia/backend/bridge/bridge_constructor/constructors/embedded/constructor.py @ 4270:0d7bb4df2343

Reformatted code base using black.
author Goffi <goffi@goffi.org>
date Wed, 19 Jun 2024 18:44:57 +0200
parents 4b842c1fb686
children
comparison
equal deleted inserted replaced
4269:64a85ce8be70 4270:0d7bb4df2343
46 FRONTEND_FORMATS = {} 46 FRONTEND_FORMATS = {}
47 47
48 def core_completion_method(self, completion, function, default, arg_doc, async_): 48 def core_completion_method(self, completion, function, default, arg_doc, async_):
49 completion.update( 49 completion.update(
50 { 50 {
51 "debug": "" 51 "debug": (
52 if not self.args.debug 52 ""
53 else 'log.debug ("%s")\n%s' % (completion["name"], 8 * " "), 53 if not self.args.debug
54 else 'log.debug ("%s")\n%s' % (completion["name"], 8 * " ")
55 ),
54 "args_result": self.get_arguments(function["sig_in"], name=arg_doc), 56 "args_result": self.get_arguments(function["sig_in"], name=arg_doc),
55 "args_comma": ", " if function["sig_in"] else "", 57 "args_comma": ", " if function["sig_in"] else "",
56 } 58 }
57 ) 59 )
58 60
59 if async_: 61 if async_:
60 completion["cb_or_lambda"] = ( 62 completion["cb_or_lambda"] = (
61 "callback" if function["sig_out"] else "lambda __: callback()" 63 "callback" if function["sig_out"] else "lambda __: callback()"
62 ) 64 )
63 completion[ 65 completion["ret_routine"] = (
64 "ret_routine" 66 """\
65 ] = """\
66 d = self._methods_cbs["{name}"]({args_result}) 67 d = self._methods_cbs["{name}"]({args_result})
67 if callback is not None: 68 if callback is not None:
68 d.addCallback({cb_or_lambda}) 69 d.addCallback({cb_or_lambda})
69 if errback is None: 70 if errback is None:
70 d.addErrback(lambda failure_: log.error(failure_)) 71 d.addErrback(lambda failure_: log.error(failure_))
71 else: 72 else:
72 d.addErrback(errback) 73 d.addErrback(errback)
73 return d 74 return d
74 """.format( 75 """.format(
75 **completion 76 **completion
77 )
76 ) 78 )
77 else: 79 else:
78 completion["ret_or_nothing"] = "ret" if function["sig_out"] else "" 80 completion["ret_or_nothing"] = "ret" if function["sig_out"] else ""
79 completion[ 81 completion["ret_routine"] = (
80 "ret_routine" 82 """\
81 ] = """\
82 try: 83 try:
83 ret = self._methods_cbs["{name}"]({args_result}) 84 ret = self._methods_cbs["{name}"]({args_result})
84 except Exception as e: 85 except Exception as e:
85 if errback is not None: 86 if errback is not None:
86 errback(e) 87 errback(e)
89 else: 90 else:
90 if callback is None: 91 if callback is None:
91 return ret 92 return ret
92 else: 93 else:
93 callback({ret_or_nothing})""".format( 94 callback({ret_or_nothing})""".format(
94 **completion 95 **completion
96 )
95 ) 97 )
96 98
97 def core_completion_signal(self, completion, function, default, arg_doc, async_): 99 def core_completion_signal(self, completion, function, default, arg_doc, async_):
98 completion.update( 100 completion.update(
99 {"args_result": self.get_arguments(function["sig_in"], name=arg_doc)} 101 {"args_result": self.get_arguments(function["sig_in"], name=arg_doc)}