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
18 changed files with 6336 additions and 6398 deletions

View file

@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Primitivus: a SAT frontend
@ -33,19 +33,19 @@ class Const(object):
"test_profile5",
]
JID_STR = [
u"test@example.org/SàT",
u"sender@example.net/house",
u"sender@example.net/work",
u"sender@server.net/res",
u"xxx@server.net/res",
"test@example.org/SàT",
"sender@example.net/house",
"sender@example.net/work",
"sender@server.net/res",
"xxx@server.net/res",
]
JID = [jid.JID(jid_s) for jid_s in JID_STR]
PROFILE_DICT = {}
for i in xrange(0, len(PROFILE)):
for i in range(0, len(PROFILE)):
PROFILE_DICT[PROFILE[i]] = JID[i]
MUC_STR = [u"room@chat.server.domain", u"sat_game@chat.server.domain"]
MUC_STR = ["room@chat.server.domain", "sat_game@chat.server.domain"]
MUC = [jid.JID(jid_s) for jid_s in MUC_STR]
NO_SECURITY_LIMIT = -1

View file

@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# SAT: a jabber client
@ -28,7 +28,7 @@ getLogger().setLevel(logging.WARNING) # put this to DEBUG when needed
from sat.core import exceptions
from sat.tools import config as tools_config
from constants import Const as C
from .constants import Const as C
from wokkel.xmppim import RosterItem
from wokkel.generic import parseXml
from sat.core.xmpp import SatRosterProtocol
@ -49,7 +49,7 @@ def b2s(value):
@return: unicode conversion, according to bridge convention
"""
return u"True" if value else u"False"
return "True" if value else "False"
def muteLogging():
@ -232,11 +232,11 @@ class FakeBridge(object):
def checkCall(*args, **kwargs):
if args != check_args or kwargs != check_kwargs:
print "\n\n--------------------"
print "Args are not equals:"
print "args\n----\n%s (sent)\n%s (wanted)" % (args, check_args)
print "kwargs\n------\n%s (sent)\n%s (wanted)" % (kwargs, check_kwargs)
print "--------------------\n\n"
print("\n\n--------------------")
print("Args are not equals:")
print("args\n----\n%s (sent)\n%s (wanted)" % (args, check_args))
print("kwargs\n------\n%s (sent)\n%s (wanted)" % (kwargs, check_kwargs))
print("--------------------\n\n")
raise DifferentArgsException
delattr(self, name)
@ -248,7 +248,7 @@ class FakeBridge(object):
setattr(self, name, checkCall)
def addMethod(self, name, int_suffix, in_sign, out_sign, method, async=False, doc=None):
def addMethod(self, name, int_suffix, in_sign, out_sign, method, async_=False, doc=None):
pass
def addSignal(self, name, int_suffix, signature):
@ -386,7 +386,7 @@ class FakeXmlStream(object):
@param obj (domish.Element, str or unicode): message to send
"""
if not isinstance(obj, domish.Element):
assert(isinstance(obj, str) or isinstance(obj, unicode))
assert(isinstance(obj, str) or isinstance(obj, str))
obj = parseXml(obj)
if obj.name == 'iq':
@ -432,21 +432,21 @@ class SatTestCase(unittest.TestCase):
value = None
setattr(elt, attr, value)
if (got_elt.tag != exp_elt.tag):
print "XML are not equals (elt %s/%s):" % (got_elt, exp_elt)
print "tag: got [%s] expected: [%s]" % (got_elt.tag, exp_elt.tag)
print("XML are not equals (elt %s/%s):" % (got_elt, exp_elt))
print("tag: got [%s] expected: [%s]" % (got_elt.tag, exp_elt.tag))
return False
if (got_elt.attrib != exp_elt.attrib):
print "XML are not equals (elt %s/%s):" % (got_elt, exp_elt)
print "attribs: got %s expected %s" % (got_elt.attrib, exp_elt.attrib)
print("XML are not equals (elt %s/%s):" % (got_elt, exp_elt))
print("attribs: got %s expected %s" % (got_elt.attrib, exp_elt.attrib))
return False
if (got_elt.tail != exp_elt.tail or got_elt.text != exp_elt.text):
print "XML are not equals (elt %s/%s):" % (got_elt, exp_elt)
print "text: got [%s] expected: [%s]" % (got_elt.text, exp_elt.text)
print "tail: got [%s] expected: [%s]" % (got_elt.tail, exp_elt.tail)
print("XML are not equals (elt %s/%s):" % (got_elt, exp_elt))
print("text: got [%s] expected: [%s]" % (got_elt.text, exp_elt.text))
print("tail: got [%s] expected: [%s]" % (got_elt.tail, exp_elt.tail))
return False
if (len(got_elt) != len(exp_elt)):
print "XML are not equals (elt %s/%s):" % (got_elt, exp_elt)
print "children len: got %d expected: %d" % (len(got_elt), len(exp_elt))
print("XML are not equals (elt %s/%s):" % (got_elt, exp_elt))
print("children len: got %d expected: %d" % (len(got_elt), len(exp_elt)))
return False
for idx, child in enumerate(got_elt):
if not equalElt(child, exp_elt[idx]):
@ -461,22 +461,22 @@ class SatTestCase(unittest.TestCase):
expected_elt = etree.fromstring(remove_blank(expected) if ignore_blank else expected)
if not equalElt(xml_elt, expected_elt):
print "---"
print "XML are not equals:"
print "got:\n-\n%s\n-\n\n" % etree.tostring(xml_elt, encoding='utf-8')
print "was expecting:\n-\n%s\n-\n\n" % etree.tostring(expected_elt, encoding='utf-8')
print "---"
print("---")
print("XML are not equals:")
print("got:\n-\n%s\n-\n\n" % etree.tostring(xml_elt, encoding='utf-8'))
print("was expecting:\n-\n%s\n-\n\n" % etree.tostring(expected_elt, encoding='utf-8'))
print("---")
raise DifferentXMLException
def assertEqualUnsortedList(self, a, b, msg):
counter_a = Counter(a)
counter_b = Counter(b)
if counter_a != counter_b:
print "---"
print "Unsorted lists are not equals:"
print "got : %s" % counter_a
print "was expecting: %s" % counter_b
print("---")
print("Unsorted lists are not equals:")
print("got : %s" % counter_a)
print("was expecting: %s" % counter_b)
if msg:
print msg
print "---"
print(msg)
print("---")
raise DifferentListException

