[Zope-CVS] CVS: Packages/Moztop/moztopsupport/http - __init__.py:1.1 configure.zcml:1.1 put.py:1.1
Sidnei da Silva
sidnei@x3ng.com.br
Thu, 20 Mar 2003 13:24:28 -0500
Update of /cvs-repository/Packages/Moztop/moztopsupport/http
In directory cvs.zope.org:/tmp/cvs-serv22557/moztopsupport/http
Added Files:
__init__.py configure.zcml put.py
Log Message:
Big refactoring. Renamed idesupport to moztop support. Adding a utility to get Resource Types
=== Added File Packages/Moztop/moztopsupport/http/__init__.py ===
##############################################################################
#
# Copyright (c) 2002, 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
__doc__ = """ HTTP Support for Moztop Extension Product
$Id: __init__.py,v 1.1 2003/03/20 18:24:27 sidnei Exp $
"""
=== Added File Packages/Moztop/moztopsupport/http/configure.zcml ===
<zopeConfigure xmlns='http://namespaces.zope.org/zope'>
<view
for="zope.app.interfaces.http.INullResource"
name="PUT"
type="zope.publisher.interfaces.http.IHTTPPresentation"
factory=".put.NullPUT"
permission="zope.Public"
allowed_attributes="PUT"
/>
<adapter
for="zope.app.interfaces.content.folder.IFolder"
provides="zope.app.interfaces.file.IFileFactory"
name="PageTemplate"
factory="zope.app.content.zpt.ZPTFactory"
permission="zope.ManageContent"
/>
</zopeConfigure>
=== Added File Packages/Moztop/moztopsupport/http/put.py ===
##############################################################################
#
# Copyright (c) 2002, 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
__doc__ = """ HTTP PUT Support for Moztop Extension Product
$Id: put.py,v 1.1 2003/03/20 18:24:27 sidnei Exp $
"""
__metaclass__ = type
from zope.component import getAdapter, queryAdapter
from zope.app.interfaces.http import INullResource
from zope.app.interfaces.file import IWriteFile, IWriteDirectory, IFileFactory
from zope.app.interfaces.container import IZopeWriteContainer
from zope.app.event import publish
from zope.app.event.objectevent import ObjectCreatedEvent
class NullPUT:
"""Put handler for null resources (new file-like things)
This view creates new objects in containers.
"""
def __init__(self, context, request):
self.context = context
self.request = request
def PUT(self):
request = self.request
for name in request:
if name.startswith('HTTP_CONTENT_'):
# Unimplemented content header
request.response.setStatus(501)
return ''
body = request.bodyFile
name = self.context.name
container = self.context.container
# Find the object type
type_name = request.getHeader('X-Zope-Type-Name', '')
# Find the extension
ext_start = name.rfind('.')
if ext_start > 0:
ext = name[ext_start:]
else:
ext = "."
# Get a "directory" surrogate for the container
dir = queryAdapter(container, IWriteDirectory)
# Get the zope adapter for that
dir = getAdapter(dir, IZopeWriteContainer)
# Now try to get a custom factory for he container by
# type name
factory = queryAdapter(container, IFileFactory, name=type_name)
if factory is None:
# Now try to get a custom factory for he container
factory = queryAdapter(container, IFileFactory, name=ext)
# Fall back to a non-custom one
if factory is None:
factory = getAdapter(container, IFileFactory)
# XXX Need to add support for large files
data = body.read()
newfile = factory(name, request.getHeader('content-type', ''), data)
publish(self.context, ObjectCreatedEvent(newfile))
dir.setObject(name, newfile)
request.response.setStatus(201)
return ''