[Zope3-checkins]
SVN: Zope3/branches/ctheune-issue-125/src/zope/app/http/put.py
- working cut of making the PUT factory conform to rfc2616
Christian Theune
ct at gocept.com
Thu Sep 28 02:10:13 EDT 2006
Log message for revision 70405:
- working cut of making the PUT factory conform to rfc2616
Changed:
U Zope3/branches/ctheune-issue-125/src/zope/app/http/put.py
-=-
Modified: Zope3/branches/ctheune-issue-125/src/zope/app/http/put.py
===================================================================
--- Zope3/branches/ctheune-issue-125/src/zope/app/http/put.py 2006-09-28 06:09:30 UTC (rev 70404)
+++ Zope3/branches/ctheune-issue-125/src/zope/app/http/put.py 2006-09-28 06:10:12 UTC (rev 70405)
@@ -20,12 +20,17 @@
from zope.lifecycleevent import ObjectCreatedEvent
from zope.interface import implements
from zope.filerepresentation.interfaces import IWriteFile
-from zope.filerepresentation.interfaces import IWriteDirectory, IFileFactory
+from zope.filerepresentation.interfaces import \
+ IWriteDirectory, IReadDirectory, IFileFactory
from zope.app.http.interfaces import INullResource
+from zope.app import zapi
+
+
class NullResource(object):
"""Object representing objects to be created by a `PUT`.
+
"""
implements(INullResource)
@@ -39,6 +44,7 @@
"""Put handler for null resources (new file-like things)
This view creates new objects in containers.
+
"""
def __init__(self, context, request):
@@ -60,7 +66,9 @@
ext = "."
# Get a "directory" surrogate for the container
- dir = IWriteDirectory(container, None)
+ # XXX Argh. Why don't we have a unioned Interface for that?!?
+ dir_write = IWriteDirectory(container)
+ dir_read = IReadDirectory(container)
# Now try to get a custom factory for he container
factory = queryAdapter(container, IFileFactory, ext)
@@ -75,13 +83,21 @@
newfile = factory(name, request.getHeader('content-type', ''), data)
notify(ObjectCreatedEvent(newfile))
- dir[name] = newfile
+ dir_write[name] = newfile
+ # Ickyness with non-predictable support for containment:
+ # make sure we get a containment proxy
+ import pdb; pdb.set_trace()
+ newfile = dir_read[name]
request.response.setStatus(201)
+ request.response.setHeader(
+ 'Location', zapi.absoluteURL(newfile, request))
return ''
+
class FilePUT(object):
"""Put handler for existing file-like things
+
"""
def __init__(self, context, request):
@@ -95,11 +111,8 @@
file = self.context
adapter = IWriteFile(file)
- # TODO: Need to add support for large files
- data = body.read()
-
- adapter.write(data)
-
+ chunk = body.read(2**6)
+ while chunk:
+ adapter.write(chunk)
+ chunk = body.read(2**6)
return ''
-
-
More information about the Zope3-Checkins
mailing list