Commit cf2f95e1 authored by Tres Seaver's avatar Tres Seaver

* Commit "WebDAV source" and "hookable PUT creation" features to trunk

  for 2.3a1.
parent 311589c2
...@@ -41,7 +41,14 @@ Zope changes ...@@ -41,7 +41,14 @@ Zope changes
- Implemented the "emergency user" concept, which is the new - Implemented the "emergency user" concept, which is the new
name for what was called the superuser. name for what was called the superuser.
- Added new "WebDAV source view" HTTP handler, enabled by new
'-W' (note uppercase) switch to z2.py. This handler is *not*
enabled by default.
- Implemented "hookable PUT creation" (allows containers to
override webdav.NullResource's guess at the type of object
to create when PUT is done to an unknown ID).
Bugs Fixed Bugs Fixed
......
...@@ -85,7 +85,7 @@ ...@@ -85,7 +85,7 @@
"""WebDAV support - null resource objects.""" """WebDAV support - null resource objects."""
__version__='$Revision: 1.23 $'[11:-2] __version__='$Revision: 1.24 $'[11:-2]
import sys, os, string, mimetypes, Globals import sys, os, string, mimetypes, Globals
import Acquisition, OFS.content_types import Acquisition, OFS.content_types
...@@ -130,23 +130,38 @@ class NullResource(Persistent, Acquisition.Implicit, Resource): ...@@ -130,23 +130,38 @@ class NullResource(Persistent, Acquisition.Implicit, Resource):
# Most methods return 404 (Not Found) for null resources. # Most methods return 404 (Not Found) for null resources.
DELETE=OPTIONS=TRACE=PROPFIND=PROPPATCH=COPY=MOVE=HEAD DELETE=OPTIONS=TRACE=PROPFIND=PROPPATCH=COPY=MOVE=HEAD
def _default_PUT_factory( self, name, typ, body ):
# Return DTMLDoc/Image/File, based on sniffing.
from OFS.Image import Image, File
from OFS.DTMLDocument import DTMLDocument
if typ in ('text/html', 'text/xml', 'text/plain'):
ob = DTMLDocument( '', __name__=name )
elif typ[:6]=='image/':
ob=Image(name, '', body, content_type=typ)
else:
ob=File(name, '', body, content_type=typ)
return ob
def PUT(self, REQUEST, RESPONSE): def PUT(self, REQUEST, RESPONSE):
"""Create a new non-collection resource.""" """Create a new non-collection resource."""
self.dav__init(REQUEST, RESPONSE) self.dav__init(REQUEST, RESPONSE)
type=REQUEST.get_header('content-type', None)
body=REQUEST.get('BODY', '')
name=self.__name__ name=self.__name__
if type is None: parent=self.__parent__
type, enc=OFS.content_types.guess_content_type(name, body) body=REQUEST.get('BODY', '')
from OFS.Image import Image, File typ=REQUEST.get_header('content-type', None)
if type in ('text/html', 'text/xml', 'text/plain'): if typ is None:
self.__parent__.manage_addDTMLDocument(name, '', body) typ, enc=OFS.content_types.guess_content_type(name, body)
elif type[:6]=='image/':
ob=Image(name, '', body, content_type=type) factory = getattr( parent, 'PUT_factory'
self.__parent__._setObject(name, ob) , self._default_PUT_factory )
else: ob = ( factory( name, typ, body )
ob=File(name, '', body, content_type=type) or self._default_PUT_factory( name, typ, body )
self.__parent__._setObject(name, ob) )
# Delegate actual PUT handling to the new object.
ob.PUT( REQUEST, RESPONSE )
self.__parent__._setObject(name, ob)
RESPONSE.setStatus(201) RESPONSE.setStatus(201)
RESPONSE.setBody('') RESPONSE.setBody('')
return RESPONSE return RESPONSE
......
# Implement the "hookable PUT" hook.
import re, OFS.DTMLMethod
TEXT_PATTERN = re.compile( '^text/.*$' )
def PUT_factory( self, name, typ, body ):
"""
"""
if TEXT_PATTERN.match( typ ):
return OFS.DTMLMethod.DTMLMethod( '', __name__=name )
return None
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