Mercurial > libervia-backend
diff sat/plugins/plugin_misc_android.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 | 758bee45612b |
children | f91d0e6d9b13 |
line wrap: on
line diff
--- a/sat/plugins/plugin_misc_android.py Wed Jul 31 11:31:22 2019 +0200 +++ b/sat/plugins/plugin_misc_android.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 file tansfer @@ -36,7 +36,7 @@ C.PI_NAME: "Android ", C.PI_IMPORT_NAME: "android", C.PI_TYPE: C.PLUG_TYPE_MISC, - C.PI_RECOMMENDATIONS: [u"XEP-0352"], + C.PI_RECOMMENDATIONS: ["XEP-0352"], C.PI_MAIN: "AndroidPlugin", C.PI_HANDLER: "no", C.PI_DESCRIPTION: D_( @@ -45,7 +45,7 @@ } if sys.platform != "android": - raise exceptions.CancelError(u"this module is not needed on this platform") + raise exceptions.CancelError("this module is not needed on this platform") from plyer import notification, vibrator @@ -60,7 +60,7 @@ PARAM_VIBRATE_CATEGORY = "Notifications" PARAM_VIBRATE_NAME = "vibrate" -PARAM_VIBRATE_LABEL = D_(u"Vibrate on notifications") +PARAM_VIBRATE_LABEL = D_("Vibrate on notifications") SOCKET_DIR = "/data/data/org.salutatoi.cagou/" SOCKET_FILE = ".socket" STATE_RUNNING = "running" @@ -101,9 +101,9 @@ f.seek(0, os.SEEK_END) size = f.tell() if size == 10: - log.info(u"seek() bug not present anymore, workaround code can be removed") + log.info("seek() bug not present anymore, workaround code can be removed") else: - log.warning(u"seek() bug detected, applying a workaround") + log.warning("seek() bug detected, applying a workaround") web_client.FileBodyProducer._determineLength = determineLength_workaround patch_seek_bug() @@ -118,7 +118,7 @@ if data in STATES: self.android_plugin.state = data else: - log.warning(u"Unexpected data: {data}".format(data=data)) + log.warning("Unexpected data: {data}".format(data=data)) class FrontendStateFactory(protocol.Factory): @@ -149,13 +149,13 @@ ) def __init__(self, host): - log.info(_(u"plugin Android initialization")) + log.info(_("plugin Android initialization")) self.host = host - self._csi = host.plugins.get(u'XEP-0352') + self._csi = host.plugins.get('XEP-0352') self._csi_timer = None host.memory.updateParams(self.params) try: - os.mkdir(SOCKET_DIR, 0700) + os.mkdir(SOCKET_DIR, 0o700) except OSError as e: if e.errno == 17: # dir already exists @@ -188,7 +188,7 @@ self.br = BroadcastReceiver( callback=lambda *args, **kwargs: reactor.callLater(0, self.onConnectivityChange), - actions=[u"android.net.conn.CONNECTIVITY_CHANGE"]) + actions=["android.net.conn.CONNECTIVITY_CHANGE"]) self.br.start() @@ -198,7 +198,7 @@ @state.setter def state(self, new_state): - log.debug(u"frontend state has changed: {state}".format(state=new_state)) + log.debug("frontend state has changed: {state}".format(state=new_state)) previous_state = self._state self._state = new_state if new_state == STATE_RUNNING: @@ -233,11 +233,11 @@ """ if (mess_data["message"] and mess_data["type"] != C.MESS_TYPE_GROUPCHAT and not mess_data["from"].userhostJID() == client.jid.userhostJID()): - message = mess_data["message"].itervalues().next() + message = next(iter(mess_data["message"].values())) try: - subject = mess_data["subject"].itervalues().next() + subject = next(iter(mess_data["subject"].values())) except StopIteration: - subject = u"Cagou new message" + subject = "Cagou new message" notification.notify(title=subject, message=message) if self.host.memory.getParamA( @@ -248,7 +248,7 @@ except Exception as e: # FIXME: vibrator is currently not working, # cf. https://github.com/kivy/plyer/issues/509 - log.warning(u"Can't use vibrator: {e}".format(e=e)) + log.warning("Can't use vibrator: {e}".format(e=e)) return mess_data def messageReceivedTrigger(self, client, message_elt, post_treat): @@ -306,24 +306,24 @@ else: net_type = NET_TYPE_OTHER if net_type != self._net_type: - log.info(u"connectivity has changed") + log.info("connectivity has changed") previous = self._net_type self._net_type = net_type if net_type == NET_TYPE_NONE: - log.info(u"no network active") + log.info("no network active") elif net_type == NET_TYPE_WIFI: - log.info(u"WIFI activated") + log.info("WIFI activated") elif net_type == NET_TYPE_MOBILE: - log.info(u"mobile data activated") + log.info("mobile data activated") else: - log.info(u"network activated (type={net_type_android})" + log.info("network activated (type={net_type_android})" .format(net_type_android=net_type_android)) self._handleNetworkChange(previous, net_type) else: - log.debug(u"_checkConnectivity called without network change ({net_type})" + log.debug("_checkConnectivity called without network change ({net_type})" .format(net_type = net_type)) def onConnectivityChange(self): - log.debug(u"onConnectivityChange called") + log.debug("onConnectivityChange called") self._checkConnectivity()