diff sat/plugins/plugin_misc_room_game.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_room_game.py	Wed Jul 31 11:31:22 2019 +0200
+++ b/sat/plugins/plugin_misc_room_game.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: a jabber client
@@ -27,7 +27,7 @@
 from twisted.internet import defer
 from time import time
 from wokkel import disco, iwokkel
-from zope.interface import implements
+from zope.interface import implementer
 import copy
 
 try:
@@ -64,13 +64,13 @@
     """
 
     # Values for self.invite_mode (who can invite after the game creation)
-    FROM_ALL, FROM_NONE, FROM_REFEREE, FROM_PLAYERS = xrange(0, 4)
+    FROM_ALL, FROM_NONE, FROM_REFEREE, FROM_PLAYERS = range(0, 4)
     # Values for self.wait_mode (for who we should wait before creating the game)
-    FOR_ALL, FOR_NONE = xrange(0, 2)
+    FOR_ALL, FOR_NONE = range(0, 2)
     # Values for self.join_mode (who can join the game - NONE means solo game)
-    ALL, INVITED, NONE = xrange(0, 3)
+    ALL, INVITED, NONE = range(0, 3)
     # Values for ready_mode (how to turn a MUC user into a player)
-    ASK, FORCE = xrange(0, 2)
+    ASK, FORCE = range(0, 2)
 
     MESSAGE = "/message"
     REQUEST = '%s/%s[@xmlns="%s"]'
@@ -218,7 +218,7 @@
 
         if not auth and (verbose or _DEBUG):
             log.debug(
-                _(u"%(user)s not allowed to join the game %(game)s in %(room)s")
+                _("%(user)s not allowed to join the game %(game)s in %(room)s")
                 % {
                     "user": user_jid.userhost() or nick,
                     "game": self.name,
@@ -377,7 +377,7 @@
             auth = self.isPlayer(room_jid, nick)
         if not auth and (verbose or _DEBUG):
             log.debug(
-                _(u"%(user)s not allowed to invite for the game %(game)s in %(room)s")
+                _("%(user)s not allowed to invite for the game %(game)s in %(room)s")
                 % {"user": nick, "game": self.name, "room": room_jid.userhost()}
             )
         return auth
@@ -431,7 +431,7 @@
         if not result[0] and (verbose or _DEBUG):
             log.debug(
                 _(
-                    u"Still waiting for %(users)s before starting the game %(game)s in %(room)s"
+                    "Still waiting for %(users)s before starting the game %(game)s in %(room)s"
                 )
                 % {
                     "users": result[2],
@@ -469,7 +469,7 @@
         """
         # FIXME: need to be refactored
         client = self.host.getClient(profile_key)
-        log.debug(_(u"Preparing room for %s game") % self.name)
+        log.debug(_("Preparing room for %s game") % self.name)
         profile = self.host.memory.getProfileName(profile_key)
         if not profile:
             log.error(_("Unknown profile"))
@@ -515,7 +515,7 @@
             batch = len(self.invitations[room_jid]) - 1
             if batch < 0:
                 log.error(
-                    u"Invitations from %s to play %s in %s have been lost!"
+                    "Invitations from %s to play %s in %s have been lost!"
                     % (profile_nick, self.name, room_jid.userhost())
                 )
                 return True
@@ -572,7 +572,7 @@
         user_nick = self.host.plugins["XEP-0045"].getRoomNick(room_jid, profile)
         if not user_nick:
             log.error(
-                u"Internal error: profile %s has not joined the room %s"
+                "Internal error: profile %s has not joined the room %s"
                 % (profile, room_jid.userhost())
             )
             return False, False
@@ -580,13 +580,13 @@
             is_referee = self.isReferee(room_jid, user_nick)
             if self._gameExists(room_jid, started=True):
                 log.info(
-                    _(u"%(game)s game already created in room %(room)s")
+                    _("%(game)s game already created in room %(room)s")
                     % {"game": self.name, "room": room_jid.userhost()}
                 )
                 return False, is_referee
             elif not is_referee:
                 log.info(
-                    _(u"%(game)s game in room %(room)s can only be created by %(user)s")
+                    _("%(game)s game in room %(room)s can only be created by %(user)s")
                     % {"game": self.name, "room": room_jid.userhost(), "user": user_nick}
                 )
                 return False, False
@@ -607,12 +607,12 @@
         @param profile_key (unicode): %(doc_profile_key)s
         """
         log.debug(
-            _(u"Creating %(game)s game in room %(room)s")
+            _("Creating %(game)s game in room %(room)s")
             % {"game": self.name, "room": room_jid}
         )
         profile = self.host.memory.getProfileName(profile_key)
         if not profile:
-            log.error(_(u"profile %s is unknown") % profile_key)
+            log.error(_("profile %s is unknown") % profile_key)
             return
         (create, sync) = self._checkCreateGameAndInit(room_jid, profile)
         if nicks is None:
@@ -643,9 +643,9 @@
         """
         profile = self.host.memory.getProfileName(profile_key)
         if not profile:
-            log.error(_(u"profile %s is unknown") % profile_key)
+            log.error(_("profile %s is unknown") % profile_key)
             return
-        log.debug(u"new player ready: %s" % profile)
+        log.debug("new player ready: %s" % profile)
         # TODO: we probably need to add the game and room names in the sent message
         self.send(referee_jid, "player_ready", {"player": player_nick}, profile=profile)
 
@@ -658,7 +658,7 @@
                     - msg_elts: dict to map each user to his specific initialization message
         @param profile
         """
-        log.debug(_(u"new round for %s game") % self.name)
+        log.debug(_("new round for %s game") % self.name)
         game_data = self.games[room_jid]
         players = game_data["players"]
         players_data = game_data["players_data"]
@@ -763,8 +763,8 @@
         return RoomGameHandler(self)
 
 
+@implementer(iwokkel.IDisco)
 class RoomGameHandler(XMPPHandler):
-    implements(iwokkel.IDisco)
 
     def __init__(self, plugin_parent):
         self.plugin_parent = plugin_parent