[Zope3-checkins] CVS: Zope3/src/zope/app/content - file.py:1.7 image.py:1.7
Steve Alexander
steve@cat-box.net
Mon, 14 Apr 2003 13:15:51 -0400
Update of /cvs-repository/Zope3/src/zope/app/content
In directory cvs.zope.org:/tmp/cvs-serv19670/src/zope/app/content
Modified Files:
file.py image.py
Log Message:
Made file and image implementations confirm to their schema.
The data field should never be None, as it must conform to a required
Bytes field.
See http://collector.zope.org/Zope3-dev/140
=== Zope3/src/zope/app/content/file.py 1.6 => 1.7 ===
--- Zope3/src/zope/app/content/file.py:1.6 Wed Mar 12 05:07:27 2003
+++ Zope3/src/zope/app/content/file.py Mon Apr 14 13:15:20 2003
@@ -79,20 +79,19 @@
size = len(data)
if size < MAXCHUNKSIZE:
self._data, self._size = FileChunk(data), size
- return None
+ return
self._data, self._size = FileChunk(data), size
- return None
+ return
# Handle case when data is None
if data is None:
- self._data, self._size = None, 0
- return None
+ raise TypeError('Cannot set None data on a file.')
# Handle case when data is already a FileChunk
if hasattr(data, '__class__') and data.__class__ is FileChunk:
size = len(data)
self._data, self._size = data, size
- return None
+ return
# Handle case when data is a file object
seek = data.seek
@@ -105,9 +104,9 @@
seek(0)
if size < MAXCHUNKSIZE:
self._data, self._size = read(size), size
- return None
+ return
self._data, self._size = FileChunk(read(size)), size
- return None
+ return
# Make sure we have an _p_jar, even if we are a new object, by
# doing a sub-transaction commit.
@@ -119,7 +118,7 @@
# Ugh
seek(0)
self._data, self._size = FileChunk(read(size)), size
- return None
+ return
# Now we're going to build a linked list from back
# to front to minimize the number of database updates
@@ -153,7 +152,7 @@
end = pos
self._data, self._size = next, size
- return None
+ return
def getSize(self):
'''See interface IFile'''
@@ -196,15 +195,12 @@
def __init__(self, data):
self._data = data
-
def __getslice__(self, i, j):
return self._data[i:j]
-
def __len__(self):
data = str(self)
return len(data)
-
def __str__(self):
next = self.next
=== Zope3/src/zope/app/content/image.py 1.6 => 1.7 ===
--- Zope3/src/zope/app/content/image.py:1.6 Wed Mar 12 05:05:08 2003
+++ Zope3/src/zope/app/content/image.py Mon Apr 14 13:15:20 2003
@@ -28,22 +28,18 @@
class Image(File):
__implements__ = IImage
- def __init__(self, data=None):
+ def __init__(self, data=''):
'''See interface IFile'''
self.contentType, self._width, self._height = getImageInfo(data)
self.data = data
-
def setData(self, data):
-
super(Image, self).setData(data)
- if data is not None:
- contentType = None
- contentType, self._width, self._height = getImageInfo(self.data)
- if contentType:
- self.contentType = contentType
-
+ contentType = None
+ contentType, self._width, self._height = getImageInfo(self.data)
+ if contentType:
+ self.contentType = contentType
def getImageSize(self):
'''See interface IImage'''