Commit 5ee2ccb8 authored by Jérome Perrin's avatar Jérome Perrin Committed by Arnaud Fontaine

File: treat data as bytes, not str

parent 268fdaf6
......@@ -589,8 +589,8 @@ class TestDocument(TestDocumentMixin):
def testTempOOoDocument_get_size(self):
# test get_size on temporary OOoDocument
doc = self.portal.newContent(temp_object=True, portal_type='OOo Document', id='tmp')
doc.edit(data='OOo')
self.assertEqual(len('OOo'), doc.get_size())
doc.edit(data=b'OOo')
self.assertEqual(len(b'OOo'), doc.get_size())
def testOOoDocument_hasData(self):
# test hasData on OOoDocument
......@@ -1279,7 +1279,7 @@ class TestDocument(TestDocumentMixin):
display='thumbnail')
self.assertEqual(mime, 'image/png')
# it's a valid PNG
self.assertEqual(image_data[1:4], 'PNG')
self.assertEqual(image_data[1:4], b'PNG')
def test_PDFToJpg(self):
upload_file = makeFileUpload('REF-en-001.pdf')
......@@ -1290,7 +1290,7 @@ class TestDocument(TestDocumentMixin):
frame=0,
display='thumbnail')
self.assertEqual(mime, 'image/jpeg')
self.assertEqual(image_data[6:10], 'JFIF')
self.assertEqual(image_data[6:10], b'JFIF')
def test_PDFToGif(self):
upload_file = makeFileUpload('REF-en-001.pdf')
......@@ -1301,7 +1301,7 @@ class TestDocument(TestDocumentMixin):
frame=0,
display='thumbnail')
self.assertEqual(mime, 'image/gif')
self.assertEqual(image_data[0:4], 'GIF8')
self.assertEqual(image_data[0:4], b'GIF8')
def test_PDFToTiff(self):
upload_file = makeFileUpload('REF-en-001.pdf')
......@@ -1312,7 +1312,7 @@ class TestDocument(TestDocumentMixin):
frame=0,
display='thumbnail')
self.assertEqual(mime, 'image/tiff')
self.assertIn(image_data[0:2], ('II', 'MM'))
self.assertIn(image_data[0:2], (b'II', b'MM'))
def test_PDF_content_information(self):
......
......@@ -38,13 +38,6 @@ from OFS.Image import File as OFS_File
from Products.ERP5Type.Utils import deprecated
def _unpackData(data):
"""
Unpack Pdata into string
OBSOLETED. use str(data) instead, because Pdata.__str__ is defined.
"""
return str(data)
_MARKER = object()
class File(Document, OFS_File):
......@@ -147,7 +140,7 @@ class File(Document, OFS_File):
if data is None:
return
if self.hasData():
if str(data.read()) == str(self.getData()):
if bytes(data.read()) == bytes(self.getData()):
# Same data as previous, no need to change its content
return
else:
......@@ -180,13 +173,13 @@ class File(Document, OFS_File):
security.declareProtected(Permissions.AccessContentsInformation, 'getData')
def getData(self, default=None):
"""return Data as str."""
"""return Data as bytes."""
self._checkConversionFormatPermission(None)
data = self._baseGetData()
if data is None:
return None
else:
return str(data)
return bytes(data)
# DAV Support
security.declareProtected(Permissions.ModifyPortalContent, 'PUT')
......@@ -226,8 +219,8 @@ class File(Document, OFS_File):
elif getattr(self, 'getBaseData', None) is not None:
content = self.getBaseData()
if content and not isinstance(content, str):
content = str(content)
if content and not isinstance(content, bytes):
content = bytes(content)
return (mime_type, content)
......
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