View file

@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# SAT: a jabber client
@ -29,7 +29,7 @@ from wokkel.disco import DiscoItem, DiscoItems
# temporary until the changes are integrated to Wokkel
from sat_tmp.wokkel.rsm import RSMResponse
from constants import Const as C
from .constants import Const as C
from sat.plugins import plugin_xep_0045
from collections import OrderedDict
@ -52,7 +52,7 @@ class FakeMUCClient(object):
roster = {}
# ask the other profiles to fill our roster
for i in xrange(0, len(C.PROFILE)):
for i in range(0, len(C.PROFILE)):
other_profile = C.PROFILE[i]
if other_profile == profile:
continue
@ -69,7 +69,7 @@ class FakeMUCClient(object):
pass
# rename our nick if it already exists
while nick in roster.keys():
while nick in list(roster.keys()):
if C.PROFILE_DICT[profile].userhost() == roster[nick].entity.userhost():
break # same user with different resource --> same nickname
nick = nick + "_"
@ -79,7 +79,7 @@ class FakeMUCClient(object):
self.joined_rooms[room_jid] = room
# fill the other rosters with the new entry
for i in xrange(0, len(C.PROFILE)):
for i in range(0, len(C.PROFILE)):
other_profile = C.PROFILE[i]
if other_profile == profile:
continue
@ -104,7 +104,7 @@ class FakeMUCClient(object):
profile = self.host.memory.getProfileName(profile_key)
room = self.joined_rooms[roomJID]
# remove ourself from the other rosters
for i in xrange(0, len(C.PROFILE)):
for i in range(0, len(C.PROFILE)):
other_profile = C.PROFILE[i]
if other_profile == profile:
continue
@ -252,7 +252,7 @@ class FakeSatPubSubClient(object):
return False
for item in items:
item_obj = parseXml(item) if isinstance(item, unicode) else item
item_obj = parseXml(item) if isinstance(item, str) else item
if not replace(item_obj):
node.append(item_obj)
return defer.succeed(None)
@ -296,6 +296,6 @@ class FakeSatPubSubClient(object):
def service_getDiscoItems(self, service, nodeIdentifier, profile_key=C.PROF_KEY_NONE):
items = DiscoItems()
for item in self.__items.keys():
for item in list(self.__items.keys()):
items.append(DiscoItem(service, item))
return defer.succeed(items)

