File contents
--- ExtFile.py.orig Fri Nov 30 00:25:32 2001
+++ ExtFile.py Thu Jan 10 23:18:20 2002
@@ -60,8 +60,7 @@
from DateTime import DateTime
import urllib, os, types, string
from os.path import join, isfile
-try: from cStringIO import StringIO
-except: from StringIO import StringIO
+import tempfile
FLAT = 0
SYNC_ZODB = 1
@@ -226,8 +225,7 @@
if (preview and not has_preview): icon = 1
if icon:
- filename = join(SOFTWARE_HOME, 'Products',
- 'ExtFile', self.getIconPath())
+ filename = join(Globals.package_home(globals()), self.getIconPath())
content_type = 'image/gif'
elif preview:
filename = self._get_filename(self.prev_filename)
@@ -241,13 +239,12 @@
if isfile(filename):
size = os.stat(filename)[6] # file size
else:
- filename = join(SOFTWARE_HOME, 'Products',
- 'ExtFile', 'icons', 'broken.gif')
+ filename = join(Globals.package_home(globals()), 'icons', 'broken.gif')
try: size = os.stat(filename)[6]
except: raise cant_read_exc, ("%s (%s)" %(self.id, filename))
content_type = 'image/gif'
icon = 1
- data = StringIO()
+ data = tempfile.TemporaryFile()
if icon==0 and width is not None and height is not None:
try:
from PIL import Image
@@ -270,7 +267,17 @@
REQUEST.RESPONSE.setHeader('Last-Modified', last_mod)
REQUEST.RESPONSE.setHeader('Content-Type', content_type)
REQUEST.RESPONSE.setHeader('Content-Length', size)
- return data.getvalue()
+ chunk = 1 << 18
+ data.seek(0)
+ if REQUEST is not None:
+ while 1:
+ buffer = data.read(chunk)
+ REQUEST.RESPONSE.write(buffer)
+ if len(buffer) < chunk:
+ break
+ return ''
+ else:
+ return data.read()
def view_image_or_file(self):
""" The default view of the contents of the File or Image. """
@@ -408,7 +415,12 @@
self.dav__init(REQUEST, RESPONSE)
content_type = REQUEST.get_header('content-type', None)
instream = REQUEST['BODYFILE']
- new_fn = self._get_ufn(self.filename)
+ # XXX: creating the disk file will fail without a proper
+ # path. however, absolute_url() does not work here,
+ # as we are not yet seated. as a workaround we
+ # introduce the path parameter to pass the location
+ # explicitly. also see the _get_new_ufn() method.
+ new_fn = self._get_ufn(self.filename, path=REQUEST.steps[:-2])
self._copy(instream, self._get_filename(new_fn))
try:
self.content_type = self._get_content_type(instream,
@@ -537,12 +549,12 @@
path = join(path,filename)
return path
- def _get_ufn(self, filename):
+ def _get_ufn(self, filename, path=None):
""" If no unique filename has been generated, generate one
otherwise, return the existing one.
"""
if UNDO_POLICY==ALWAYS_BACKUP or filename==[]:
- new_fn = self._get_new_ufn()
+ new_fn = self._get_new_ufn(path=path)
else:
new_fn = filename[:]
if filename:
@@ -555,9 +567,14 @@
except: pass
return new_fn
- def _get_new_ufn(self):
+ def _get_new_ufn(self, path=None):
""" Create a new unique filename """
- rel_url_list = string.split(self.absolute_url(1), '/')[:-1]
+ # XXX: absolute_url() does not work inside a PUT factory
+ # so we pass in the path. also see the PUT() method.
+ if path is not None:
+ rel_url_list = path
+ else:
+ rel_url_list = string.split(self.absolute_url(1), '/')[:-1]
rel_url_list = filter(None, rel_url_list)
pos = string.rfind(self.id, '.')
if (pos+1):
--- ExtImage.py.orig Thu Jan 10 20:54:00 2002
+++ ExtImage.py Thu Jan 10 23:17:24 2002
@@ -361,7 +361,7 @@
RESPONSE = ExtImage.inheritedAttribute("PUT")(self,REQUEST, RESPONSE)
if self.has_preview:
width, height = self._getImageSize(self.prev_filename)
- prev_filename = self._get_ufn()
+ prev_filename = self._get_ufn(path=REQUEST.steps[:-2])
self._createPreview(self.filename, prev_filename,
width, height, 0)
return RESPONSE
@@ -433,12 +433,12 @@
os.rename(fn+'.undo', fn) # rename preview
return ExtImage.inheritedAttribute("_undo")(self)
- def _get_ufn(self, filename=None):
+ def _get_ufn(self, filename=None, path=None):
""" If no unique filename has been generated, generate one
otherwise, return the existing one.
"""
if filename is not None:
- return ExtImage.inheritedAttribute("_get_ufn") (self, filename)
+ return ExtImage.inheritedAttribute("_get_ufn") (self, filename, path=path)
new_fn = ''
if self.filename:
test_fn = self._get_filename(self.filename) + '.preview'
@@ -446,7 +446,7 @@
new_fn = self.filename[:]
if not new_fn:
new_fn = ExtImage.inheritedAttribute("_get_ufn") (self,
- self.prev_filename)
+ self.prev_filename, path=path)
if new_fn != self.prev_filename:
new_fn[-1] = new_fn[-1] + '.preview'
return new_fn