Mercurial > libervia-backend
comparison sat/bridge/bridge_constructor/constructors/pb/pb_frontend_template.py @ 3028:ab2696e34d29
Python 3 port:
/!\ this is a huge commit
/!\ starting from this commit, SàT is needs Python 3.6+
/!\ SàT maybe be instable or some feature may not work anymore, this will improve with time
This patch port backend, bridge and frontends to Python 3.
Roughly this has been done this way:
- 2to3 tools has been applied (with python 3.7)
- all references to python2 have been replaced with python3 (notably shebangs)
- fixed files not handled by 2to3 (notably the shell script)
- several manual fixes
- fixed issues reported by Python 3 that where not handled in Python 2
- replaced "async" with "async_" when needed (it's a reserved word from Python 3.7)
- replaced zope's "implements" with @implementer decorator
- temporary hack to handle data pickled in database, as str or bytes may be returned,
to be checked later
- fixed hash comparison for password
- removed some code which is not needed anymore with Python 3
- deactivated some code which needs to be checked (notably certificate validation)
- tested with jp, fixed reported issues until some basic commands worked
- ported Primitivus (after porting dependencies like urwid satext)
- more manual fixes
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 13 Aug 2019 19:08:41 +0200 |
parents | 003b8b4b56a7 |
children | a1bc34f90fa5 |
comparison
equal
deleted
inserted
replaced
3027:ff5bcb12ae60 | 3028:ab2696e34d29 |
---|---|
1 #!/usr/bin/env python2 | 1 #!/usr/bin/env python3 |
2 # -*- coding: utf-8 -*- | 2 # -*- coding: utf-8 -*- |
3 | 3 |
4 # SAT communication bridge | 4 # SAT communication bridge |
5 # Copyright (C) 2009-2019 Jérôme Poisson (goffi@goffi.org) | 5 # Copyright (C) 2009-2019 Jérôme Poisson (goffi@goffi.org) |
6 | 6 |
26 | 26 |
27 | 27 |
28 class SignalsHandler(pb.Referenceable): | 28 class SignalsHandler(pb.Referenceable): |
29 def __getattr__(self, name): | 29 def __getattr__(self, name): |
30 if name.startswith("remote_"): | 30 if name.startswith("remote_"): |
31 log.debug(u"calling an unregistered signal: {name}".format(name=name[7:])) | 31 log.debug("calling an unregistered signal: {name}".format(name=name[7:])) |
32 return lambda *args, **kwargs: None | 32 return lambda *args, **kwargs: None |
33 | 33 |
34 else: | 34 else: |
35 raise AttributeError(name) | 35 raise AttributeError(name) |
36 | 36 |
41 self.__getattribute__(self, method_name) | 41 self.__getattribute__(self, method_name) |
42 except AttributeError: | 42 except AttributeError: |
43 pass | 43 pass |
44 else: | 44 else: |
45 raise exceptions.InternalError( | 45 raise exceptions.InternalError( |
46 u"{name} signal handler has been registered twice".format( | 46 "{name} signal handler has been registered twice".format( |
47 name=method_name | 47 name=method_name |
48 ) | 48 ) |
49 ) | 49 ) |
50 setattr(self, method_name, handler) | 50 setattr(self, method_name, handler) |
51 | 51 |
97 d.addCallback(self.remoteCallback, callback) | 97 d.addCallback(self.remoteCallback, callback) |
98 if errback is not None: | 98 if errback is not None: |
99 d.addErrback(errback) | 99 d.addErrback(errback) |
100 | 100 |
101 def _initBridgeEb(self, failure): | 101 def _initBridgeEb(self, failure): |
102 log.error(u"Can't init bridge: {msg}".format(msg=failure)) | 102 log.error("Can't init bridge: {msg}".format(msg=failure)) |
103 | 103 |
104 def _set_root(self, root): | 104 def _set_root(self, root): |
105 """set remote root object | 105 """set remote root object |
106 | 106 |
107 bridge will then be initialised | 107 bridge will then be initialised |
110 d = root.callRemote("initBridge", self.signals_handler) | 110 d = root.callRemote("initBridge", self.signals_handler) |
111 d.addErrback(self._initBridgeEb) | 111 d.addErrback(self._initBridgeEb) |
112 return d | 112 return d |
113 | 113 |
114 def _generic_errback(self, failure): | 114 def _generic_errback(self, failure): |
115 log.error(u"bridge failure: {}".format(failure)) | 115 log.error("bridge failure: {}".format(failure)) |
116 | 116 |
117 def bridgeConnect(self, callback, errback): | 117 def bridgeConnect(self, callback, errback): |
118 factory = pb.PBClientFactory() | 118 factory = pb.PBClientFactory() |
119 reactor.connectTCP("localhost", 8789, factory) | 119 reactor.connectTCP("localhost", 8789, factory) |
120 d = factory.getRootObject() | 120 d = factory.getRootObject() |