comparison 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
comparison
equal deleted inserted replaced
3027:ff5bcb12ae60 3028:ab2696e34d29
1 #!/usr/bin/env python2 1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*- 2 # -*- coding: utf-8 -*-
3 3
4 # SAT: a jabber client 4 # SAT: a jabber client
5 # Copyright (C) 2009, 2010, 2011, 2012, 2013 Jérôme Poisson (goffi@goffi.org) 5 # Copyright (C) 2009, 2010, 2011, 2012, 2013 Jérôme Poisson (goffi@goffi.org)
6 # Copyright (C) 2013 Adrien Cossa (souliane@mailoo.org) 6 # Copyright (C) 2013 Adrien Cossa (souliane@mailoo.org)
22 22
23 from sat.core import exceptions 23 from sat.core import exceptions
24 from sat.test import helpers, helpers_plugins 24 from sat.test import helpers, helpers_plugins
25 from sat.plugins import plugin_misc_radiocol as plugin 25 from sat.plugins import plugin_misc_radiocol as plugin
26 from sat.plugins import plugin_misc_room_game as plugin_room_game 26 from sat.plugins import plugin_misc_room_game as plugin_room_game
27 from constants import Const 27 from .constants import Const
28 28
29 from twisted.words.protocols.jabber.jid import JID 29 from twisted.words.protocols.jabber.jid import JID
30 from twisted.words.xish import domish 30 from twisted.words.xish import domish
31 from twisted.internet import reactor 31 from twisted.internet import reactor
32 from twisted.internet import defer 32 from twisted.internet import defer
38 from mutagen.mp3 import MP3 38 from mutagen.mp3 import MP3
39 from mutagen.easyid3 import EasyID3 39 from mutagen.easyid3 import EasyID3
40 from mutagen.id3 import ID3NoHeaderError 40 from mutagen.id3 import ID3NoHeaderError
41 except ImportError: 41 except ImportError:
42 raise exceptions.MissingModule( 42 raise exceptions.MissingModule(
43 u"Missing module Mutagen, please download/install from https://bitbucket.org/lazka/mutagen" 43 "Missing module Mutagen, please download/install from https://bitbucket.org/lazka/mutagen"
44 ) 44 )
45 45
46 import uuid 46 import uuid
47 import os 47 import os
48 import copy 48 import copy
89 content = "<started" 89 content = "<started"
90 if not players: 90 if not players:
91 content += "/>" 91 content += "/>"
92 else: 92 else:
93 content += ">" 93 content += ">"
94 for i in xrange(0, len(players)): 94 for i in range(0, len(players)):
95 content += "<player index='%s'>%s</player>" % (i, players[i]) 95 content += "<player index='%s'>%s</player>" % (i, players[i])
96 content += "</started>" 96 content += "</started>"
97 return content 97 return content
98 98
99 def _expectedMessage(self, to_jid, type_, content): 99 def _expectedMessage(self, to_jid, type_, content):
166 @param attrs: information dict about the song 166 @param attrs: information dict about the song
167 @param profile_index: profile index of the uploader 167 @param profile_index: profile index of the uploader
168 """ 168 """
169 sent = self.host.getSentMessage(0) 169 sent = self.host.getSentMessage(0)
170 attrs["sender"] = self.plugin_0045.getNick(0, profile_index) 170 attrs["sender"] = self.plugin_0045.getNick(0, profile_index)
171 radiocol_elt = domish.generateElementsNamed(sent.elements(), "radiocol").next() 171 radiocol_elt = next(domish.generateElementsNamed(sent.elements(), "radiocol"))
172 preload_elt = domish.generateElementsNamed( 172 preload_elt = next(domish.generateElementsNamed(
173 radiocol_elt.elements(), "preload" 173 radiocol_elt.elements(), "preload"
174 ).next() 174 ))
175 attrs["timestamp"] = preload_elt["timestamp"] # we could not guess it... 175 attrs["timestamp"] = preload_elt["timestamp"] # we could not guess it...
176 content = "<preload xmlns='' %s/>" % " ".join( 176 content = "<preload xmlns='' %s/>" % " ".join(
177 ["%s='%s'" % (attr, attrs[attr]) for attr in attrs] 177 ["%s='%s'" % (attr, attrs[attr]) for attr in attrs]
178 ) 178 )
179 if sent.hasAttribute("from"): 179 if sent.hasAttribute("from"):
299 Const.JID_STR[0] 299 Const.JID_STR[0]
300 if recipient == room.nick 300 if recipient == room.nick
301 else room.roster[recipient].entity.full() 301 else room.roster[recipient].entity.full()
302 ) 302 )
303 303
304 for index in xrange(0, len(Const.PROFILE)): 304 for index in range(0, len(Const.PROFILE)):
305 nick = self.plugin_0045.getNick(0, index) 305 nick = self.plugin_0045.getNick(0, index)
306 if nick: 306 if nick:
307 if not recipient or nick == recipient: 307 if not recipient or nick == recipient:
308 if call and ( 308 if call and (
309 self.plugin.isPlayer(ROOM_JID, nick) 309 self.plugin.isPlayer(ROOM_JID, nick)
408 408
409 @param song_index: index of the song or None to test with non existing file 409 @param song_index: index of the song or None to test with non existing file
410 @param profile_index: index of the uploader's profile 410 @param profile_index: index of the uploader's profile
411 """ 411 """
412 if song_index is None: 412 if song_index is None:
413 dst_filepath = unicode(uuid.uuid1()) 413 dst_filepath = str(uuid.uuid1())
414 expect_io_error = True 414 expect_io_error = True
415 else: 415 else:
416 song_index = song_index % len(self.songs) 416 song_index = song_index % len(self.songs)
417 src_filename = self.songs[song_index] 417 src_filename = self.songs[song_index]
418 dst_filepath = "/tmp/%s%s" % (uuid.uuid1(), os.path.splitext(src_filename)[1]) 418 dst_filepath = "/tmp/%s%s" % (uuid.uuid1(), os.path.splitext(src_filename)[1])
481 ) # ogg or mp3 file should exist in sat_media/test/song 481 ) # ogg or mp3 file should exist in sat_media/test/song
482 self._uploadSong(None, 0) # non existing file 482 self._uploadSong(None, 0) # non existing file
483 483
484 # another songs are added by Const.JID[1] until the radio starts + 1 to fill the queue 484 # another songs are added by Const.JID[1] until the radio starts + 1 to fill the queue
485 # when the first song starts + 1 to be rejected because the queue is full 485 # when the first song starts + 1 to be rejected because the queue is full
486 for song_index in xrange(1, plugin.QUEUE_TO_START + 1): 486 for song_index in range(1, plugin.QUEUE_TO_START + 1):
487 self._uploadSong(song_index, 1) 487 self._uploadSong(song_index, 1)
488 488
489 self.plugin.playNext(Const.MUC[0], PROFILE) # simulate the end of the first song 489 self.plugin.playNext(Const.MUC[0], PROFILE) # simulate the end of the first song
490 self._playNextSongCb() 490 self._playNextSongCb()
491 self._uploadSong( 491 self._uploadSong(