Commit 1193ace5 authored by Jérome Perrin's avatar Jérome Perrin

web: py3

parent 4b016377
......@@ -134,10 +134,12 @@ def parseCssForUrl(text):
result.append(("data", data))
return result
# pylint:disable=no-name-in-module
if six.PY2:
def unescape(self, html):
return HTMLParser().unescape(html)
else:
from html import unescape as html_unescape
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):
"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