Commit fec1d133 authored by Jérome Perrin's avatar Jérome Perrin

ERP5OOo: py3

parent ce214637
......@@ -29,6 +29,7 @@
import re, zipfile
from io import BytesIO
import six
from warnings import warn
from AccessControl import ClassSecurityInfo
from OFS.Image import Pdata
......@@ -38,8 +39,8 @@ from Products.ERP5Type import Permissions, PropertySheet
from Products.ERP5Type.Cache import CachingMethod
from erp5.component.document.File import File
from erp5.component.document.Document import Document, \
VALID_IMAGE_FORMAT_LIST, ConversionError, NotConvertedError
from Products.ERP5Type.Utils import bytes2str, fill_args_from_request, str2bytes
VALID_IMAGE_FORMAT_LIST, VALID_TEXT_FORMAT_LIST, ConversionError, NotConvertedError
from Products.ERP5Type.Utils import guessEncodingFromText, bytes2str, fill_args_from_request, str2bytes
# Mixin Import
from erp5.component.mixin.BaseConvertableFileMixin import BaseConvertableFileMixin
......@@ -334,7 +335,14 @@ class OOoDocument(OOoDocumentExtensibleTraversableMixin, BaseConvertableFileMixi
# store conversion
self.setConversion(data, mime, format=original_format, **kw)
return self.getConversion(format=original_format, **kw)
mime, data = self.getConversion(format=original_format, **kw)
if format in VALID_TEXT_FORMAT_LIST:
# Libreoffice conversions on cloudooo usually have a BOM, we are using guessEncodingFromText
# here mostly as a convenient way to decode with the encoding from BOM
data = data.decode(guessEncodingFromText(data) or 'ascii')
if six.PY2:
data = data.encode('utf-8')
return mime, data
security.declareProtected(Permissions.ModifyPortalContent,
'_populateConversionCacheWithHTML')
......
......@@ -27,7 +27,7 @@ class OdtToDoc:
raise AttributeError(attr)
def convert(self, orig, data, cache=None, filename=None, context=None, **kwargs):
data = str(orig)
data = bytes(orig)
doc = OOOdCommandTransform(context, filename, data, self.inputs[0])
msword = doc.convertTo('doc')
if cache is not None:
......
......@@ -27,7 +27,7 @@ class OdtToPdf:
raise AttributeError(attr)
def convert(self, orig, data, cache=None, filename=None, context=None, **kwargs):
data = str(orig)
data = bytes(orig)
doc = OOOdCommandTransform(context, filename, data, self.inputs[0])
pdf = doc.convertTo('pdf')
if cache is not None:
......
......@@ -28,7 +28,7 @@ class OdtToXml:
raise AttributeError(attr)
def convert(self, orig, data, cache=None, filename=None, context=None, **kwargs):
data = str(orig)
data = bytes(orig)
doc = OOOdCommandTransform(context, filename, data, self.inputs[0])
builder = OOoBuilder(doc)
content = builder.extract('content.xml')
......
......@@ -143,7 +143,7 @@ class OOOdCommandTransform(commandtransform):
image = OFSImage(image.getId(), image.getTitle(), image_data)
# image should be OFSImage
data = str(image.data)
data = bytes(image.data)
width = image.width
height = image.height
if height:
......
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