[Zope-Checkins] CVS: Packages/webdav - NullResource.py:188.8.131.52.8.1
Sidnei da Silva
sidnei at awkly.org
Wed Nov 3 15:15:04 EST 2004
Update of /cvs-repository/Packages/webdav
In directory cvs.zope.org:/tmp/cvs-serv17273/lib/python/webdav
Create a directive for configuring the large file threshold where temp files are created and use it for NullResource.PUT.
=== Packages/webdav/NullResource.py 184.108.40.206 => 220.127.116.11.8.1 ===
--- Packages/webdav/NullResource.py:18.104.22.168 Mon Apr 26 11:42:33 2004
+++ Packages/webdav/NullResource.py Wed Nov 3 15:14:34 2004
@@ -81,13 +81,16 @@
ob=File(name, '', body, content_type=typ)
+ PUT__roles__ = ('Anonymous',)
def PUT(self, REQUEST, RESPONSE):
- """Create a new non-collection resource."""
+ """Create a new non-collection resource.
+ from ZServer import LARGE_FILE_THRESHOLD
+ name = self.__name__
+ parent = self.__parent__
ifhdr = REQUEST.get_header('If', '')
if WriteLockInterface.isImplementedBy(parent) and parent.wl_isLocked():
@@ -101,17 +104,40 @@
# There was an If header, but the parent is not locked
- body=REQUEST.get('BODY', '')
+ # SDS: Only use BODY if the file size is smaller than
+ # LARGE_FILE_THRESHOLD, otherwise read LARGE_FILE_THRESHOLD
+ # bytes from the file which should be enough to trigger
+ # content_type detection, and possibly enough for CMF's
+ # content_type_registry too.
+ # Note that body here is really just used for detecting the
+ # content type and figuring out the correct factory. The correct
+ # file content will be uploaded on ob.PUT(REQUEST, RESPONSE) after
+ # the object has been created.
+ # A problem I could see is content_type_registry predicates
+ # that do depend on the whole file being passed here as an
+ # argument. There's none by default that does this though. If
+ # they really do want to look at the file, they should use
+ # REQUEST['BODYFILE'] directly and try as much as possible not
+ # to read the whole file into memory.
+ if int(REQUEST.get('CONTENT_LENGTH') or 0) > LARGE_FILE_THRESHOLD:
+ file = REQUEST['BODYFILE']
+ body = file.read(LARGE_FILE_THRESHOLD)
+ body = REQUEST.get('BODY', '')
if typ is None:
typ, enc=OFS.content_types.guess_content_type(name, body)
factory = getattr(parent, 'PUT_factory', self._default_PUT_factory )
ob = factory(name, typ, body)
- ob = (ob is None and
- self._default_PUT_factory(name, typ, body) or
+ if ob is None:
+ ob = self._default_PUT_factory(name, typ, body)
# We call _verifyObjectPaste with verify_src=0, to see if the
# user can create this type of object (and we don't need to
# check the clipboard.
@@ -122,9 +148,11 @@
raise Forbidden, sys.exc_info()
- # Delegate actual PUT handling to the new object.
- ob.PUT(REQUEST, RESPONSE)
+ # Delegate actual PUT handling to the new object,
+ # SDS: But just *after* it has been stored.
+ ob = self.__parent__._getOb(name)
+ ob.PUT(REQUEST, RESPONSE)
More information about the Zope-Checkins