Commit 8aea5b39 authored by Julien Muchembled's avatar Julien Muchembled

File: clean up _setData

parent 403aba39
...@@ -36,7 +36,7 @@ from Products.ERP5.Document.Document import ConversionError ...@@ -36,7 +36,7 @@ from Products.ERP5.Document.Document import ConversionError
from Products.ERP5Type.Base import Base, removeIContentishInterface from Products.ERP5Type.Base import Base, removeIContentishInterface
from Products.CMFDefault.File import File as CMFFile from Products.CMFDefault.File import File as CMFFile
from OFS.Image import Pdata from OFS.Image import Pdata
import cStringIO from cStringIO import StringIO
from Products.ERP5Type.Utils import deprecated from Products.ERP5Type.Utils import deprecated
def _unpackData(data): def _unpackData(data):
...@@ -172,24 +172,15 @@ class File(Document, CMFFile): ...@@ -172,24 +172,15 @@ class File(Document, CMFFile):
def _setData(self, data): def _setData(self, data):
""" """
""" """
size = None
# update_data use len(data) when size is None, which breaks this method. # update_data use len(data) when size is None, which breaks this method.
# define size = 0 will prevent len be use and keep the consistency of # define size = 0 will prevent len be use and keep the consistency of
# getData() and setData() # getData() and setData()
if data is None: if data is None:
size = 0 size = 0
if not isinstance(data, Pdata) and data is not None:
file = cStringIO.StringIO(data)
data, size = self._read_data(file)
if getattr(self, 'update_data', None) is not None:
# We call this method to make sure size is set and caches reset
self.update_data(data, size=size)
else: else:
self._baseSetData(data) # XXX - It would be better to always use this accessor data, size = self._read_data(data)
self._setSize(size) # We call this method to make sure size is set and caches reset
self.ZCacheable_invalidate() self.update_data(data, size=size)
self.ZCacheable_set(None)
self.http__refreshEtag()
security.declareProtected(Permissions.AccessContentsInformation, 'getData') security.declareProtected(Permissions.AccessContentsInformation, 'getData')
def getData(self, default=None): def getData(self, default=None):
......
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