Commit 946b9bca authored by Jérome Perrin's avatar Jérome Perrin

web: py3

parent c770ff41
......@@ -1257,8 +1257,8 @@ return True
ehtml_data = page.WebPage_exportAsSingleFile(format="embedded_html")
self.assertTrue(ehtml_data.startswith("".join([
"<p>Hello</p>",
'<img src="data:image/svg+xml;base64,%s" />' % b64encode(XSMALL_SVG_IMAGE_ICON_DATA),
'<img src="data:image/png;base64,%s" />' % b64encode(XSMALL_PNG_IMAGE_ICON_DATA),
'<img src="data:image/svg+xml;base64,%s" />' % b64encode(XSMALL_SVG_IMAGE_ICON_DATA).decode(),
'<img src="data:image/png;base64,%s" />' % b64encode(XSMALL_PNG_IMAGE_ICON_DATA).decode(),
'<img src="data:image/png;base64,'
])))
......@@ -1359,7 +1359,7 @@ return True
self.assertEqual(ehtml_data, "".join([
"<p>Hello</p>",
] + ([
'<img src="data:image/svg+xml;base64,%s" />' % b64encode(XSMALL_SVG_IMAGE_ICON_DATA),
'<img src="data:image/svg+xml;base64,%s" />' % b64encode(XSMALL_SVG_IMAGE_ICON_DATA).decode(),
] * 6) + [
'<img src="%s//example.com/%s?format=" />' % (protocol, svg.getRelativeUrl()),
'<img src="http://example.com/%s?format=" />' % svg.getRelativeUrl(),
......@@ -1524,7 +1524,7 @@ return True
ehtml_data,
"<style>%s</style><p>Hello</p>" % (
'body { background-image: url(data:image/svg+xml;base64,%s); }' % (
b64encode(XSMALL_SVG_IMAGE_ICON_DATA))),
b64encode(XSMALL_SVG_IMAGE_ICON_DATA).decode())),
)
def test_WebPageAsMhtml_pageWithStyle(self):
......
......@@ -140,4 +140,4 @@ if six.PY2:
else:
from html import unescape as html_unescape
def unescape(self, html):
return html_unescape(self, html)
return html_unescape(html)
......@@ -41,6 +41,7 @@ def main(data):
"data": data,
})
data = context.Base_formatAttachmentListToMIMEMultipartString(**mhtml_message)
return data
def handleHtmlTag(tag, attrs):
......@@ -179,22 +180,23 @@ def handleImageSourceObject(obj, src):
format_kw["display"] = str(value)
if format_kw:
mime, data = obj.convert(**format_kw)
return handleLinkedData(mime, str(data), src)
return handleLinkedData(mime, data, src)
return handleHrefObject(obj, src, default_mimetype=bad_image_mime_type, default_data=bad_image_data)
def handleHrefObject(obj, src, default_mimetype="text/html", default_data="<p>Linked page not found</p>"):
def handleHrefObject(obj, src, default_mimetype="text/html", default_data=b"<p>Linked page not found</p>"):
# handle File portal_skins/folder/file.png
# XXX handle "?portal_skin=" parameter ?
if hasattr(obj, "getContentType"):
mime = obj.getContentType()
if mime:
if hasattr(obj, "data"):
data = str(obj.data or "")
data = bytes(obj.data or b"")
else:
data = getattr(obj, "getData", lambda: str(obj))() or ""
data = getattr(obj, "getData", lambda: bytes(obj))() or b""
if six.PY2 and isinstance(data, unicode):
data = data.encode("utf-8")
assert isinstance(data, bytes)
return handleLinkedData(mime, data, src)
return handleLinkedData(default_mimetype, default_data, src)
......@@ -272,7 +274,11 @@ def handleLinkedData(mime, data, href):
})
return url
else:
return "data:%s;base64,%s" % (mime, b64encode(data.encode()).decode())
if isinstance(data, six.text_type):
data = data.encode('utf-8')
else:
data = bytes(data)
return "data:%s;base64,%s" % (mime, b64encode(data).decode())
def makeHrefAbsolute(href):
if isHrefAnAbsoluteUrl(href) or not isHrefAUrl(href):
......
......@@ -80,7 +80,7 @@ def encode_quopri(msg):
when necessary.
"""
orig = msg.get_payload()
encdata = quopri.encodestring(orig).replace("=\n", "=\r\n")
encdata = quopri.encodestring(orig.encode()).replace("=\n", "=\r\n")
msg.set_payload(encdata)
msg.add_header("Content-Transfer-Encoding", "quoted-printable")
......
# This script has 'Anonymous' proxy role to check 'View' permission for Anonymous.
return 'format' in context.REQUEST and context.getPortalObject().portal_membership.checkPermission('View', context)
if 'format' in container.REQUEST:
from zExceptions import Unauthorized
portal = context.getPortalObject()
try:
return portal.portal_membership.checkPermission(
'View', context)
except Unauthorized:
pass
return False
......@@ -9,7 +9,7 @@
image_conversion_arguments python: '&'.join(['%s=%s' % (k, v) for k, v in image_conversion_dict.items()]);
description python: here.getDescription();
box_relative_url python: request.get('box_relative_url', '');
dom_id python: modules['base64'].urlsafe_b64encode('%s-%s' %(box_relative_url, here.getUid())).rstrip('=')">
dom_id python: modules['base64'].urlsafe_b64encode(('%s-%s' %( box_relative_url, here.getUid())).encode()).decode().rstrip('=')">
<div class="document-gadget-quick-preview">
<div class="teaser"
tal:attributes="onclick string:$('#${dom_id}').toggle();">
......
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