Commit 66129a6e authored by Emmy Vouriot's avatar Emmy Vouriot Committed by Arnaud Fontaine

str to bytes WIP

parent 720719dd
...@@ -32,7 +32,7 @@ import zope.interface ...@@ -32,7 +32,7 @@ import zope.interface
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions, PropertySheet from Products.ERP5Type import Permissions, PropertySheet
from Products.ERP5Type.Utils import bytes2str from Products.ERP5Type.Utils import bytes2str, str2bytes
from erp5.component.interface.IWatermarkable import IWatermarkable from erp5.component.interface.IWatermarkable import IWatermarkable
from erp5.component.document.Image import Image from erp5.component.document.Image import Image
from erp5.component.document.Document import ConversionError from erp5.component.document.Document import ConversionError
...@@ -291,10 +291,10 @@ class PDFDocument(Image): ...@@ -291,10 +291,10 @@ class PDFDocument(Image):
finally: finally:
tmp.close() tmp.close()
# Quick hack to remove bg color - XXX # Quick hack to remove bg color - XXX
h = command_result.replace('<BODY bgcolor="#A0A0A0"', '<BODY ') h = command_result.replace(b'<BODY bgcolor="#A0A0A0"', b'<BODY ')
# Make links relative # Make links relative
h = h.replace('href="%s.html' % tmp.name.split(os.sep)[-1], h = h.replace(str2bytes('href="%s.html' % tmp.name.split(os.sep)[-1]),
'href="asEntireHTML') b'href="asEntireHTML')
return h return h
security.declarePrivate('_convertToDJVU') security.declarePrivate('_convertToDJVU')
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
############################################################################## ##############################################################################
import re import re
import six
from DateTime import DateTime from DateTime import DateTime
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Products.ERP5Type.Accessor.Constant import PropertyGetter as ConstantGetter from Products.ERP5Type.Accessor.Constant import PropertyGetter as ConstantGetter
...@@ -47,7 +48,10 @@ except ImportError: ...@@ -47,7 +48,10 @@ except ImportError:
not installed yet. not installed yet.
""" """
from email import message_from_string if six.PY2:
from email import message_from_string as message_from_x
else:
from email import message_from_bytes as message_from_x
from email.utils import parsedate_tz, mktime_tz from email.utils import parsedate_tz, mktime_tz
DEFAULT_TEXT_FORMAT = 'text/html' DEFAULT_TEXT_FORMAT = 'text/html'
...@@ -170,7 +174,7 @@ class EmailDocument(TextDocument, MailMessageMixin): ...@@ -170,7 +174,7 @@ class EmailDocument(TextDocument, MailMessageMixin):
content_type=self.getContentType(), content_type=self.getContentType(),
embedded_file_list=self.getAggregateValueList(portal_type=document_type_list), embedded_file_list=self.getAggregateValueList(portal_type=document_type_list),
) )
result = message_from_string(data) result = message_from_x(data)
self._v_message = result self._v_message = result
return result return result
......
...@@ -35,6 +35,7 @@ from zLOG import LOG, INFO ...@@ -35,6 +35,7 @@ from zLOG import LOG, INFO
from email.header import decode_header, HeaderParseError from email.header import decode_header, HeaderParseError
import re import re
import six
filename_regexp = 'name="([^"]*)"' filename_regexp = 'name="([^"]*)"'
...@@ -43,6 +44,7 @@ def testCharsetAndConvert(text_content, content_type, encoding): ...@@ -43,6 +44,7 @@ def testCharsetAndConvert(text_content, content_type, encoding):
if encoding is not None: if encoding is not None:
text_content = text_content.decode(encoding).encode('utf-8') text_content = text_content.decode(encoding).encode('utf-8')
else: else:
if six.PY2:
text_content = text_content.decode().encode('utf-8') text_content = text_content.decode().encode('utf-8')
except (UnicodeDecodeError, LookupError): except (UnicodeDecodeError, LookupError):
encoding = guessEncodingFromText(text_content, content_type) encoding = guessEncodingFromText(text_content, content_type)
......
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