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