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 Publish-Subscribe (xep-0071)
|
||||
|
|
@ -27,14 +27,14 @@ from sat.tools.common import data_format
|
|||
|
||||
from twisted.internet import defer
|
||||
from wokkel import disco, iwokkel
|
||||
from zope.interface import implements
|
||||
from zope.interface import implementer
|
||||
|
||||
# from lxml import etree
|
||||
try:
|
||||
from lxml import html
|
||||
except ImportError:
|
||||
raise exceptions.MissingModule(
|
||||
u"Missing module lxml, please download/install it from http://lxml.de/"
|
||||
"Missing module lxml, please download/install it from http://lxml.de/"
|
||||
)
|
||||
try:
|
||||
from twisted.words.protocols.xmlstream import XMPPHandler
|
||||
|
|
@ -176,14 +176,14 @@ class XEP_0071(object):
|
|||
|
||||
syntax = self._s.getCurrentSyntax(client.profile)
|
||||
defers = []
|
||||
if u"xhtml" in data["extra"]:
|
||||
if "xhtml" in data["extra"]:
|
||||
# we have directly XHTML
|
||||
for lang, xhtml in data_format.getSubDict("xhtml", data["extra"]):
|
||||
self._check_body_text(data, lang, xhtml, self._s.SYNTAX_XHTML, defers)
|
||||
d = self._s.convert(xhtml, self._s.SYNTAX_XHTML, self.SYNTAX_XHTML_IM)
|
||||
d.addCallback(syntax_converted, lang)
|
||||
defers.append(d)
|
||||
elif u"rich" in data["extra"]:
|
||||
elif "rich" in data["extra"]:
|
||||
# we have rich syntax to convert
|
||||
for lang, rich_data in data_format.getSubDict("rich", data["extra"]):
|
||||
self._check_body_text(data, lang, rich_data, syntax, defers)
|
||||
|
|
@ -191,7 +191,7 @@ class XEP_0071(object):
|
|||
d.addCallback(syntax_converted, lang)
|
||||
defers.append(d)
|
||||
else:
|
||||
exceptions.InternalError(u"xhtml or rich should be present at this point")
|
||||
exceptions.InternalError("xhtml or rich should be present at this point")
|
||||
d_list = defer.DeferredList(defers)
|
||||
d_list.addCallback(lambda __: data)
|
||||
return d_list
|
||||
|
|
@ -200,7 +200,7 @@ class XEP_0071(object):
|
|||
""" Check presence of XHTML-IM in message
|
||||
"""
|
||||
try:
|
||||
html_elt = message.elements(NS_XHTML_IM, "html").next()
|
||||
html_elt = next(message.elements(NS_XHTML_IM, "html"))
|
||||
except StopIteration:
|
||||
# No XHTML-IM
|
||||
pass
|
||||
|
|
@ -213,14 +213,14 @@ class XEP_0071(object):
|
|||
""" Check presence of rich text in extra """
|
||||
rich = {}
|
||||
xhtml = {}
|
||||
for key, value in data["extra"].iteritems():
|
||||
for key, value in data["extra"].items():
|
||||
if key.startswith("rich"):
|
||||
rich[key[5:]] = value
|
||||
elif key.startswith("xhtml"):
|
||||
xhtml[key[6:]] = value
|
||||
if rich and xhtml:
|
||||
raise exceptions.DataError(
|
||||
_(u"Can't have XHTML and rich content at the same time")
|
||||
_("Can't have XHTML and rich content at the same time")
|
||||
)
|
||||
if rich or xhtml:
|
||||
if rich:
|
||||
|
|
@ -247,7 +247,7 @@ class XEP_0071(object):
|
|||
continue
|
||||
purged.append((name, value.strip()))
|
||||
|
||||
return u"; ".join([u"%s: %s" % data for data in purged])
|
||||
return "; ".join(["%s: %s" % data for data in purged])
|
||||
|
||||
def XHTML2XHTML_IM(self, xhtml):
|
||||
""" Convert XHTML document to XHTML_IM subset
|
||||
|
|
@ -265,7 +265,7 @@ class XEP_0071(object):
|
|||
else:
|
||||
body_elt.attrib.clear()
|
||||
|
||||
allowed_tags = allowed.keys()
|
||||
allowed_tags = list(allowed.keys())
|
||||
to_strip = []
|
||||
for elem in body_elt.iter():
|
||||
if elem.tag not in allowed_tags:
|
||||
|
|
@ -282,7 +282,7 @@ class XEP_0071(object):
|
|||
for elem in to_strip:
|
||||
if elem.tag in blacklist:
|
||||
# we need to remove the element and all descendants
|
||||
log.debug(u"removing black listed tag: %s" % (elem.tag))
|
||||
log.debug("removing black listed tag: %s" % (elem.tag))
|
||||
elem.drop_tree()
|
||||
else:
|
||||
elem.drop_tag()
|
||||
|
|
@ -295,8 +295,8 @@ class XEP_0071(object):
|
|||
return html.tostring(root_elt, encoding="unicode", method="xml")
|
||||
|
||||
|
||||
@implementer(iwokkel.IDisco)
|
||||
class XEP_0071_handler(XMPPHandler):
|
||||
implements(iwokkel.IDisco)
|
||||
|
||||
def __init__(self, plugin_parent):
|
||||
self.plugin_parent = plugin_parent
|
||||
|
|
|
|||
Loading…
Reference in a new issue