Commit 7792bd1e authored by Jérome Perrin's avatar Jérome Perrin

web: py3

parent 8f034842
...@@ -1257,8 +1257,8 @@ return True ...@@ -1257,8 +1257,8 @@ return True
ehtml_data = page.WebPage_exportAsSingleFile(format="embedded_html") ehtml_data = page.WebPage_exportAsSingleFile(format="embedded_html")
self.assertTrue(ehtml_data.startswith("".join([ self.assertTrue(ehtml_data.startswith("".join([
"<p>Hello</p>", "<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(),
'<img src="data:image/png;base64,%s" />' % b64encode(XSMALL_PNG_IMAGE_ICON_DATA), '<img src="data:image/png;base64,%s" />' % b64encode(XSMALL_PNG_IMAGE_ICON_DATA).decode(),
'<img src="data:image/png;base64,' '<img src="data:image/png;base64,'
]))) ])))
...@@ -1359,7 +1359,7 @@ return True ...@@ -1359,7 +1359,7 @@ return True
self.assertEqual(ehtml_data, "".join([ self.assertEqual(ehtml_data, "".join([
"<p>Hello</p>", "<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) + [ ] * 6) + [
'<img src="%s//example.com/%s?format=" />' % (protocol, svg.getRelativeUrl()), '<img src="%s//example.com/%s?format=" />' % (protocol, svg.getRelativeUrl()),
'<img src="http://example.com/%s?format=" />' % svg.getRelativeUrl(), '<img src="http://example.com/%s?format=" />' % svg.getRelativeUrl(),
...@@ -1524,7 +1524,7 @@ return True ...@@ -1524,7 +1524,7 @@ return True
ehtml_data, ehtml_data,
"<style>%s</style><p>Hello</p>" % ( "<style>%s</style><p>Hello</p>" % (
'body { background-image: url(data:image/svg+xml;base64,%s); }' % ( '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): def test_WebPageAsMhtml_pageWithStyle(self):
......
...@@ -134,10 +134,12 @@ def parseCssForUrl(text): ...@@ -134,10 +134,12 @@ def parseCssForUrl(text):
result.append(("data", data)) result.append(("data", data))
return result return result
# pylint:disable=no-name-in-module
if six.PY2: if six.PY2:
def unescape(self, html): def unescape(self, html):
return HTMLParser().unescape(html) return HTMLParser().unescape(html)
else: else:
from html import unescape as html_unescape from html import unescape as html_unescape
def unescape(self, html): def unescape(self, html):
return html_unescape(self, html) return html_unescape(html)
# pylint:enable=no-name-in-module
...@@ -41,6 +41,7 @@ def main(data): ...@@ -41,6 +41,7 @@ def main(data):
"data": data, "data": data,
}) })
data = context.Base_formatAttachmentListToMIMEMultipartString(**mhtml_message) data = context.Base_formatAttachmentListToMIMEMultipartString(**mhtml_message)
return data return data
def handleHtmlTag(tag, attrs): def handleHtmlTag(tag, attrs):
...@@ -179,22 +180,23 @@ def handleImageSourceObject(obj, src): ...@@ -179,22 +180,23 @@ def handleImageSourceObject(obj, src):
format_kw["display"] = str(value) format_kw["display"] = str(value)
if format_kw: if format_kw:
mime, data = obj.convert(**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) 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 # handle File portal_skins/folder/file.png
# XXX handle "?portal_skin=" parameter ? # XXX handle "?portal_skin=" parameter ?
if hasattr(obj, "getContentType"): if hasattr(obj, "getContentType"):
mime = obj.getContentType() mime = obj.getContentType()
if mime: if mime:
if hasattr(obj, "data"): if hasattr(obj, "data"):
data = str(obj.data or "") data = bytes(obj.data or b"")
else: 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): if six.PY2 and isinstance(data, unicode):
data = data.encode("utf-8") data = data.encode("utf-8")
assert isinstance(data, bytes)
return handleLinkedData(mime, data, src) return handleLinkedData(mime, data, src)
return handleLinkedData(default_mimetype, default_data, src) return handleLinkedData(default_mimetype, default_data, src)
...@@ -272,7 +274,11 @@ def handleLinkedData(mime, data, href): ...@@ -272,7 +274,11 @@ def handleLinkedData(mime, data, href):
}) })
return url return url
else: 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): def makeHrefAbsolute(href):
if isHrefAnAbsoluteUrl(href) or not isHrefAUrl(href): if isHrefAnAbsoluteUrl(href) or not isHrefAUrl(href):
......
...@@ -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).replace("=\n", "=\r\n") encdata = quopri.encodestring(orig.encode()).replace("=\n", "=\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")
......
# This script has 'Anonymous' proxy role to check 'View' permission for Anonymous. # 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 @@ ...@@ -9,7 +9,7 @@
image_conversion_arguments python: '&'.join(['%s=%s' % (k, v) for k, v in image_conversion_dict.items()]); image_conversion_arguments python: '&'.join(['%s=%s' % (k, v) for k, v in image_conversion_dict.items()]);
description python: here.getDescription(); description python: here.getDescription();
box_relative_url python: request.get('box_relative_url', ''); 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="document-gadget-quick-preview">
<div class="teaser" <div class="teaser"
tal:attributes="onclick string:$('#${dom_id}').toggle();"> 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