Mercurial > libervia-backend
diff sat/plugins/plugin_misc_nat-port.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 |
line wrap: on
line diff
--- a/sat/plugins/plugin_misc_nat-port.py Wed Jul 31 11:31:22 2019 +0200 +++ b/sat/plugins/plugin_misc_nat-port.py Tue Aug 13 19:08:41 2019 +0200 @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 # -*- coding: utf-8 -*- # SAT plugin for NAT port mapping @@ -32,7 +32,7 @@ import miniupnpc except ImportError: raise exceptions.MissingModule( - u"Missing module MiniUPnPc, please download/install it (and its Python binding) at http://miniupnp.free.fr/ (or use pip install miniupnpc)" + "Missing module MiniUPnPc, please download/install it (and its Python binding) at http://miniupnp.free.fr/ (or use pip install miniupnpc)" ) @@ -47,7 +47,7 @@ STARTING_PORT = 6000 # starting point to automatically find a port DEFAULT_DESC = ( - u"SaT port mapping" + "SaT port mapping" ) # we don't use "à" here as some bugged NAT don't manage charset correctly @@ -74,23 +74,23 @@ def unload(self): if self._to_unmap: - log.info(u"Cleaning mapped ports") + log.info("Cleaning mapped ports") return threads.deferToThread(self._unmapPortsBlocking) def _init_failed(self, failure_): e = failure_.trap(exceptions.NotFound, exceptions.FeatureNotFound) if e == exceptions.FeatureNotFound: - log.info(u"UPnP-IGD seems to be not activated on the device") + log.info("UPnP-IGD seems to be not activated on the device") else: - log.info(u"UPnP-IGD not available") + log.info("UPnP-IGD not available") self._upnp = None def _discover(self): devices = self._upnp.discover() if devices: - log.info(u"{nb} UPnP-IGD device(s) found".format(nb=devices)) + log.info("{nb} UPnP-IGD device(s) found".format(nb=devices)) else: - log.info(u"Can't find UPnP-IGD device on the local network") + log.info("Can't find UPnP-IGD device on the local network") raise failure.Failure(exceptions.NotFound()) self._upnp.selectigd() try: @@ -119,7 +119,7 @@ self._mutex.acquire() try: for port, protocol in self._to_unmap: - log.info(u"Unmapping port {}".format(port)) + log.info("Unmapping port {}".format(port)) unmapping = self._upnp.deleteportmapping( # the last parameter is remoteHost, we don't use it port, @@ -129,7 +129,7 @@ if not unmapping: log.error( - u"Can't unmap port {port} ({protocol})".format( + "Can't unmap port {port} ({protocol})".format( port=port, protocol=protocol ) ) @@ -174,7 +174,7 @@ "", ) except Exception as e: - log.error(_(u"addportmapping error: {msg}").format(msg=e)) + log.error(_("addportmapping error: {msg}").format(msg=e)) raise failure.Failure(MappingError()) if not mapping: @@ -201,7 +201,7 @@ def mappingCb(ext_port): log.info( - u"{protocol} mapping from {int_port} to {ext_port} successful".format( + "{protocol} mapping from {int_port} to {ext_port} successful".format( protocol=protocol, int_port=int_port, ext_port=ext_port ) ) @@ -209,10 +209,10 @@ def mappingEb(failure_): failure_.trap(MappingError) - log.warning(u"Can't map internal {int_port}".format(int_port=int_port)) + log.warning("Can't map internal {int_port}".format(int_port=int_port)) def mappingUnknownEb(failure_): - log.error(_(u"error while trying to map ports: {msg}").format(msg=failure_)) + log.error(_("error while trying to map ports: {msg}").format(msg=failure_)) d = threads.deferToThread( self._mapPortBlocking, int_port, ext_port, protocol, desc