Commit 83635909 authored by Aurel's avatar Aurel

fixup! Get rid of Products.CMFDefault.{File.File,Portal.CMFSite}

See commit 12e4cc8b.

File._setFile does not support that 'data' is a bytes object:
it crashes if there are already data stored on the object.
test_PUT_on_web_page (erp5_dms:testWebDavSupport) is changed to cover
this case and the caller of File._edit is fixed to make that 'file'
is always a file-like object.

File._setFile is also optimized to avoid reading data for nothing
if the document has no data.
parent 1c613aeb
...@@ -186,12 +186,14 @@ class TestWebDavSupport(ERP5TypeTestCase): ...@@ -186,12 +186,14 @@ class TestWebDavSupport(ERP5TypeTestCase):
""" """
iso_text_content = text_content.decode('utf-8').encode('iso-8859-1') iso_text_content = text_content.decode('utf-8').encode('iso-8859-1')
path = web_page_module.getPath() path = web_page_module.getPath()
response = self.publish('%s/%s' % (path, filename), for _ in xrange(2): # Run twice to check the code that compares
request_method='PUT', # old & new data when setting file attribute.
stdin=StringIO(iso_text_content), response = self.publish('%s/%s' % (path, filename),
basic=self.authentication) request_method='PUT',
self.assertEqual(response.getStatus(), httplib.NO_CONTENT) stdin=StringIO(iso_text_content),
self.assertEqual(web_page_module[filename].getData(), iso_text_content) basic=self.authentication)
self.assertEqual(response.getStatus(), httplib.NO_CONTENT)
self.assertEqual(web_page_module[filename].getData(), iso_text_content)
# Convert to base format and run conversion into utf-8 # Convert to base format and run conversion into utf-8
self.tic() self.tic()
# Content-Type header is replaced if sonversion encoding succeed # Content-Type header is replaced if sonversion encoding succeed
......
...@@ -36,6 +36,7 @@ from erp5.component.document.Document import ConversionError ...@@ -36,6 +36,7 @@ from erp5.component.document.Document import ConversionError
from Products.ERP5Type.Base import Base, removeIContentishInterface from Products.ERP5Type.Base import Base, removeIContentishInterface
from OFS.Image import File as OFS_File from OFS.Image import File as OFS_File
from Products.ERP5Type.Utils import deprecated from Products.ERP5Type.Utils import deprecated
from cStringIO import StringIO
def _unpackData(data): def _unpackData(data):
""" """
...@@ -146,9 +147,12 @@ class File(Document, OFS_File): ...@@ -146,9 +147,12 @@ class File(Document, OFS_File):
def _setFile(self, data, precondition=None): def _setFile(self, data, precondition=None):
if data is None: if data is None:
return return
if str(data.read()) == (self.hasData() and str(self.getData())): if self.hasData():
# Same data as previous, no need to change its content if str(data.read()) == str(self.getData()):
return # Same data as previous, no need to change its content
return
else:
data.seek(0, 2)
if data.tell(): if data.tell():
data.seek(0) data.seek(0)
......
...@@ -23,6 +23,7 @@ from Products.ERP5Type.Globals import InitializeClass ...@@ -23,6 +23,7 @@ from Products.ERP5Type.Globals import InitializeClass
from Products.ERP5Type import Permissions from Products.ERP5Type import Permissions
from Products.CMFCore.PortalContent import ResourceLockedError from Products.CMFCore.PortalContent import ResourceLockedError
from zExceptions import Forbidden from zExceptions import Forbidden
from cStringIO import StringIO
security = ModuleSecurityInfo(__name__) security = ModuleSecurityInfo(__name__)
...@@ -76,7 +77,7 @@ class TextContent: ...@@ -76,7 +77,7 @@ class TextContent:
headers = self.parseHeadersFromText(body) headers = self.parseHeadersFromText(body)
content_type = REQUEST.get_header('Content-Type', '') content_type = REQUEST.get_header('Content-Type', '')
headers.setdefault('content_type', content_type) headers.setdefault('content_type', content_type)
headers['file'] = body headers['file'] = StringIO(body)
self._edit(**headers) self._edit(**headers)
except ResourceLockedError: except ResourceLockedError:
transaction.abort() transaction.abort()
......
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