Commit 4aab9681 authored by Jérome Perrin's avatar Jérome Perrin

ERP5OOo: py3

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