Commit 6bbd903a authored by Jérome Perrin's avatar Jérome Perrin

web: py3 WIP

parent 872e02d7
...@@ -1130,7 +1130,7 @@ return True ...@@ -1130,7 +1130,7 @@ return True
"quoted-printable", "quoted-printable",
) )
self.assertEqual(htmlmessage.get("Content-Location"), page.absolute_url()) self.assertEqual(htmlmessage.get("Content-Location"), page.absolute_url())
self.assertEqual(quopri.decodestring(htmlmessage.get_payload()), html_data) self.assertEqual(quopri.decodestring(htmlmessage.get_payload()).decode(), html_data)
def test_WebPageAsEmbeddedHtml_pageWithLink(self): def test_WebPageAsEmbeddedHtml_pageWithLink(self):
"""Test convert one html page with links to embedded html file""" """Test convert one html page with links to embedded html file"""
...@@ -1184,7 +1184,7 @@ return True ...@@ -1184,7 +1184,7 @@ return True
"quoted-printable", "quoted-printable",
) )
self.assertEqual(htmlmessage.get("Content-Location"), page.absolute_url()) self.assertEqual(htmlmessage.get("Content-Location"), page.absolute_url())
self.assertEqual(quopri.decodestring(htmlmessage.get_payload()), "".join([ self.assertEqual(quopri.decodestring(htmlmessage.get_payload()).decode(), "".join([
"<p>Hello</p>", "<p>Hello</p>",
'<a href="%s//a.a/">aa</a>' % self.portal.absolute_url().split("/", 1)[0], '<a href="%s//a.a/">aa</a>' % self.portal.absolute_url().split("/", 1)[0],
'<a href="%s/b">bb</a>' % self.portal.absolute_url(), '<a href="%s/b">bb</a>' % self.portal.absolute_url(),
...@@ -1194,7 +1194,7 @@ return True ...@@ -1194,7 +1194,7 @@ return True
message = EmailParser().parsestr(mhtml_data) message = EmailParser().parsestr(mhtml_data)
htmlmessage, = message.get_payload() htmlmessage, = message.get_payload()
self.assertEqual(htmlmessage.get("Content-Location"), "https://hel.lo/world") self.assertEqual(htmlmessage.get("Content-Location"), "https://hel.lo/world")
self.assertEqual(quopri.decodestring(htmlmessage.get_payload()), "".join([ self.assertEqual(quopri.decodestring(htmlmessage.get_payload()).decode(), "".join([
"<p>Hello</p>", "<p>Hello</p>",
'<a href="https://a.a/">aa</a>', '<a href="https://a.a/">aa</a>',
'<a href="https://hel.lo/b">bb</a>', '<a href="https://hel.lo/b">bb</a>',
...@@ -1233,7 +1233,7 @@ return True ...@@ -1233,7 +1233,7 @@ return True
"quoted-printable", "quoted-printable",
) )
self.assertEqual(htmlmessage.get("Content-Location"), page.absolute_url()) self.assertEqual(htmlmessage.get("Content-Location"), page.absolute_url())
self.assertEqual(quopri.decodestring(htmlmessage.get_payload()), "<p>World</p>") self.assertEqual(quopri.decodestring(htmlmessage.get_payload()).decode(), "<p>World</p>")
def test_WebPageAsEmbeddedHtml_pageWithMoreThanOneImage(self): def test_WebPageAsEmbeddedHtml_pageWithMoreThanOneImage(self):
"""Test convert one html page with images to embedded html file""" """Test convert one html page with images to embedded html file"""
...@@ -1285,7 +1285,7 @@ return True ...@@ -1285,7 +1285,7 @@ return True
message = EmailParser().parsestr(mhtml_data) message = EmailParser().parsestr(mhtml_data)
htmlmessage, svgmessage, pngmessage, svgtopngmessage = message.get_payload() htmlmessage, svgmessage, pngmessage, svgtopngmessage = message.get_payload()
self.assertEqual( self.assertEqual(
quopri.decodestring(htmlmessage.get_payload()), quopri.decodestring(htmlmessage.get_payload()).decode(),
"".join([ "".join([
"<p>Hello</p>", "<p>Hello</p>",
'<img src="%s?format=" />' % svg.absolute_url(), '<img src="%s?format=" />' % svg.absolute_url(),
...@@ -1402,7 +1402,7 @@ return True ...@@ -1402,7 +1402,7 @@ return True
self.assertEqual(len(message.get_payload()), 7) self.assertEqual(len(message.get_payload()), 7)
htmlmessage = message.get_payload()[0] htmlmessage = message.get_payload()[0]
self.assertEqual( self.assertEqual(
quopri.decodestring(htmlmessage.get_payload()), quopri.decodestring(htmlmessage.get_payload()).decode(),
"".join([ "".join([
"<p>Hello</p>", "<p>Hello</p>",
'<img src="%s/%s?format=" />' % (page.absolute_url(), svg.getRelativeUrl()), '<img src="%s/%s?format=" />' % (page.absolute_url(), svg.getRelativeUrl()),
...@@ -1546,7 +1546,7 @@ return True ...@@ -1546,7 +1546,7 @@ return True
message = EmailParser().parsestr(mhtml_data) message = EmailParser().parsestr(mhtml_data)
htmlmessage, imagemessage = message.get_payload() htmlmessage, imagemessage = message.get_payload()
self.assertEqual( self.assertEqual(
quopri.decodestring(htmlmessage.get_payload()), quopri.decodestring(htmlmessage.get_payload()).decode(),
"<style>%s</style><p>Hello</p>" % ( "<style>%s</style><p>Hello</p>" % (
"body { background-image: url(%s?format=); }" % ( "body { background-image: url(%s?format=); }" % (
img.absolute_url())), img.absolute_url())),
......
...@@ -270,7 +270,7 @@ def handleLinkedData(mime, data, href): ...@@ -270,7 +270,7 @@ def handleLinkedData(mime, data, href):
"mime_type": mime, "mime_type": mime,
"encode": "quoted-printable" if mime.startswith("text/") else None, "encode": "quoted-printable" if mime.startswith("text/") else None,
"add_header_list": [("Content-Location", url)], "add_header_list": [("Content-Location", url)],
"data": str(data), "data": bytes(data),
}) })
return url return url
else: else:
...@@ -335,7 +335,7 @@ def replaceFromDataUri(data_uri, replacer): ...@@ -335,7 +335,7 @@ def replaceFromDataUri(data_uri, replacer):
data = b64decode(data) data = b64decode(data)
if not is_base64: if not is_base64:
data = replacer(data) data = replacer(data)
return "%s,%s" % (header, b64encode(data) if is_base64 else data) return "%s,%s" % (header, b64encode(data).decode() if is_base64 else data)
def extractUrlSearch(url): def extractUrlSearch(url):
url = url.split("#", 1)[0].split("?", 1) url = url.split("#", 1)[0].split("?", 1)
......
...@@ -80,7 +80,7 @@ def encode_quopri(msg): ...@@ -80,7 +80,7 @@ def encode_quopri(msg):
when necessary. when necessary.
""" """
orig = msg.get_payload() orig = msg.get_payload()
encdata = quopri.encodestring(orig.encode()).replace("=\n", "=\r\n") encdata = quopri.encodestring(orig.encode()).replace(b"=\n", b"=\r\n")
msg.set_payload(encdata) msg.set_payload(encdata)
msg.add_header("Content-Transfer-Encoding", "quoted-printable") msg.add_header("Content-Transfer-Encoding", "quoted-printable")
......
...@@ -42,7 +42,7 @@ class TestRenderJSPortalType(ERP5TypeTestCase): ...@@ -42,7 +42,7 @@ class TestRenderJSPortalType(ERP5TypeTestCase):
portal_type='Web Style', portal_type='Web Style',
reference='test_web_style.css' reference='test_web_style.css'
) )
web_style.setTextContent('/* cl\xc3\xa0sse */ .classe { background: red }') web_style.setTextContent(b'/* cl\xc3\xa0sse */ .classe { background: red }'.decode('utf-8'))
web_style.publish() web_style.publish()
self.tic() self.tic()
self.assertEqual('text/css', web_style.getContentType()) self.assertEqual('text/css', web_style.getContentType())
...@@ -52,7 +52,7 @@ class TestRenderJSPortalType(ERP5TypeTestCase): ...@@ -52,7 +52,7 @@ class TestRenderJSPortalType(ERP5TypeTestCase):
'%s/%s' % (self.web_site.getPath(), web_style.getReference()) '%s/%s' % (self.web_site.getPath(), web_style.getReference())
) )
self.assertEqual( self.assertEqual(
'/* cl\xc3\xa0sse */ .classe { background: red }', b'/* cl\xc3\xa0sse */ .classe { background: red }',
response.getBody() response.getBody()
) )
self.assertEqual( self.assertEqual(
...@@ -65,7 +65,7 @@ class TestRenderJSPortalType(ERP5TypeTestCase): ...@@ -65,7 +65,7 @@ class TestRenderJSPortalType(ERP5TypeTestCase):
portal_type='Web Script', portal_type='Web Script',
reference='test_web_script.js' reference='test_web_script.js'
) )
web_script.setTextContent('alert("h\xc3\xa9h\xc3\xa9")') web_script.setTextContent(b'alert("h\xc3\xa9h\xc3\xa9")'.decode('utf-8'))
web_script.publish() web_script.publish()
self.tic() self.tic()
self.assertEqual('application/javascript', web_script.getContentType()) self.assertEqual('application/javascript', web_script.getContentType())
...@@ -75,7 +75,7 @@ class TestRenderJSPortalType(ERP5TypeTestCase): ...@@ -75,7 +75,7 @@ class TestRenderJSPortalType(ERP5TypeTestCase):
'%s/%s' % (self.web_site.getPath(), web_script.getReference()) '%s/%s' % (self.web_site.getPath(), web_script.getReference())
) )
self.assertEqual( self.assertEqual(
'alert("h\xc3\xa9h\xc3\xa9")', b'alert("h\xc3\xa9h\xc3\xa9")',
response.getBody() response.getBody()
) )
self.assertEqual( self.assertEqual(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment