diff sat/tools/sat_defer.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 cd391ea847cb
children 9d0df638c8b4
line wrap: on
line diff
--- a/sat/tools/sat_defer.py	Wed Jul 31 11:31:22 2019 +0200
+++ b/sat/tools/sat_defer.py	Tue Aug 13 19:08:41 2019 +0200
@@ -1,4 +1,4 @@
-#!/usr/bin/env python2
+#!/usr/bin/env python3
 # -*- coding: utf-8 -*-
 
 # SàT: a XMPP client
@@ -38,7 +38,7 @@
 def stanza2NotFound(failure_):
     """Convert item-not-found StanzaError to exceptions.NotFound"""
     failure_.trap(jabber_error.StanzaError)
-    if failure_.value.condition == u'item-not-found':
+    if failure_.value.condition == 'item-not-found':
         raise exceptions.NotFound(failure_.value.text or failure_.value.condition)
     return failure_
 
@@ -107,8 +107,8 @@
             data, profile=profile
         )
         if isinstance(deferreds, dict):
-            session_data[KEY_DEFERREDS] = deferreds.values()
-            iterator = deferreds.iteritems()
+            session_data[KEY_DEFERREDS] = list(deferreds.values())
+            iterator = iter(deferreds.items())
         else:
             session_data[KEY_DEFERREDS] = deferreds
             iterator = enumerate(deferreds)
@@ -121,7 +121,7 @@
         return session_id
 
     def _purgeSession(
-        self, session_id, reason=u"timeout", no_warning=False, got_result=False
+        self, session_id, reason="timeout", no_warning=False, got_result=False
     ):
         """Purge the session
 
@@ -137,7 +137,7 @@
                 timer, session_data, profile = self._sessions[session_id]
             except ValueError:
                 raise exceptions.InternalError(
-                    u"was expecting timer, session_data and profile; is profile set ?"
+                    "was expecting timer, session_data and profile; is profile set ?"
                 )
 
             # next_defer must be called before deferreds,
@@ -152,7 +152,7 @@
 
             if not no_warning:
                 log.warning(
-                    u"RTDeferredList cancelled: {} (profile {})".format(reason, profile)
+                    "RTDeferredList cancelled: {} (profile {})".format(reason, profile)
                 )
 
         super(RTDeferredSessions, self)._purgeSession(session_id)
@@ -175,7 +175,7 @@
         deferred._RTDeferred_return = (False, failure)
         self._gotResult(session_id, profile)
 
-    def cancel(self, session_id, reason=u"timeout", no_log=False):
+    def cancel(self, session_id, reason="timeout", no_log=False):
         """Stop this RTDeferredList
 
         Cancel all remaining deferred, and call self.final_defer.errback