Commit 6d2f9a37 authored by Jérome Perrin's avatar Jérome Perrin Committed by Arnaud Fontaine

py3: cloudooo.git/d4abf3ff: convertFile() take an str() and returns an str().

parent adab0ee8
......@@ -3,6 +3,7 @@
from Products.PortalTransforms.interfaces import ITransform
from zope.interface import implementer
from erp5.component.document.Document import DocumentConversionServerProxy, ConversionError, enc, dec
from Products.ERP5Type.Utils import bytes2str, str2bytes
@implementer(ITransform)
class DocumentConversionServerTransform:
"""
......@@ -51,13 +52,13 @@ class DocumentConversionServerTransform:
source_format = self._getFormatFromMimetype(source_mimetype)
destination_format = self._getFormatFromMimetype(self.output)
data.setData(dec(server_proxy.convertFile(
enc(orig),
data.setData(dec(str2bytes(server_proxy.convertFile(
bytes2str(enc(orig)),
source_format,
destination_format,
# Default values are ConversionServer default ones
kwargs.get('zip', False),
kwargs.get('refresh', False),
kwargs.get('conversion_kw', {}))))
kwargs.get('conversion_kw', {})))))
return data
\ No newline at end of file
......@@ -31,6 +31,7 @@
from erp5.component.document.Document import DocumentConversionServerProxy
from base64 import b64encode, b64decode
from zExceptions import Unauthorized
from Products.ERP5Type.Utils import bytes2str
def convertDocumentByConversionServer(
self,
......@@ -48,7 +49,7 @@ def convertDocumentByConversionServer(
proxy = DocumentConversionServerProxy(self)
return b64decode(
proxy.convertFile(
b64encode(data),
bytes2str(b64encode(data)),
source_mimetype,
destination_mimetype,
zip,
......
# -*- coding: utf-8 -*-
import six
from Products.PortalTransforms.interfaces import ITransform
from zope.interface import implementer
from erp5.component.module.TransformLib import DocumentConversionServerTransform
......@@ -19,11 +20,13 @@ class TransformHtmlToPdf(DocumentConversionServerTransform):
# (https://lab.nexedi.com/nexedi/cloudooo/merge_requests/20)
return 'html' if mimetype == 'text/html' else 'pdf'
def convert(self, *args, **kwargs):
def convert(self, orig, *args, **kwargs):
# wkhtmltopdf handler currently requires conversion_kw (hack in convertFile())...
if 'conversion_kw' not in kwargs:
kwargs['conversion_kw'] = {'encoding': 'utf-8'}
return DocumentConversionServerTransform.convert(self, *args, **kwargs)
if six.PY3 and isinstance(orig, str):
orig = orig.encode()
return DocumentConversionServerTransform.convert(self, orig, *args, **kwargs)
def register():
return TransformHtmlToPdf()
\ No newline at end of file
......@@ -218,6 +218,8 @@ class MailMessageMixin:
encoding=part_encoding,
index=index) # add index to generate
# a unique cache key per attachment
if six.PY3:
content = content.encode()
else:
content = part.get_payload(decode=1)
return content
......
......@@ -228,11 +228,11 @@ class OOOdCommandTransform(commandtransform):
response_code, response_dict, message = server_proxy.run_generate(
'',
enc(self.data),
enc(self.data).decode(),
None,
format,
self.mimetype)
data = dec(response_dict['data'])
data = dec(response_dict['data'].encode())
if self.mimetype == 'text/html':
data = self.includeImageList(data)
return data
......
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