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
This commit is contained in:
Goffi 2019-08-13 19:08:41 +02:00
commit fbfe96c505

View file

@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# SAT plugin for managing Quiz game
@ -190,7 +190,7 @@ class Quiz(object):
"""Convert a domish element with game_data to a dict"""
game_data = {}
for data_elt in game_data_elt.elements():
game_data[data_elt.name] = unicode(data_elt)
game_data[data_elt.name] = str(data_elt)
return game_data
def __answer_result_to_signal_args(self, answer_result_elt):
@ -255,7 +255,7 @@ class Quiz(object):
"""Called when a player give an answer"""
client = self.host.getClient(profile_key)
log.debug(
u"new player answer (%(profile)s): %(answer)s"
"new player answer (%(profile)s): %(answer)s"
% {"profile": client.profile, "answer": answer}
)
mess = self.createGameElt(jid.JID(referee))
@ -309,7 +309,7 @@ class Quiz(object):
mess = self.createGameElt(room_jid)
mess.firstChildElement().addChild(
self.__ask_question(
game_data["question_id"], u"Quel est l'âge du capitaine ?", timer
game_data["question_id"], "Quel est l'âge du capitaine ?", timer
)
)
client.send(mess)
@ -343,7 +343,7 @@ class Quiz(object):
common_data = {"game_score": 0}
new_game_data = {
"instructions": _(
u"""Bienvenue dans cette partie rapide de quizz, le premier à atteindre le score de 9 remporte le jeu
"""Bienvenue dans cette partie rapide de quizz, le premier à atteindre le score de 9 remporte le jeu
Attention, tu es prêt ?"""
)
@ -366,7 +366,7 @@ Attention, tu es prêt ?"""
if elt.name == "started": # new game created
players = []
for player in elt.elements():
players.append(unicode(player))
players.append(str(player))
self.host.bridge.quizGameStarted(
room_jid.userhost(), from_jid.full(), players, profile
)
@ -377,11 +377,11 @@ Attention, tu es prêt ?"""
nb_players = len(self.games[room_jid]["players"])
status[player] = "ready"
log.debug(
_(u"Player %(player)s is ready to start [status: %(status)s]")
_("Player %(player)s is ready to start [status: %(status)s]")
% {"player": player, "status": status}
)
if (
status.values().count("ready") == nb_players
list(status.values()).count("ready") == nb_players
): # everybody is ready, we can start the game
self.newGame(room_jid, profile)
@ -394,7 +394,7 @@ Attention, tu es prêt ?"""
self.host.bridge.quizGameQuestion(
room_jid.userhost(),
elt["id"],
unicode(elt),
str(elt),
int(elt["timer"]),
profile,
)
@ -414,7 +414,7 @@ Attention, tu es prêt ?"""
self.pauseTimer(room_jid)
# and we send the player answer
mess = self.createGameElt(room_jid)
_answer = unicode(elt)
_answer = str(elt)
say_elt = mess.firstChildElement().addElement("player_says")
say_elt["player"] = player
say_elt.addContent(_answer)
@ -433,7 +433,7 @@ Attention, tu es prêt ?"""
self.host.bridge.quizGamePlayerSays(
room_jid.userhost(),
elt["player"],
unicode(elt),
str(elt),
int(elt["delay"]),
profile,
)
@ -453,4 +453,4 @@ Attention, tu es prêt ?"""
)
else:
log.error(_(u"Unmanaged game element: %s") % elt.name)
log.error(_("Unmanaged game element: %s") % elt.name)