annotate sat/bridge/bridge_constructor/constructors/embedded/constructor.py @ 3721:6878745a47e8

component file sharing: fix incorrect use of `returnValue` in `items` async method
author Goffi <goffi@goffi.org>
date Tue, 25 Jan 2022 17:13:32 +0100
parents 7550ae9cfbac
children 524856bd7b19
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
1 #!/usr/bin/env python3
3137
559a625a236b fixed shebangs
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
2
2087
159250d66407 bridge (constructor): embedded bridge generator:
Goffi <goffi@goffi.org>
parents:
diff changeset
3
3480
7550ae9cfbac Renamed the project from "Salut à Toi" to "Libervia":
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
4 # Libervia: an XMPP client
3479
be6d91572633 date update
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
5 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org)
2087
159250d66407 bridge (constructor): embedded bridge generator:
Goffi <goffi@goffi.org>
parents:
diff changeset
6
159250d66407 bridge (constructor): embedded bridge generator:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # This program is free software: you can redistribute it and/or modify
159250d66407 bridge (constructor): embedded bridge generator:
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
159250d66407 bridge (constructor): embedded bridge generator:
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
159250d66407 bridge (constructor): embedded bridge generator:
Goffi <goffi@goffi.org>
parents:
diff changeset
10 # (at your option) any later version.
159250d66407 bridge (constructor): embedded bridge generator:
Goffi <goffi@goffi.org>
parents:
diff changeset
11
159250d66407 bridge (constructor): embedded bridge generator:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # This program is distributed in the hope that it will be useful,
159250d66407 bridge (constructor): embedded bridge generator:
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
159250d66407 bridge (constructor): embedded bridge generator:
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
159250d66407 bridge (constructor): embedded bridge generator:
Goffi <goffi@goffi.org>
parents:
diff changeset
15 # GNU Affero General Public License for more details.
159250d66407 bridge (constructor): embedded bridge generator:
Goffi <goffi@goffi.org>
parents:
diff changeset
16
159250d66407 bridge (constructor): embedded bridge generator:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
159250d66407 bridge (constructor): embedded bridge generator:
Goffi <goffi@goffi.org>
parents:
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
159250d66407 bridge (constructor): embedded bridge generator:
Goffi <goffi@goffi.org>
parents:
diff changeset
19
159250d66407 bridge (constructor): embedded bridge generator:
Goffi <goffi@goffi.org>
parents:
diff changeset
20 from sat.bridge.bridge_constructor import base_constructor
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
21
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
22 #  from textwraps import dedent
2087
159250d66407 bridge (constructor): embedded bridge generator:
Goffi <goffi@goffi.org>
parents:
diff changeset
23
159250d66407 bridge (constructor): embedded bridge generator:
Goffi <goffi@goffi.org>
parents:
diff changeset
24
159250d66407 bridge (constructor): embedded bridge generator:
Goffi <goffi@goffi.org>
parents:
diff changeset
25 class EmbeddedConstructor(base_constructor.Constructor):
159250d66407 bridge (constructor): embedded bridge generator:
Goffi <goffi@goffi.org>
parents:
diff changeset
26 NAME = "embedded"
159250d66407 bridge (constructor): embedded bridge generator:
Goffi <goffi@goffi.org>
parents:
diff changeset
27 CORE_TEMPLATE = "embedded_template.py"
159250d66407 bridge (constructor): embedded bridge generator:
Goffi <goffi@goffi.org>
parents:
diff changeset
28 CORE_DEST = "embedded.py"
159250d66407 bridge (constructor): embedded bridge generator:
Goffi <goffi@goffi.org>
parents:
diff changeset
29 CORE_FORMATS = {
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
30 "methods": """\
2087
159250d66407 bridge (constructor): embedded bridge generator:
Goffi <goffi@goffi.org>
parents:
diff changeset
31 def {name}(self, {args}{args_comma}callback=None, errback=None):
159250d66407 bridge (constructor): embedded bridge generator:
Goffi <goffi@goffi.org>
parents:
diff changeset
32 {ret_routine}
159250d66407 bridge (constructor): embedded bridge generator:
Goffi <goffi@goffi.org>
parents:
diff changeset
33 """,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
34 "signals": """\
2087
159250d66407 bridge (constructor): embedded bridge generator:
Goffi <goffi@goffi.org>
parents:
diff changeset
35 def {name}(self, {args}):
159250d66407 bridge (constructor): embedded bridge generator:
Goffi <goffi@goffi.org>
parents:
diff changeset
36 try:
159250d66407 bridge (constructor): embedded bridge generator:
Goffi <goffi@goffi.org>
parents:
diff changeset
37 cb = self._signals_cbs["{category}"]["{name}"]
159250d66407 bridge (constructor): embedded bridge generator:
Goffi <goffi@goffi.org>
parents:
diff changeset
38 except KeyError:
2118
442423faf220 bridge (constructor/embedded): fixed warning on unregistered callback
Goffi <goffi@goffi.org>
parents: 2087
diff changeset
39 log.warning(u"ignoring signal {name}: no callback registered")
2087
159250d66407 bridge (constructor): embedded bridge generator:
Goffi <goffi@goffi.org>
parents:
diff changeset
40 else:
159250d66407 bridge (constructor): embedded bridge generator:
Goffi <goffi@goffi.org>
parents:
diff changeset
41 cb({args_result})
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
42 """,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
43 }
2087
159250d66407 bridge (constructor): embedded bridge generator:
Goffi <goffi@goffi.org>
parents:
diff changeset
44 FRONTEND_TEMPLATE = "embedded_frontend_template.py"
159250d66407 bridge (constructor): embedded bridge generator:
Goffi <goffi@goffi.org>
parents:
diff changeset
45 FRONTEND_DEST = CORE_DEST
159250d66407 bridge (constructor): embedded bridge generator:
Goffi <goffi@goffi.org>
parents:
diff changeset
46 FRONTEND_FORMATS = {}
159250d66407 bridge (constructor): embedded bridge generator:
Goffi <goffi@goffi.org>
parents:
diff changeset
47
159250d66407 bridge (constructor): embedded bridge generator:
Goffi <goffi@goffi.org>
parents:
diff changeset
48 def core_completion_method(self, completion, function, default, arg_doc, async_):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
49 completion.update(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
50 {
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
51 "debug": ""
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
52 if not self.args.debug
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
53 else 'log.debug ("%s")\n%s' % (completion["name"], 8 * " "),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
54 "args_result": self.getArguments(function["sig_in"], name=arg_doc),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
55 "args_comma": ", " if function["sig_in"] else "",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
56 }
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
57 )
2087
159250d66407 bridge (constructor): embedded bridge generator:
Goffi <goffi@goffi.org>
parents:
diff changeset
58
159250d66407 bridge (constructor): embedded bridge generator:
Goffi <goffi@goffi.org>
parents:
diff changeset
59 if async_:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
60 completion["cb_or_lambda"] = (
2765
378188abe941 misc: replaced all "dummy" by the more conventional and readable "__" ("_" being used for gettext)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
61 "callback" if function["sig_out"] else "lambda __: callback()"
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
62 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
63 completion[
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
64 "ret_routine"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
65 ] = """\
2087
159250d66407 bridge (constructor): embedded bridge generator:
Goffi <goffi@goffi.org>
parents:
diff changeset
66 d = self._methods_cbs["{name}"]({args_result})
159250d66407 bridge (constructor): embedded bridge generator:
Goffi <goffi@goffi.org>
parents:
diff changeset
67 if callback is not None:
159250d66407 bridge (constructor): embedded bridge generator:
Goffi <goffi@goffi.org>
parents:
diff changeset
68 d.addCallback({cb_or_lambda})
159250d66407 bridge (constructor): embedded bridge generator:
Goffi <goffi@goffi.org>
parents:
diff changeset
69 if errback is None:
159250d66407 bridge (constructor): embedded bridge generator:
Goffi <goffi@goffi.org>
parents:
diff changeset
70 d.addErrback(lambda failure_: log.error(failure_))
159250d66407 bridge (constructor): embedded bridge generator:
Goffi <goffi@goffi.org>
parents:
diff changeset
71 else:
159250d66407 bridge (constructor): embedded bridge generator:
Goffi <goffi@goffi.org>
parents:
diff changeset
72 d.addErrback(errback)
159250d66407 bridge (constructor): embedded bridge generator:
Goffi <goffi@goffi.org>
parents:
diff changeset
73 return d
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
74 """.format(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
75 **completion
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
76 )
2087
159250d66407 bridge (constructor): embedded bridge generator:
Goffi <goffi@goffi.org>
parents:
diff changeset
77 else:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
78 completion["ret_or_nothing"] = "ret" if function["sig_out"] else ""
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
79 completion[
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
80 "ret_routine"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
81 ] = """\
2087
159250d66407 bridge (constructor): embedded bridge generator:
Goffi <goffi@goffi.org>
parents:
diff changeset
82 try:
159250d66407 bridge (constructor): embedded bridge generator:
Goffi <goffi@goffi.org>
parents:
diff changeset
83 ret = self._methods_cbs["{name}"]({args_result})
159250d66407 bridge (constructor): embedded bridge generator:
Goffi <goffi@goffi.org>
parents:
diff changeset
84 except Exception as e:
159250d66407 bridge (constructor): embedded bridge generator:
Goffi <goffi@goffi.org>
parents:
diff changeset
85 if errback is not None:
159250d66407 bridge (constructor): embedded bridge generator:
Goffi <goffi@goffi.org>
parents:
diff changeset
86 errback(e)
159250d66407 bridge (constructor): embedded bridge generator:
Goffi <goffi@goffi.org>
parents:
diff changeset
87 else:
159250d66407 bridge (constructor): embedded bridge generator:
Goffi <goffi@goffi.org>
parents:
diff changeset
88 raise e
159250d66407 bridge (constructor): embedded bridge generator:
Goffi <goffi@goffi.org>
parents:
diff changeset
89 else:
159250d66407 bridge (constructor): embedded bridge generator:
Goffi <goffi@goffi.org>
parents:
diff changeset
90 if callback is None:
159250d66407 bridge (constructor): embedded bridge generator:
Goffi <goffi@goffi.org>
parents:
diff changeset
91 return ret
159250d66407 bridge (constructor): embedded bridge generator:
Goffi <goffi@goffi.org>
parents:
diff changeset
92 else:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
93 callback({ret_or_nothing})""".format(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
94 **completion
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
95 )
2087
159250d66407 bridge (constructor): embedded bridge generator:
Goffi <goffi@goffi.org>
parents:
diff changeset
96
159250d66407 bridge (constructor): embedded bridge generator:
Goffi <goffi@goffi.org>
parents:
diff changeset
97 def core_completion_signal(self, completion, function, default, arg_doc, async_):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
98 completion.update(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
99 {"args_result": self.getArguments(function["sig_in"], name=arg_doc)}
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
100 )