Mercurial > libervia-backend
comparison sat/plugins/plugin_exp_command_export.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 | 9d0df638c8b4 |
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 plugin to export commands (experimental) | 4 # SAT plugin to export commands (experimental) |
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 |
50 self.client = client | 50 self.client = client |
51 | 51 |
52 def _clean(self, data): | 52 def _clean(self, data): |
53 if not data: | 53 if not data: |
54 log.error("data should not be empty !") | 54 log.error("data should not be empty !") |
55 return u"" | 55 return "" |
56 decoded = data.decode("utf-8", "ignore")[: -1 if data[-1] == "\n" else None] | 56 decoded = data.decode("utf-8", "ignore")[: -1 if data[-1] == "\n" else None] |
57 return clean_ustr(decoded) | 57 return clean_ustr(decoded) |
58 | 58 |
59 def connectionMade(self): | 59 def connectionMade(self): |
60 log.info("connectionMade :)") | 60 log.info("connectionMade :)") |
64 | 64 |
65 def errReceived(self, data): | 65 def errReceived(self, data): |
66 self.client.sendMessage(self.target, {"": self._clean(data)}, no_trigger=True) | 66 self.client.sendMessage(self.target, {"": self._clean(data)}, no_trigger=True) |
67 | 67 |
68 def processEnded(self, reason): | 68 def processEnded(self, reason): |
69 log.info(u"process finished: %d" % (reason.value.exitCode,)) | 69 log.info("process finished: %d" % (reason.value.exitCode,)) |
70 self.parent.removeProcess(self.target, self) | 70 self.parent.removeProcess(self.target, self) |
71 | 71 |
72 def write(self, message): | 72 def write(self, message): |
73 self.transport.write(message.encode("utf-8")) | 73 self.transport.write(message.encode("utf-8")) |
74 | 74 |
118 from_jid = jid.JID(message_elt["from"]) | 118 from_jid = jid.JID(message_elt["from"]) |
119 spawned_key = (from_jid.userhostJID(), client.profile) | 119 spawned_key = (from_jid.userhostJID(), client.profile) |
120 | 120 |
121 if spawned_key in self.spawned: | 121 if spawned_key in self.spawned: |
122 try: | 122 try: |
123 body = message_elt.elements(C.NS_CLIENT, "body").next() | 123 body = next(message_elt.elements(C.NS_CLIENT, "body")) |
124 except StopIteration: | 124 except StopIteration: |
125 # do not block message without body (chat state notification...) | 125 # do not block message without body (chat state notification...) |
126 return True | 126 return True |
127 | 127 |
128 mess_data = unicode(body) + "\n" | 128 mess_data = str(body) + "\n" |
129 processes_set = self.spawned[spawned_key] | 129 processes_set = self.spawned[spawned_key] |
130 _continue = False | 130 _continue = False |
131 exclusive = False | 131 exclusive = False |
132 for process in processes_set: | 132 for process in processes_set: |
133 process.write(mess_data) | 133 process.write(mess_data) |
156 _jid = jid.JID(target) | 156 _jid = jid.JID(target) |
157 if not _jid.user or not _jid.host: | 157 if not _jid.user or not _jid.host: |
158 raise jid.InvalidFormat | 158 raise jid.InvalidFormat |
159 _jid = _jid.userhostJID() | 159 _jid = _jid.userhostJID() |
160 except (RuntimeError, jid.InvalidFormat, AttributeError): | 160 except (RuntimeError, jid.InvalidFormat, AttributeError): |
161 log.info(u"invalid target ignored: %s" % (target,)) | 161 log.info("invalid target ignored: %s" % (target,)) |
162 continue | 162 continue |
163 process_prot = ExportCommandProtocol(self, client, _jid, options) | 163 process_prot = ExportCommandProtocol(self, client, _jid, options) |
164 self.spawned.setdefault((_jid, client.profile), set()).add(process_prot) | 164 self.spawned.setdefault((_jid, client.profile), set()).add(process_prot) |
165 reactor.spawnProcess( | 165 reactor.spawnProcess( |
166 process_prot, command, args, usePTY=process_prot.boolOption("pty") | 166 process_prot, command, args, usePTY=process_prot.boolOption("pty") |