View file

@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# SAT: a jabber client
@ -18,7 +18,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from sat.test import helpers
from constants import Const
from .constants import Const
from twisted.trial import unittest
from sat.core import xmpp
from twisted.words.protocols.jabber.jid import JID
@ -35,7 +35,7 @@ class SatXMPPClientTest(unittest.TestCase):
def test_init(self):
"""Check that init values are correctly initialised"""
self.assertEqual(self.client.profile, Const.PROFILE[0])
print self.client.host
print(self.client.host)
self.assertEqual(self.client.host_app, self.host)
@ -53,7 +53,7 @@ class SatMessageProtocolTest(unittest.TestCase):
</message>
"""
stanza = parseXml(xml)
self.host.bridge.expectCall("messageNew", u"sender@example.net/house", u"test", u"chat", u"test@example.org/SàT", {}, profile=Const.PROFILE[0])
self.host.bridge.expectCall("messageNew", "sender@example.net/house", "test", "chat", "test@example.org/SàT", {}, profile=Const.PROFILE[0])
self.message.onMessage(stanza)
@ -66,12 +66,12 @@ class SatRosterProtocolTest(unittest.TestCase):
def test__registerItem(self):
roster_item = RosterItem(Const.JID[0])
roster_item.name = u"Test Man"
roster_item.name = "Test Man"
roster_item.subscriptionTo = True
roster_item.subscriptionFrom = True
roster_item.ask = False
roster_item.groups = set([u"Test Group 1", u"Test Group 2", u"Test Group 3"])
self.host.bridge.expectCall("newContact", Const.JID_STR[0], {'to': 'True', 'from': 'True', 'ask': 'False', 'name': u'Test Man'}, set([u"Test Group 1", u"Test Group 2", u"Test Group 3"]), Const.PROFILE[0])
roster_item.groups = set(["Test Group 1", "Test Group 2", "Test Group 3"])
self.host.bridge.expectCall("newContact", Const.JID_STR[0], {'to': 'True', 'from': 'True', 'ask': 'False', 'name': 'Test Man'}, set(["Test Group 1", "Test Group 2", "Test Group 3"]), Const.PROFILE[0])
self.roster._registerItem(roster_item)

View file

@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# SAT: a jabber client

View file

@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# SAT: a jabber client
@ -21,7 +21,7 @@ from sat.core.i18n import _
from sat.test import helpers
from twisted.trial import unittest
import traceback
from constants import Const
from .constants import Const
from xml.dom import minidom

View file

@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# SAT: a jabber client
@ -30,7 +30,7 @@ from twisted.internet import defer
def getRandomUnicode(len):
"""Return a random unicode string"""
return u"".join(random.choice(string.letters + u"éáúóâêûôßüöä") for i in xrange(len))
return "".join(random.choice(string.letters + "éáúóâêûôßüöä") for i in range(len))
class CryptoTest(helpers.SatTestCase):

View file

@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# SAT: a jabber client
@ -20,7 +20,7 @@
""" Plugin groupblogs """
from constants import Const as C
from .constants import Const as C
from sat.test import helpers, helpers_plugins
from sat.plugins import plugin_misc_groupblog
from sat.plugins import plugin_xep_0060
@ -29,30 +29,31 @@ from sat.plugins import plugin_xep_0163
from sat.plugins import plugin_misc_text_syntaxes
from twisted.internet import defer
from twisted.words.protocols.jabber import jid
import importlib
NS_PUBSUB = "http://jabber.org/protocol/pubsub"
DO_NOT_COUNT_COMMENTS = -1
SERVICE = u"pubsub.example.com"
PUBLISHER = u"test@example.org"
OTHER_PUBLISHER = u"other@xmpp.net"
NODE_ID = u"urn:xmpp:groupblog:{publisher}".format(publisher=PUBLISHER)
OTHER_NODE_ID = u"urn:xmpp:groupblog:{publisher}".format(publisher=OTHER_PUBLISHER)
ITEM_ID_1 = u"c745a688-9b02-11e3-a1a3-c0143dd4fe51"
COMMENT_ID_1 = u"d745a688-9b02-11e3-a1a3-c0143dd4fe52"
COMMENT_ID_2 = u"e745a688-9b02-11e3-a1a3-c0143dd4fe53"
SERVICE = "pubsub.example.com"
PUBLISHER = "test@example.org"
OTHER_PUBLISHER = "other@xmpp.net"
NODE_ID = "urn:xmpp:groupblog:{publisher}".format(publisher=PUBLISHER)
OTHER_NODE_ID = "urn:xmpp:groupblog:{publisher}".format(publisher=OTHER_PUBLISHER)
ITEM_ID_1 = "c745a688-9b02-11e3-a1a3-c0143dd4fe51"
COMMENT_ID_1 = "d745a688-9b02-11e3-a1a3-c0143dd4fe52"
COMMENT_ID_2 = "e745a688-9b02-11e3-a1a3-c0143dd4fe53"
def COMMENTS_NODE_ID(publisher=PUBLISHER):
return u"urn:xmpp:comments:_{id}__urn:xmpp:groupblog:{publisher}".format(
return "urn:xmpp:comments:_{id}__urn:xmpp:groupblog:{publisher}".format(
id=ITEM_ID_1, publisher=publisher
)
def COMMENTS_NODE_URL(publisher=PUBLISHER):
return u"xmpp:{service}?node={node}".format(
return "xmpp:{service}?node={node}".format(
service=SERVICE,
id=ITEM_ID_1,
node=COMMENTS_NODE_ID(publisher).replace(":", "%3A").replace("@", "%40"),
@ -60,7 +61,7 @@ def COMMENTS_NODE_URL(publisher=PUBLISHER):
def ITEM(publisher=PUBLISHER):
return u"""
return """
<item id='{id}' xmlns='{ns}'>
<entry>
<title type='text'>The Uses of This World</title>
@ -82,7 +83,7 @@ def ITEM(publisher=PUBLISHER):
def COMMENT(id_=COMMENT_ID_1):
return u"""
return """
<item id='{id}' xmlns='{ns}'>
<entry>
<title type='text'>The Uses of This World</title>
@ -113,7 +114,7 @@ def ITEM_DATA(id_=ITEM_ID_1, count=0):
"comments_node": COMMENTS_NODE_ID_1,
}
if count != DO_NOT_COUNT_COMMENTS:
res.update({"comments_count": unicode(count)})
res.update({"comments_count": str(count)})
return res
@ -154,7 +155,7 @@ class XEP_groupblogTest(helpers.SatTestCase):
self.host = helpers.FakeSAT()
self.host.plugins["XEP-0060"] = plugin_xep_0060.XEP_0060(self.host)
self.host.plugins["XEP-0163"] = plugin_xep_0163.XEP_0163(self.host)
reload(plugin_misc_text_syntaxes) # reload the plugin to avoid conflict error
importlib.reload(plugin_misc_text_syntaxes) # reload the plugin to avoid conflict error
self.host.plugins["TEXT_SYNTAXES"] = plugin_misc_text_syntaxes.TextSyntaxes(
self.host
)
@ -215,7 +216,7 @@ class XEP_groupblogTest(helpers.SatTestCase):
def test_updateGroupBlog(self):
pub_data = (SERVICE, NODE_ID, ITEM_ID_1)
new_text = u"silfu23RFWUP)IWNOEIOEFÖ"
new_text = "silfu23RFWUP)IWNOEIOEFÖ"
self._initialise(C.PROFILE[0])
d = self.psclient.publish(SERVICE, NODE_ID, [ITEM_1])
@ -370,7 +371,7 @@ class XEP_groupblogTest(helpers.SatTestCase):
)
def cb(atom):
self.assertIsInstance(atom, unicode)
self.assertIsInstance(atom, str)
self.assertTrue(atom.startswith('<?xml version="1.0" encoding="utf-8"?>'))
return d.addCallback(cb)

View file

@ -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.core import exceptions
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 @@ try:
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 @@ class RadiocolTest(helpers.SatTestCase):
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 @@ class RadiocolTest(helpers.SatTestCase):
"""
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 @@ class RadiocolTest(helpers.SatTestCase):
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 @@ class RadiocolTest(helpers.SatTestCase):
@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 @@ class RadiocolTest(helpers.SatTestCase):
# 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

