comparison sat/bridge/pb.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 c7c52c0dc13a
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: a jabber client 4 # SAT: a jabber client
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
44 def __init__(self): 44 def __init__(self):
45 self.signals_handlers = [] 45 self.signals_handlers = []
46 46
47 def remote_initBridge(self, signals_handler): 47 def remote_initBridge(self, signals_handler):
48 self.signals_handlers.append(signals_handler) 48 self.signals_handlers.append(signals_handler)
49 log.info(u"registered signal handler") 49 log.info("registered signal handler")
50 50
51 def sendSignalEb(self, failure, signal_name): 51 def sendSignalEb(self, failure, signal_name):
52 log.error( 52 log.error(
53 u"Error while sending signal {name}: {msg}".format( 53 "Error while sending signal {name}: {msg}".format(
54 name=signal_name, msg=failure 54 name=signal_name, msg=failure
55 ) 55 )
56 ) 56 )
57 57
58 def sendSignal(self, name, args, kwargs): 58 def sendSignal(self, name, args, kwargs):
64 to_remove.append(handler) 64 to_remove.append(handler)
65 else: 65 else:
66 d.addErrback(self.sendSignalEb, name) 66 d.addErrback(self.sendSignalEb, name)
67 if to_remove: 67 if to_remove:
68 for handler in to_remove: 68 for handler in to_remove:
69 log.debug(u"Removing signal handler for dead frontend") 69 log.debug("Removing signal handler for dead frontend")
70 self.signals_handlers.remove(handler) 70 self.signals_handlers.remove(handler)
71 71
72 def _bridgeDeactivateSignals(self): 72 def _bridgeDeactivateSignals(self):
73 if hasattr(self, "signals_paused"): 73 if hasattr(self, "signals_paused"):
74 log.warning(u"bridge signals already deactivated") 74 log.warning("bridge signals already deactivated")
75 if self.signals_handler: 75 if self.signals_handler:
76 self.signals_paused.extend(self.signals_handler) 76 self.signals_paused.extend(self.signals_handler)
77 else: 77 else:
78 self.signals_paused = self.signals_handlers 78 self.signals_paused = self.signals_handlers
79 self.signals_handlers = [] 79 self.signals_handlers = []
80 log.debug(u"bridge signals have been deactivated") 80 log.debug("bridge signals have been deactivated")
81 81
82 def _bridgeReactivateSignals(self): 82 def _bridgeReactivateSignals(self):
83 try: 83 try:
84 self.signals_handlers = self.signals_paused 84 self.signals_handlers = self.signals_paused
85 except AttributeError: 85 except AttributeError:
86 log.debug(u"signals were already activated") 86 log.debug("signals were already activated")
87 else: 87 else:
88 del self.signals_paused 88 del self.signals_paused
89 log.debug(u"bridge signals have been reactivated") 89 log.debug("bridge signals have been reactivated")
90 90
91 ##METHODS_PART## 91 ##METHODS_PART##
92 92
93 93
94 class Bridge(object): 94 class Bridge(object):
100 def sendSignal(self, name, *args, **kwargs): 100 def sendSignal(self, name, *args, **kwargs):
101 self.root.sendSignal(name, args, kwargs) 101 self.root.sendSignal(name, args, kwargs)
102 102
103 def remote_initBridge(self, signals_handler): 103 def remote_initBridge(self, signals_handler):
104 self.signals_handlers.append(signals_handler) 104 self.signals_handlers.append(signals_handler)
105 log.info(u"registered signal handler") 105 log.info("registered signal handler")
106 106
107 def register_method(self, name, callback): 107 def register_method(self, name, callback):
108 log.debug("registering PB bridge method [%s]" % name) 108 log.debug("registering PB bridge method [%s]" % name)
109 setattr(self.root, "remote_" + name, callback) 109 setattr(self.root, "remote_" + name, callback)
110 #  self.root.register_method(name, callback) 110 #  self.root.register_method(name, callback)
111 111
112 def addMethod(self, name, int_suffix, in_sign, out_sign, method, async=False, doc={}): 112 def addMethod(self, name, int_suffix, in_sign, out_sign, method, async_=False, doc={}):
113 """Dynamically add a method to PB Bridge""" 113 """Dynamically add a method to PB Bridge"""
114 # FIXME: doc parameter is kept only temporary, the time to remove it from calls 114 # FIXME: doc parameter is kept only temporary, the time to remove it from calls
115 log.debug("Adding method {name} to PB bridge".format(name=name)) 115 log.debug("Adding method {name} to PB bridge".format(name=name))
116 self.register_method(name, method) 116 self.register_method(name, method)
117 117