diff sat/test/test_plugin_misc_radiocol.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 56f94936df1e
children 559a625a236b
line wrap: on
line diff
--- a/sat/test/test_plugin_misc_radiocol.py	Wed Jul 31 11:31:22 2019 +0200
+++ b/sat/test/test_plugin_misc_radiocol.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
@@ -24,7 +24,7 @@
 from sat.test import helpers, helpers_plugins
 from sat.plugins import plugin_misc_radiocol as plugin
 from sat.plugins import plugin_misc_room_game as plugin_room_game
-from constants import Const
+from .constants import Const
 
 from twisted.words.protocols.jabber.jid import JID
 from twisted.words.xish import domish
@@ -40,7 +40,7 @@
     from mutagen.id3 import ID3NoHeaderError
 except ImportError:
     raise exceptions.MissingModule(
-        u"Missing module Mutagen, please download/install from https://bitbucket.org/lazka/mutagen"
+        "Missing module Mutagen, please download/install from https://bitbucket.org/lazka/mutagen"
     )
 
 import uuid
@@ -91,7 +91,7 @@
             content += "/>"
         else:
             content += ">"
-            for i in xrange(0, len(players)):
+            for i in range(0, len(players)):
                 content += "<player index='%s'>%s</player>" % (i, players[i])
             content += "</started>"
         return content
@@ -168,10 +168,10 @@
         """
         sent = self.host.getSentMessage(0)
         attrs["sender"] = self.plugin_0045.getNick(0, profile_index)
-        radiocol_elt = domish.generateElementsNamed(sent.elements(), "radiocol").next()
-        preload_elt = domish.generateElementsNamed(
+        radiocol_elt = next(domish.generateElementsNamed(sent.elements(), "radiocol"))
+        preload_elt = next(domish.generateElementsNamed(
             radiocol_elt.elements(), "preload"
-        ).next()
+        ))
         attrs["timestamp"] = preload_elt["timestamp"]  # we could not guess it...
         content = "<preload xmlns='' %s/>" % " ".join(
             ["%s='%s'" % (attr, attrs[attr]) for attr in attrs]
@@ -301,7 +301,7 @@
                 else room.roster[recipient].entity.full()
             )
 
-        for index in xrange(0, len(Const.PROFILE)):
+        for index in range(0, len(Const.PROFILE)):
             nick = self.plugin_0045.getNick(0, index)
             if nick:
                 if not recipient or nick == recipient:
@@ -410,7 +410,7 @@
         @param profile_index: index of the uploader's profile
         """
         if song_index is None:
-            dst_filepath = unicode(uuid.uuid1())
+            dst_filepath = str(uuid.uuid1())
             expect_io_error = True
         else:
             song_index = song_index % len(self.songs)
@@ -483,7 +483,7 @@
 
         # another songs are added by Const.JID[1] until the radio starts + 1 to fill the queue
         # when the first song starts + 1 to be rejected because the queue is full
-        for song_index in xrange(1, plugin.QUEUE_TO_START + 1):
+        for song_index in range(1, plugin.QUEUE_TO_START + 1):
             self._uploadSong(song_index, 1)
 
         self.plugin.playNext(Const.MUC[0], PROFILE)  # simulate the end of the first song