Commit 61934eef authored by Jérome Perrin's avatar Jérome Perrin

web: py3 WIP

parent 792bbf91
......@@ -1130,7 +1130,7 @@ return True
"quoted-printable",
)
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):
"""Test convert one html page with links to embedded html file"""
......@@ -1184,7 +1184,7 @@ return True
"quoted-printable",
)
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>",
'<a href="%s//a.a/">aa</a>' % self.portal.absolute_url().split("/", 1)[0],
'<a href="%s/b">bb</a>' % self.portal.absolute_url(),
......@@ -1194,7 +1194,7 @@ return True
message = EmailParser().parsestr(mhtml_data)
htmlmessage, = message.get_payload()
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>",
'<a href="https://a.a/">aa</a>',
'<a href="https://hel.lo/b">bb</a>',
......@@ -1233,7 +1233,7 @@ return True
"quoted-printable",
)
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):
"""Test convert one html page with images to embedded html file"""
......@@ -1285,7 +1285,7 @@ return True
message = EmailParser().parsestr(mhtml_data)
htmlmessage, svgmessage, pngmessage, svgtopngmessage = message.get_payload()
self.assertEqual(
quopri.decodestring(htmlmessage.get_payload()),
quopri.decodestring(htmlmessage.get_payload()).decode(),
"".join([
"<p>Hello</p>",
'<img src="%s?format=" />' % svg.absolute_url(),
......@@ -1402,7 +1402,7 @@ return True
self.assertEqual(len(message.get_payload()), 7)
htmlmessage = message.get_payload()[0]
self.assertEqual(
quopri.decodestring(htmlmessage.get_payload()),
quopri.decodestring(htmlmessage.get_payload()).decode(),
"".join([
"<p>Hello</p>",
'<img src="%s/%s?format=" />' % (page.absolute_url(), svg.getRelativeUrl()),
......@@ -1546,7 +1546,7 @@ return True
message = EmailParser().parsestr(mhtml_data)
htmlmessage, imagemessage = message.get_payload()
self.assertEqual(
quopri.decodestring(htmlmessage.get_payload()),
quopri.decodestring(htmlmessage.get_payload()).decode(),
"<style>%s</style><p>Hello</p>" % (
"body { background-image: url(%s?format=); }" % (
img.absolute_url())),
......
......@@ -270,7 +270,7 @@ def handleLinkedData(mime, data, href):
"mime_type": mime,
"encode": "quoted-printable" if mime.startswith("text/") else None,
"add_header_list": [("Content-Location", url)],
"data": str(data),
"data": bytes(data),
})
return url
else:
......@@ -335,7 +335,7 @@ def replaceFromDataUri(data_uri, replacer):
data = b64decode(data)
if not is_base64:
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):
url = url.split("#", 1)[0].split("?", 1)
......
......@@ -80,7 +80,7 @@ def encode_quopri(msg):
when necessary.
"""
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.add_header("Content-Transfer-Encoding", "quoted-printable")
......
......@@ -42,7 +42,7 @@ class TestRenderJSPortalType(ERP5TypeTestCase):
portal_type='Web Style',
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()
self.tic()
self.assertEqual('text/css', web_style.getContentType())
......@@ -52,7 +52,7 @@ class TestRenderJSPortalType(ERP5TypeTestCase):
'%s/%s' % (self.web_site.getPath(), web_style.getReference())
)
self.assertEqual(
'/* cl\xc3\xa0sse */ .classe { background: red }',
b'/* cl\xc3\xa0sse */ .classe { background: red }',
response.getBody()
)
self.assertEqual(
......@@ -65,7 +65,7 @@ class TestRenderJSPortalType(ERP5TypeTestCase):
portal_type='Web Script',
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()
self.tic()
self.assertEqual('application/javascript', web_script.getContentType())
......@@ -75,7 +75,7 @@ class TestRenderJSPortalType(ERP5TypeTestCase):
'%s/%s' % (self.web_site.getPath(), web_script.getReference())
)
self.assertEqual(
'alert("h\xc3\xa9h\xc3\xa9")',
b'alert("h\xc3\xa9h\xc3\xa9")',
response.getBody()
)
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