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:
parent
d21a6a660f
commit
fbfe96c505
1 changed files with 6336 additions and 6398 deletions
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# SAT plugin for managing French Tarot game
|
||||
|
|
@ -87,7 +87,7 @@ class Tarot(object):
|
|||
in_sign="asss",
|
||||
out_sign="",
|
||||
method=self._prepareRoom,
|
||||
async=True,
|
||||
async_=True,
|
||||
) # args: players, room_jid, profile
|
||||
host.bridge.addMethod(
|
||||
"tarotGameCreate",
|
||||
|
|
@ -138,10 +138,10 @@ class Tarot(object):
|
|||
"tarotGameInvalidCards", ".plugin", signature="ssa(ss)a(ss)s"
|
||||
) # args: room_jid, game phase, played_cards, invalid_cards, profile
|
||||
self.deck_ordered = []
|
||||
for value in ["excuse"] + map(str, range(1, 22)):
|
||||
for value in ["excuse"] + list(map(str, list(range(1, 22)))):
|
||||
self.deck_ordered.append(TarotCard(("atout", value)))
|
||||
for suit in ["pique", "coeur", "carreau", "trefle"]:
|
||||
for value in map(str, range(1, 11)) + ["valet", "cavalier", "dame", "roi"]:
|
||||
for value in list(map(str, list(range(1, 11)))) + ["valet", "cavalier", "dame", "roi"]:
|
||||
self.deck_ordered.append(TarotCard((suit, value)))
|
||||
self.__choose_contrat_id = host.registerCallback(
|
||||
self._contratChoosed, with_data=True
|
||||
|
|
@ -172,7 +172,7 @@ class Tarot(object):
|
|||
field = data_form.Field(
|
||||
"list-single",
|
||||
"contrat",
|
||||
options=map(data_form.Option, self.contrats),
|
||||
options=list(map(data_form.Option, self.contrats)),
|
||||
required=True,
|
||||
)
|
||||
form.addField(field)
|
||||
|
|
@ -271,7 +271,7 @@ class Tarot(object):
|
|||
players_data[pl_waiting]["levees"].append(card)
|
||||
log.debug(
|
||||
_(
|
||||
u"Player %(excuse_owner)s give %(card_waited)s to %(player_waiting)s for Excuse compensation"
|
||||
"Player %(excuse_owner)s give %(card_waited)s to %(player_waiting)s for Excuse compensation"
|
||||
)
|
||||
% {
|
||||
"excuse_owner": player,
|
||||
|
|
@ -311,7 +311,7 @@ class Tarot(object):
|
|||
players_data[winner]["levees"].append(low_card)
|
||||
log.debug(
|
||||
_(
|
||||
u"Player %(excuse_owner)s give %(card_waited)s to %(player_waiting)s for Excuse compensation"
|
||||
"Player %(excuse_owner)s give %(card_waited)s to %(player_waiting)s for Excuse compensation"
|
||||
)
|
||||
% {
|
||||
"excuse_owner": excuse_player,
|
||||
|
|
@ -325,7 +325,7 @@ class Tarot(object):
|
|||
players_data[excuse_player]["wait_for_low"] = winner
|
||||
log.debug(
|
||||
_(
|
||||
u"%(excuse_owner)s keep the Excuse but has not card to give, %(winner)s is waiting for one"
|
||||
"%(excuse_owner)s keep the Excuse but has not card to give, %(winner)s is waiting for one"
|
||||
)
|
||||
% {"excuse_owner": excuse_player, "winner": winner}
|
||||
)
|
||||
|
|
@ -339,7 +339,7 @@ class Tarot(object):
|
|||
scores_str += "\n"
|
||||
for player in game_data["players"]:
|
||||
scores_str += _(
|
||||
u"\n--\n%(player)s:\nscore for this game ==> %(score_game)i\ntotal score ==> %(total_score)i"
|
||||
"\n--\n%(player)s:\nscore for this game ==> %(score_game)i\ntotal score ==> %(total_score)i"
|
||||
) % {
|
||||
"player": player,
|
||||
"score_game": 0,
|
||||
|
|
@ -420,7 +420,7 @@ class Tarot(object):
|
|||
loosers.append(player)
|
||||
|
||||
scores_str = _(
|
||||
u"The attacker (%(attaquant)s) makes %(points)i and needs to make %(point_limit)i (%(nb_bouts)s oulder%(plural)s%(separator)s%(bouts)s): (s)he %(victory)s"
|
||||
"The attacker (%(attaquant)s) makes %(points)i and needs to make %(point_limit)i (%(nb_bouts)s oulder%(plural)s%(separator)s%(bouts)s): (s)he %(victory)s"
|
||||
) % {
|
||||
"attaquant": game_data["attaquant"],
|
||||
"points": score,
|
||||
|
|
@ -434,7 +434,7 @@ class Tarot(object):
|
|||
scores_str += "\n"
|
||||
for player in game_data["players"]:
|
||||
scores_str += _(
|
||||
u"\n--\n%(player)s:\nscore for this game ==> %(score_game)i\ntotal score ==> %(total_score)i"
|
||||
"\n--\n%(player)s:\nscore for this game ==> %(score_game)i\ntotal score ==> %(total_score)i"
|
||||
) % {
|
||||
"player": player,
|
||||
"score_game": player_score[player],
|
||||
|
|
@ -537,7 +537,7 @@ class Tarot(object):
|
|||
data = xml_tools.XMLUIResult2DataFormResult(raw_data)
|
||||
contrat = data["contrat"]
|
||||
log.debug(
|
||||
_(u"contrat [%(contrat)s] choosed by %(profile)s")
|
||||
_("contrat [%(contrat)s] choosed by %(profile)s")
|
||||
% {"contrat": contrat, "profile": profile}
|
||||
)
|
||||
d = self.send(
|
||||
|
|
@ -578,10 +578,10 @@ class Tarot(object):
|
|||
"""
|
||||
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"Cards played by %(profile)s: [%(cards)s]")
|
||||
_("Cards played by %(profile)s: [%(cards)s]")
|
||||
% {"profile": profile, "cards": cards}
|
||||
)
|
||||
elem = self.__card_list_to_xml(TarotCard.from_tuples(cards), "cards_played")
|
||||
|
|
@ -647,7 +647,7 @@ class Tarot(object):
|
|||
): # new game created and/or players list updated
|
||||
players = []
|
||||
for player in elt.elements():
|
||||
players.append(unicode(player))
|
||||
players.append(str(player))
|
||||
signal = (
|
||||
self.host.bridge.tarotGameStarted
|
||||
if elt.name == "started"
|
||||
|
|
@ -661,11 +661,11 @@ class Tarot(object):
|
|||
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.newRound(room_jid, profile)
|
||||
|
||||
|
|
@ -689,7 +689,7 @@ class Tarot(object):
|
|||
# TODO: check we receive the contrat from the right person
|
||||
# TODO: use proper XEP-0004 way for answering form
|
||||
player = elt["player"]
|
||||
players_data[player]["contrat"] = unicode(elt)
|
||||
players_data[player]["contrat"] = str(elt)
|
||||
contrats = [players_data[p]["contrat"] for p in game_data["players"]]
|
||||
if contrats.count(None):
|
||||
# not everybody has choosed his contrat, it's next one turn
|
||||
|
|
@ -720,7 +720,7 @@ class Tarot(object):
|
|||
game_data["status"][player] = "init"
|
||||
return
|
||||
log.debug(
|
||||
_(u"%(player)s win the bid with %(contrat)s")
|
||||
_("%(player)s win the bid with %(contrat)s")
|
||||
% {"player": best_contrat[0], "contrat": best_contrat[1]}
|
||||
)
|
||||
game_data["contrat"] = best_contrat[1]
|
||||
|
|
@ -825,7 +825,7 @@ class Tarot(object):
|
|||
if all(played):
|
||||
# everybody has played
|
||||
winner = self.__winner(game_data)
|
||||
log.debug(_(u"The winner of this trick is %s") % winner)
|
||||
log.debug(_("The winner of this trick is %s") % winner)
|
||||
# the winner win the trick
|
||||
self.__excuse_hack(game_data, played, winner)
|
||||
players_data[elt["player"]]["levees"].extend(played)
|
||||
|
|
@ -861,13 +861,13 @@ class Tarot(object):
|
|||
self.host.bridge.tarotGameYourTurn(room_jid.userhost(), profile)
|
||||
|
||||
elif elt.name == "score":
|
||||
form_elt = elt.elements(name="x", uri="jabber:x:data").next()
|
||||
form_elt = next(elt.elements(name="x", uri="jabber:x:data"))
|
||||
winners = []
|
||||
loosers = []
|
||||
for winner in elt.elements(name="winner", uri=NS_CG):
|
||||
winners.append(unicode(winner))
|
||||
winners.append(str(winner))
|
||||
for looser in elt.elements(name="looser", uri=NS_CG):
|
||||
loosers.append(unicode(looser))
|
||||
loosers.append(str(looser))
|
||||
form = data_form.Form.fromElement(form_elt)
|
||||
session_id, session_data = self._sessions.newSession(profile=profile)
|
||||
session_data["room_jid"] = room_jid
|
||||
|
|
@ -880,10 +880,10 @@ class Tarot(object):
|
|||
elif elt.name == "error":
|
||||
if elt["type"] == "invalid_cards":
|
||||
played_cards = self.__xml_to_list(
|
||||
elt.elements(name="played", uri=NS_CG).next()
|
||||
next(elt.elements(name="played", uri=NS_CG))
|
||||
)
|
||||
invalid_cards = self.__xml_to_list(
|
||||
elt.elements(name="invalid", uri=NS_CG).next()
|
||||
next(elt.elements(name="invalid", uri=NS_CG))
|
||||
)
|
||||
self.host.bridge.tarotGameInvalidCards(
|
||||
room_jid.userhost(),
|
||||
|
|
@ -893,9 +893,9 @@ class Tarot(object):
|
|||
profile,
|
||||
)
|
||||
else:
|
||||
log.error(_(u"Unmanaged error type: %s") % elt["type"])
|
||||
log.error(_("Unmanaged error type: %s") % elt["type"])
|
||||
else:
|
||||
log.error(_(u"Unmanaged card game element: %s") % elt.name)
|
||||
log.error(_("Unmanaged card game element: %s") % elt.name)
|
||||
|
||||
def getSyncDataForPlayer(self, room_jid, nick):
|
||||
return []
|
||||
|
|
|
|||
Loading…
Reference in a new issue