View file

@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# SAT: a jabber client
@ -21,7 +21,7 @@
""" Tests for the plugin room game (base class for MUC games) """
from sat.core.i18n import _
from constants import Const
from .constants import Const
from sat.test import helpers, helpers_plugins
from sat.plugins import plugin_misc_room_game as plugin
from twisted.words.protocols.jabber.jid import JID
@ -77,7 +77,7 @@ class RoomGameTest(helpers.SatTestCase):
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 += "</%s>" % tag
return "<message to='%s' type='%s'><%s xmlns='%s'>%s</dummy></message>" % (

View file

@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# SAT: a jabber client
@ -23,6 +23,7 @@ from sat.test import helpers
from sat.plugins import plugin_misc_text_syntaxes
from twisted.trial.unittest import SkipTest
import re
import importlib
class SanitisationTest(helpers.SatTestCase):
@ -58,11 +59,11 @@ class SanitisationTest(helpers.SatTestCase):
def setUp(self):
self.host = helpers.FakeSAT()
reload(plugin_misc_text_syntaxes) # reload the plugin to avoid conflict error
importlib.reload(plugin_misc_text_syntaxes) # reload the plugin to avoid conflict error
self.text_syntaxes = plugin_misc_text_syntaxes.TextSyntaxes(self.host)
def test_xhtml_sanitise(self):
expected = u"""<div>
expected = """<div>
<style>/* deleted */</style>
<body>
<a href="">a link</a>
@ -82,7 +83,7 @@ class SanitisationTest(helpers.SatTestCase):
return d
def test_styles_sanitise(self):
expected = u"""<p style="color: blue">test <strong>retest</strong><br/><span style="color: #cf2828; font-size: 3px; color: red; color: red !important; font-size: 100px !important; font-size: 100%; font-size: 100px; font-size: 100; font-size: 100 %; color: rgba(0, 0, 0, 0.1); color: rgb(35,79,255); background-color: no-repeat"> toto </span></p>"""
expected = """<p style="color: blue">test <strong>retest</strong><br/><span style="color: #cf2828; font-size: 3px; color: red; color: red !important; font-size: 100px !important; font-size: 100%; font-size: 100px; font-size: 100; font-size: 100 %; color: rgba(0, 0, 0, 0.1); color: rgb(35,79,255); background-color: no-repeat"> toto </span></p>"""
d = self.text_syntaxes.cleanXHTML(self.EVIL_HTML2)
d.addCallback(self.assertEqualXML, expected)
@ -105,10 +106,10 @@ class SanitisationTest(helpers.SatTestCase):
return d
def test_removeXHTMLMarkups(self):
expected = u""" a link another link a paragraph secret EVIL! of EVIL! Password: annoying EVIL! spam spam SPAM! """
expected = """ a link another link a paragraph secret EVIL! of EVIL! Password: annoying EVIL! spam spam SPAM! """
result = self.text_syntaxes._removeMarkups(self.EVIL_HTML1)
self.assertEqual(re.sub(r"\s+", " ", result).rstrip(), expected.rstrip())
expected = u"""test retest toto"""
expected = """test retest toto"""
result = self.text_syntaxes._removeMarkups(self.EVIL_HTML2)
self.assertEqual(re.sub(r"\s+", " ", result).rstrip(), expected.rstrip())

View file

@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# SAT: a jabber client
@ -20,7 +20,7 @@
""" Plugin extended addressing stanzas """
from constants import Const
from .constants import Const
from sat.test import helpers
from sat.plugins import plugin_xep_0033 as plugin
from sat.core.exceptions import CancelError
@ -46,7 +46,7 @@ class XEP_0033Test(helpers.SatTestCase):
def test_messageReceived(self):
self.host.memory.reinit()
xml = u"""
xml = """
<message type="chat" from="%s" to="%s" id="test_1">
<body>test</body>
<addresses xmlns='http://jabber.org/protocol/address'>
@ -87,7 +87,7 @@ class XEP_0033Test(helpers.SatTestCase):
"extra": {},
}
mess_data["extra"]["address"] = "%s:%s\n%s:%s\n%s:%s\n" % ADDRS
original_stanza = u"""
original_stanza = """
<message type="chat" from="%s" to="%s" id="test_1">
<body>content</body>
</message>

