Commit fa4bd88e authored by Emmy Vouriot's avatar Emmy Vouriot Committed by Jérome Perrin

str to bytes WIP

parent 4492b4fa
......@@ -32,7 +32,7 @@ import zope.interface
from AccessControl import ClassSecurityInfo
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.document.Image import Image
from erp5.component.document.Document import ConversionError
......@@ -291,10 +291,10 @@ class PDFDocument(Image):
finally:
tmp.close()
# 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
h = h.replace('href="%s.html' % tmp.name.split(os.sep)[-1],
'href="asEntireHTML')
h = h.replace(str2bytes('href="%s.html' % tmp.name.split(os.sep)[-1]),
b'href="asEntireHTML')
return h
security.declarePrivate('_convertToDJVU')
......
......@@ -28,6 +28,7 @@
##############################################################################
import re
import six
from DateTime import DateTime
from AccessControl import ClassSecurityInfo
from Products.ERP5Type.Accessor.Constant import PropertyGetter as ConstantGetter
......@@ -47,7 +48,10 @@ except ImportError:
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
DEFAULT_TEXT_FORMAT = 'text/html'
......@@ -170,7 +174,7 @@ class EmailDocument(TextDocument, MailMessageMixin):
content_type=self.getContentType(),
embedded_file_list=self.getAggregateValueList(portal_type=document_type_list),
)
result = message_from_string(data)
result = message_from_x(data)
self._v_message = result
return result
......
......@@ -35,6 +35,7 @@ from zLOG import LOG, INFO
from email.header import decode_header, HeaderParseError
import re
import six
filename_regexp = 'name="([^"]*)"'
......@@ -43,7 +44,8 @@ def testCharsetAndConvert(text_content, content_type, encoding):
if encoding is not None:
text_content = text_content.decode(encoding).encode('utf-8')
else:
text_content = text_content.decode().encode('utf-8')
if six.PY2:
text_content = text_content.decode().encode('utf-8')
except (UnicodeDecodeError, LookupError):
encoding = guessEncodingFromText(text_content, content_type)
if encoding is not None:
......
......@@ -37,7 +37,7 @@ from lxml import etree
from AccessControl.SecurityManagement import newSecurityManager
from AccessControl import Unauthorized
from DateTime import DateTime
from Products.ERP5Type.Utils import convertToUpperCase
from Products.ERP5Type.Utils import convertToUpperCase, str2bytes
from Products.ERP5Type.tests.ERP5TypeTestCase import (
ERP5TypeTestCase, _getConversionServerUrlList)
from Products.CMFCore.WorkflowCore import WorkflowException
......@@ -1952,7 +1952,7 @@ return result
module = self.portal.document_module
document = module.newContent(portal_type='File',
property_which_doesnot_exists='Foo',
data='Hello World!',
data=b'Hello World!',
filename='toto.txt')
document.publish()
self.tic()
......@@ -1967,7 +1967,7 @@ return result
self.assertEqual(new_doc.getTitle(), 'One title')
self.assertEqual(new_doc.getReference(), 'EFAA')
self.assertEqual(new_doc.getValidationState(), 'published')
self.assertEqual(new_doc.getData(), 'Hello World!')
self.assertEqual(new_doc.getData(), b'Hello World!')
# Migrate a document with url property
url = new_doc.absolute_url() + '/getData'
......@@ -1979,7 +1979,7 @@ return result
new_doc = document.migratePortalType('File')
self.assertEqual(new_doc.getPortalType(), 'File')
self.assertEqual(new_doc.asURL(), url)
self.assertEqual(new_doc.getData(), 'Hello World!')
self.assertEqual(new_doc.getData(), b'Hello World!')
self.assertEqual(new_doc.getValidationState(), 'submitted')
def test_ContributionTool_isURLIngestionPermitted(self):
......@@ -2067,14 +2067,14 @@ return result
uri = '%(protocol)s://%(hostname)s' % url_dict
push_url = '%s%s/newContent' % (uri, self.portal.portal_contributions.getPath(),)
request = six.moves.urllib.request.Request(push_url, six.moves.urllib.parse.urlencode(
request = six.moves.urllib.request.Request(push_url, str2bytes(six.moves.urllib.parse.urlencode(
{'data': data,
'filename': filename,
'reference': reference,
'disable_cookie_login__': 1,
}), headers={
})), headers={
'Authorization': 'Basic %s' %
base64.b64encode('ERP5TypeTestCase:')
base64.b64encode(b'ERP5TypeTestCase:')
})
# disable_cookie_login__ is required to force zope to raise Unauthorized (401)
# then HTTPDigestAuthHandler can perform HTTP Authentication
......
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