Commit 02f1a34a authored by Carlos Ramos Carreño's avatar Carlos Ramos Carreño Committed by Jérome Perrin

Fix TestCorporateIdentityTemplateList in Python 2.

Errors were being raised for returning `None` in Python 2
(due to a missing else branch) and for re-encoding bytes
in Python 2.

I changed the code to use str2bytes in the cases where bytes
are expected.
parent be4f29a0
......@@ -36,6 +36,7 @@ import re
import six
from Products.PythonScripts.standard import html_quote
from Products.ERP5Type.Utils import str2bytes
from base64 import b64encode
blank = ''
......@@ -359,22 +360,22 @@ elif book_format == "pdf":
)
# ================ encode and build cloudoo elements =========================
header_embedded_html_data = book.Base_convertHtmlToSingleFile(book_head, allow_script=True).encode('utf-8')
header_embedded_html_data = str2bytes(book.Base_convertHtmlToSingleFile(book_head, allow_script=True))
before_toc_data_list = [
b64encode(book.Base_convertHtmlToSingleFile(book_cover, allow_script=True).encode('utf-8')).decode(),
b64encode(str2bytes(book.Base_convertHtmlToSingleFile(book_cover, allow_script=True))).decode(),
]
after_toc_data_list = []
if book_include_history_table:
before_toc_data_list.append(
b64encode(book.Base_convertHtmlToSingleFile(book_history, allow_script=True).encode('utf-8')).decode()
b64encode(str2bytes(book.Base_convertHtmlToSingleFile(book_history, allow_script=True))).decode()
)
#if book_include_reference_table:
# after_toc_data_list.append(
# b64encode(book.Base_convertHtmlToSingleFile(book_references, allow_script=True).encode('utf-8')).decode()
# b64encode(str2bytes(book.Base_convertHtmlToSingleFile(book_references, allow_script=True))).decode()
# )
xsl_style_sheet_data = book_table_of_content.encode('utf-8')
embedded_html_data = book.Base_convertHtmlToSingleFile(book_content, allow_script=True).encode('utf-8')
footer_embedded_html_data = book.Base_convertHtmlToSingleFile(book_foot, allow_script=True).encode('utf-8')
embedded_html_data = str2bytes(book.Base_convertHtmlToSingleFile(book_content, allow_script=True))
footer_embedded_html_data = str2bytes(book.Base_convertHtmlToSingleFile(book_foot, allow_script=True))
if margin_15mm:
margin_top = 50
margin_bottom = 25
......
......@@ -28,6 +28,8 @@ mhtml_message = {
}
def main(data):
# type: (str) -> str
# Preserves input type (unicode or bytes)
if isinstance(data, bytes):
data = data.decode("utf-8")
data = u"".join([fn(p) for fn, p in handleHtmlPartList(parseHtml(data))])
......
......@@ -42,7 +42,7 @@ from string import Template
from erp5.component.mixin.CachedConvertableMixin import CachedConvertableMixin
from erp5.component.mixin.BaseConvertableFileMixin import BaseConvertableFileMixin
from Products.ERP5Type.mixin.text_content_history import TextContentHistoryMixin
from Products.ERP5Type.Utils import guessEncodingFromText, bytes2str
from Products.ERP5Type.Utils import guessEncodingFromText, bytes2str, str2bytes
from lxml import html as etree_html
from lxml import etree
......@@ -428,8 +428,7 @@ class TextDocument(CachedConvertableMixin, BaseConvertableFileMixin, TextContent
data = self._baseGetTextContent()
else:
data = self._baseGetTextContent(default)
if not isinstance(data, bytes):
return data.encode('utf-8')
return str2bytes(data)
else:
if default is _MARKER:
return File.getData(self)
......
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