View file

@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# SAT: a jabber client
@ -20,7 +20,7 @@
""" Plugin chat states notification tests """
from constants import Const
from .constants import Const
from sat.test import helpers
from sat.core.constants import Const as C
from sat.plugins import plugin_xep_0085 as plugin
@ -43,7 +43,7 @@ class XEP_0085Test(helpers.SatTestCase):
def test_messageReceived(self):
for state in plugin.CHAT_STATES:
xml = u"""
xml = """
<message type="chat" from="%s" to="%s" id="test_1">
%s
<%s xmlns='%s'/>
@ -77,7 +77,7 @@ class XEP_0085Test(helpers.SatTestCase):
"message": "content",
"extra": {} if state == "active" else {"chat_state": state},
}
stanza = u"""
stanza = """
<message type="chat" from="%s" to="%s" id="test_1">
%s
</message>

View file

@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# SAT: a jabber client

View file

@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# SAT: a jabber client
@ -25,12 +25,13 @@ from sat.plugins import plugin_xep_0060
from sat.plugins import plugin_misc_text_syntaxes
from sat.tools.xml_tools import ElementParser
from wokkel.pubsub import NS_PUBSUB
import importlib
class XEP_0277Test(helpers.SatTestCase):
PUBSUB_ENTRY_1 = (
u"""
"""
<item id="c745a688-9b02-11e3-a1a3-c0143dd4fe51">
<entry xmlns="%s">
<title type="text">&lt;span&gt;titre&lt;/span&gt;</title>
@ -49,7 +50,7 @@ class XEP_0277Test(helpers.SatTestCase):
)
PUBSUB_ENTRY_2 = (
u"""
"""
<item id="c745a688-9b02-11e3-a1a3-c0143dd4fe51">
<entry xmlns='%s'>
<title type="text">&lt;div&gt;titre&lt;/div&gt;</title>
@ -81,7 +82,7 @@ class XEP_0277Test(helpers.SatTestCase):
self.host.plugins["XEP-0060"] = plugin_xep_0060.XEP_0060(self.host)
self.host.plugins["XEP-0163"] = XEP_0163(self.host)
reload(plugin_misc_text_syntaxes) # reload the plugin to avoid conflict error
importlib.reload(plugin_misc_text_syntaxes) # reload the plugin to avoid conflict error
self.host.plugins["TEXT_SYNTAXES"] = plugin_misc_text_syntaxes.TextSyntaxes(
self.host
)
@ -89,17 +90,17 @@ class XEP_0277Test(helpers.SatTestCase):
def test_item2mbdata_1(self):
expected = {
u"id": u"c745a688-9b02-11e3-a1a3-c0143dd4fe51",
u"atom_id": u"c745a688-9b02-11e3-a1a3-c0143dd4fe51",
u"title": u"<span>titre</span>",
u"updated": u"1392992199.0",
u"published": u"1392992198.0",
u"content": u"<p>contenu</p>texte sans balise<p>autre contenu</p>",
u"content_xhtml": u"<div><p>contenu</p>texte sans balise<p>autre contenu</p></div>",
u"author": u"test1@souliane.org",
"id": "c745a688-9b02-11e3-a1a3-c0143dd4fe51",
"atom_id": "c745a688-9b02-11e3-a1a3-c0143dd4fe51",
"title": "<span>titre</span>",
"updated": "1392992199.0",
"published": "1392992198.0",
"content": "<p>contenu</p>texte sans balise<p>autre contenu</p>",
"content_xhtml": "<div><p>contenu</p>texte sans balise<p>autre contenu</p></div>",
"author": "test1@souliane.org",
}
item_elt = (
ElementParser()(self.PUBSUB_ENTRY_1, namespace=NS_PUBSUB).elements().next()
next(ElementParser()(self.PUBSUB_ENTRY_1, namespace=NS_PUBSUB).elements())
)
d = self.plugin.item2mbdata(item_elt)
d.addCallback(self.assertEqual, expected)
@ -107,18 +108,18 @@ class XEP_0277Test(helpers.SatTestCase):
def test_item2mbdata_2(self):
expected = {
u"id": u"c745a688-9b02-11e3-a1a3-c0143dd4fe51",
u"atom_id": u"c745a688-9b02-11e3-a1a3-c0143dd4fe51",
u"title": u"<div>titre</div>",
u"title_xhtml": u'<div><div style="">titre</div></div>',
u"updated": u"1392992199.0",
u"published": u"1392992198.0",
u"content": u"<div><p>contenu</p>texte dans balise<p>autre contenu</p></div>",
u"content_xhtml": u"<div><p>contenu</p>texte dans balise<p>autre contenu</p></div>",
u"author": u"test1@souliane.org",
"id": "c745a688-9b02-11e3-a1a3-c0143dd4fe51",
"atom_id": "c745a688-9b02-11e3-a1a3-c0143dd4fe51",
"title": "<div>titre</div>",
"title_xhtml": '<div><div style="">titre</div></div>',
"updated": "1392992199.0",
"published": "1392992198.0",
"content": "<div><p>contenu</p>texte dans balise<p>autre contenu</p></div>",
"content_xhtml": "<div><p>contenu</p>texte dans balise<p>autre contenu</p></div>",
"author": "test1@souliane.org",
}
item_elt = (
ElementParser()(self.PUBSUB_ENTRY_2, namespace=NS_PUBSUB).elements().next()
next(ElementParser()(self.PUBSUB_ENTRY_2, namespace=NS_PUBSUB).elements())
)
d = self.plugin.item2mbdata(item_elt)
d.addCallback(self.assertEqual, expected)

View file

@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# SAT: a jabber client
@ -20,7 +20,7 @@
""" Plugin XEP-0297 """
from constants import Const as C
from .constants import Const as C
from sat.test import helpers
from sat.plugins.plugin_xep_0203 import XEP_0203
from sat.plugins.plugin_xep_0297 import XEP_0297

View file

@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# SAT: a jabber client
@ -20,7 +20,7 @@
""" Plugin XEP-0313 """
from constants import Const as C
from .constants import Const as C
from sat.test import helpers
from sat.plugins.plugin_xep_0313 import XEP_0313
from twisted.words.protocols.jabber.jid import JID
@ -209,7 +209,7 @@ class XEP_0313Test(helpers.SatTestCase):
)
start = datetime.datetime(2010, 8, 7, 0, 0, 0, tzinfo=tzutc())
form = buildForm(start=start)
rsm = RSMRequest(max_=10, after=u"09af3-cc343-b409f")
rsm = RSMRequest(max_=10, after="09af3-cc343-b409f")
d = self.plugin.queryArchive(self.client, MAMRequest(form, rsm), SERVICE_JID)
d.addCallback(
lambda __: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)

View file

@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# SAT: a jabber client
@ -20,7 +20,7 @@
""" Plugin XEP-0334 """
from constants import Const as C
from .constants import Const as C
from sat.test import helpers
from sat.plugins.plugin_xep_0334 import XEP_0334
from twisted.internet import defer