[Zope] Product that catches webdav PUTs and does something else
Brian Lloyd
brian@digicool.com
Wed, 28 Mar 2001 13:50:49 -0500
> Thanks Brian, that does seem to be what I'm after, however, I
> couldn't make
> it do what I expected. After many attempts at solving the problem, I
> defined a PUT method that seems to be called instead of the
> PUT_factory when
> uploading from Composer into the webdav_src_port. Is this what would be
> expected? If so, I think I misunderstand the use of PUT_factory.
Here is a quick primer on what happens when a PUT occurs.
Lets say you do a PUT on /foo/bar/file.html, an object
*that already exists* in the system. In this case:
- the publisher traverses to the object /foo/bar/file.html
- if the HTTP request method is GET or POST, it looks for
index_html. Otherwise (as in this case), it looks for
a method on the object matching the HTTP method (PUT).
So if /foo/bar/file.html already exists, it's PUT method will
be called. This is the case for editing / updating existing
objects.
Where the PUT_factory comes in is when /foo/bar/file.html does
*not* yet exist. In this case:
- the publisher traverses to /foo/bar/file.html. When it asks
'bar' for 'file.html' ( assuming 'bar' is a Folder), 'bar'
finds that it doesn't exist so it returns a special object
called a 'NullResource'. NullResource is a class defined
in the lib/python/webdav package, and its sole purpose is
to have a PUT method that will be called in this case (where
no object exists yet).
The PUT implementation of NullResource objects first tries to
delegate to self.PUT_factory(...), which gives app developers an
opportunity to expand on the default handling of a PUT on a
non-existing resource. The NullResource is an acquirer, so the
developer can implement a PUT_factory as a method of the container,
or as a Python Script, whatever, to override the default behavior
of the NullResource PUT. The default behavior (used if no PUT_factory
is found), is to try to 'do the right thing' based on the mime-type
or file extension (create a DTMLDocument for .txt, .html; Image for
.gif, .jpg; File for anything else).
Hopefully this sheds some light on what happens underneath and
make the PUT_factory document more useful - if you still can't
get PUT_factory to work as expected you might want to contact
the author (Tres) to make sure it is up to date (I can't tell
from a glance - but knowing Tres I suspect it is up to date :).
Brian Lloyd brian@digicool.com
Software Engineer 540.371.6909
Digital Creations http://www.digicool.com