Mercurial > libervia-backend
comparison libervia/backend/bridge/bridge_constructor/constructors/pb/constructor.py @ 4071:4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 02 Jun 2023 11:49:51 +0200 |
parents | sat/bridge/bridge_constructor/constructors/pb/constructor.py@524856bd7b19 |
children | 0d7bb4df2343 |
comparison
equal
deleted
inserted
replaced
4070:d10748475025 | 4071:4b842c1fb686 |
---|---|
1 #!/usr/bin/env python3 | |
2 | |
3 # Libervia: an XMPP client | |
4 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org) | |
5 | |
6 # This program is free software: you can redistribute it and/or modify | |
7 # it under the terms of the GNU Affero General Public License as published by | |
8 # the Free Software Foundation, either version 3 of the License, or | |
9 # (at your option) any later version. | |
10 | |
11 # This program is distributed in the hope that it will be useful, | |
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 # GNU Affero General Public License for more details. | |
15 | |
16 # You should have received a copy of the GNU Affero General Public License | |
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
18 | |
19 from libervia.backend.bridge.bridge_constructor import base_constructor | |
20 | |
21 | |
22 class pbConstructor(base_constructor.Constructor): | |
23 NAME = "pb" | |
24 CORE_TEMPLATE = "pb_core_template.py" | |
25 CORE_DEST = "pb.py" | |
26 CORE_FORMATS = { | |
27 "signals": """\ | |
28 def {name}(self, {args}): | |
29 {debug}self.send_signal("{name}", {args_no_def})\n""" | |
30 } | |
31 | |
32 FRONTEND_TEMPLATE = "pb_frontend_template.py" | |
33 FRONTEND_DEST = CORE_DEST | |
34 FRONTEND_FORMATS = { | |
35 "methods": """\ | |
36 def {name}(self{args_comma}{args}, callback=None, errback=None): | |
37 {debug}d = self.root.callRemote("{name}"{args_comma}{args_no_def}) | |
38 if callback is not None: | |
39 d.addCallback({callback}) | |
40 if errback is None: | |
41 d.addErrback(self._generic_errback) | |
42 else: | |
43 d.addErrback(self._errback, ori_errback=errback)\n""", | |
44 "async_methods": """\ | |
45 def {name}(self{args_comma}{args}): | |
46 {debug}d = self.root.callRemote("{name}"{args_comma}{args_no_def}) | |
47 d.addErrback(self._errback) | |
48 return d.asFuture(asyncio.get_event_loop())\n""", | |
49 } | |
50 | |
51 def core_completion_signal(self, completion, function, default, arg_doc, async_): | |
52 completion["args_no_def"] = self.get_arguments(function["sig_in"], name=arg_doc) | |
53 completion["debug"] = ( | |
54 "" | |
55 if not self.args.debug | |
56 else 'log.debug ("%s")\n%s' % (completion["name"], 8 * " ") | |
57 ) | |
58 | |
59 def frontend_completion_method(self, completion, function, default, arg_doc, async_): | |
60 completion.update( | |
61 { | |
62 "args_comma": ", " if function["sig_in"] else "", | |
63 "args_no_def": self.get_arguments(function["sig_in"], name=arg_doc), | |
64 "callback": "callback" | |
65 if function["sig_out"] | |
66 else "lambda __: callback()", | |
67 "debug": "" | |
68 if not self.args.debug | |
69 else 'log.debug ("%s")\n%s' % (completion["name"], 8 * " "), | |
70 } | |
71 ) |