Commit 1e60e0d1 authored by 's avatar

Added Pdata to keep big blobs out of memory until needed

parent e9447a6b
"""Image object""" """Image object"""
__version__='$Revision: 1.27 $'[11:-2] __version__='$Revision: 1.28 $'[11:-2]
import Globals import Globals
from Globals import HTMLFile, MessageDialog from Globals import HTMLFile, MessageDialog
...@@ -10,6 +10,22 @@ from Persistence import Persistent ...@@ -10,6 +10,22 @@ from Persistence import Persistent
from Acquisition import Implicit from Acquisition import Implicit
class Pdata(Persistent, Implicit):
# Wrapper for possibly large data
def __init__(self, data):
self.data=data
def __str__(self):
return self.data
def __len__(self):
return len(self.data)
class File(Persistent,Implicit,RoleManager,Item_w__name__): class File(Persistent,Implicit,RoleManager,Item_w__name__):
""" """ """ """
meta_type='File' meta_type='File'
...@@ -49,12 +65,13 @@ class File(Persistent,Implicit,RoleManager,Item_w__name__): ...@@ -49,12 +65,13 @@ class File(Persistent,Implicit,RoleManager,Item_w__name__):
if not content_type: if not content_type:
raise 'BadValue', 'No content type specified' raise 'BadValue', 'No content type specified'
self.content_type=content_type self.content_type=content_type
self.data=file self.data=Pdata(file)
else: else:
self.content_type=headers['content-type'] self.content_type=headers['content-type']
self.data=file.read() self.data=Pdata(file.read())
self.__name__=id self.__name__=id
self.title=title self.title=title
self.size=len(self.data)
def id(self): return self.__name__ def id(self): return self.__name__
...@@ -74,11 +91,10 @@ class File(Persistent,Implicit,RoleManager,Item_w__name__): ...@@ -74,11 +91,10 @@ class File(Persistent,Implicit,RoleManager,Item_w__name__):
def manage_upload(self,file='',REQUEST=None): def manage_upload(self,file='',REQUEST=None):
""" """ """ """
headers=file.headers self.content_type=file.headers['content-type']
data=file.read() data=file.read()
content_type=headers['content-type'] self.data=Pdata(data)
self.data=data self.size=len(data)
self.content_type=content_type
if REQUEST: return MessageDialog( if REQUEST: return MessageDialog(
title ='Success!', title ='Success!',
message='Your changes have been saved', message='Your changes have been saved',
...@@ -87,16 +103,18 @@ class File(Persistent,Implicit,RoleManager,Item_w__name__): ...@@ -87,16 +103,18 @@ class File(Persistent,Implicit,RoleManager,Item_w__name__):
PUT__roles__=['Manager'] PUT__roles__=['Manager']
def PUT(self, BODY, REQUEST): def PUT(self, BODY, REQUEST):
'handle PUT requests' 'handle PUT requests'
self.data=BODY self.data=Pdata(BODY)
self.size=len(BODY)
try: try:
type=REQUEST['CONTENT_TYPE'] type=REQUEST['CONTENT_TYPE']
if type: self.content_type=type if type: self.content_type=type
except KeyError: pass except KeyError: pass
def __str__(self): return self.data def size(self): return len(self.data)
def __str__(self): return str(self.data)
def __len__(self): return 1 def __len__(self): return 1
def size(self): return len(self.data)
class Image(File): class Image(File):
......
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