[Zope3-checkins]
SVN: Zope3/branches/ajung-target-requestpublication-next-try-branch/src/zope/app/publication/
added the 'publisher' directive
Tarek Ziadé
tziade at nuxeo.com
Fri Oct 7 07:18:24 EDT 2005
Log message for revision 38862:
added the 'publisher' directive
Changed:
U Zope3/branches/ajung-target-requestpublication-next-try-branch/src/zope/app/publication/configure.zcml
A Zope3/branches/ajung-target-requestpublication-next-try-branch/src/zope/app/publication/meta.zcml
A Zope3/branches/ajung-target-requestpublication-next-try-branch/src/zope/app/publication/metaconfigure.py
A Zope3/branches/ajung-target-requestpublication-next-try-branch/src/zope/app/publication/metadirectives.py
-=-
Modified: Zope3/branches/ajung-target-requestpublication-next-try-branch/src/zope/app/publication/configure.zcml
===================================================================
--- Zope3/branches/ajung-target-requestpublication-next-try-branch/src/zope/app/publication/configure.zcml 2005-10-07 11:03:28 UTC (rev 38861)
+++ Zope3/branches/ajung-target-requestpublication-next-try-branch/src/zope/app/publication/configure.zcml 2005-10-07 11:18:23 UTC (rev 38862)
@@ -10,4 +10,36 @@
permission="zope.Public"
/>
+ <publisher
+ name="SOAP"
+ factory=".requestpublicationfactories.SOAPFactory"
+ method="POST"
+ mimetype="text/xml"
+ priority="30"
+ />
+
+ <publisher
+ name="XMLRPC"
+ factory=".requestpublicationfactories.XMLRPCFactory"
+ method="POST"
+ mimetype="text/xml"
+ priority="20"
+ />
+
+ <publisher
+ name="BROWSER"
+ factory=".requestpublicationfactories.BrowserFactory"
+ method="GET,POST,HEAD"
+ mimetype="*"
+ priority="10"
+ />
+
+ <publisher
+ name="HTTP"
+ factory=".requestpublicationfactories.HTTPFactory"
+ method="*"
+ mimetype="*"
+ priority="0"
+ />
+
</configure>
Added: Zope3/branches/ajung-target-requestpublication-next-try-branch/src/zope/app/publication/meta.zcml
===================================================================
--- Zope3/branches/ajung-target-requestpublication-next-try-branch/src/zope/app/publication/meta.zcml 2005-10-07 11:03:28 UTC (rev 38861)
+++ Zope3/branches/ajung-target-requestpublication-next-try-branch/src/zope/app/publication/meta.zcml 2005-10-07 11:18:23 UTC (rev 38862)
@@ -0,0 +1,8 @@
+<configure xmlns:meta="http://namespaces.zope.org/meta">
+ <meta:directive
+ namespace="http://namespaces.zope.org/zope"
+ name="publisher"
+ schema=".metadirectives.IRequestPublicationDirective"
+ handler=".metaconfigure.publisher"
+ />
+</configure>
Added: Zope3/branches/ajung-target-requestpublication-next-try-branch/src/zope/app/publication/metaconfigure.py
===================================================================
--- Zope3/branches/ajung-target-requestpublication-next-try-branch/src/zope/app/publication/metaconfigure.py 2005-10-07 11:03:28 UTC (rev 38861)
+++ Zope3/branches/ajung-target-requestpublication-next-try-branch/src/zope/app/publication/metaconfigure.py 2005-10-07 11:18:23 UTC (rev 38862)
@@ -0,0 +1,59 @@
+##############################################################################
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (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.
+#
+##############################################################################
+""" Directive handler for publication factory
+
+See metadirective.py
+
+$Id: $
+"""
+__docformat__ = 'restructuredtext'
+
+class RequestPublicationRegisterer(object):
+ """ Link a request type to a request-publication factory """
+
+ def __init__(self, name, factory, method=u'', mimetype=u'', priority=0):
+
+ methods = self._extractElements(method)
+ mimetypes = self._extractElements(mimetype)
+ self._installFactory(name, factory, methods, mimetypes, priority)
+
+ def _extractElements(self, chain):
+ """ elements are separated by commas,
+
+ >>> reg = RequestPublicationRegisterer()
+ >>> reg._extractElements('GET, POST,HEAD')
+ ['GET', 'POST', 'HEAD']
+ >>> reg._extractElements('*')
+ ['*']
+ >>> reg._extractElements('')
+ ['*']
+ >>> reg._extractElements('text/xml, text/html')
+ ['text/xml', 'text/html']
+ """
+ def _cleanElement(element):
+ element = element.strip()
+ if element == u'':
+ return u'*'
+ return element
+
+ return map(_cleanElement, chain.split(u','))
+
+ def _installFactory(self, name, factory, methods, mimetypes, priority):
+ """ calls the register factory utility, that actually links
+ the factory.
+ """
+ pass
+
+def publisher(_context, name, factory, method='*', mimetype='*', priority=0):
+ RequestPublicationRegisterer(name, factory, method, mimetype, priority)
Added: Zope3/branches/ajung-target-requestpublication-next-try-branch/src/zope/app/publication/metadirectives.py
===================================================================
--- Zope3/branches/ajung-target-requestpublication-next-try-branch/src/zope/app/publication/metadirectives.py 2005-10-07 11:03:28 UTC (rev 38861)
+++ Zope3/branches/ajung-target-requestpublication-next-try-branch/src/zope/app/publication/metadirectives.py 2005-10-07 11:18:23 UTC (rev 38862)
@@ -0,0 +1,53 @@
+##############################################################################
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (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.
+#
+##############################################################################
+""" Directive schema, for publication factory
+
+This module provides the schema for the new zcml directive,
+that let the developer associate a publication factory to a given
+request, based on its method and mimetype.
+
+Each directive also has a name and a sortkey.
+
+The sortkey helps when several directives can handle a request:
+they are sorted by this key and the highest one is taken.
+
+$Id: $
+"""
+__docformat__ = 'restructuredtext'
+
+from zope.interface import Interface
+from zope.configuration.fields import GlobalObject
+from zope.schema import TextLine, Int
+
+class IRequestPublicationDirective(Interface):
+ """ Link a request type to a request-publication factory """
+
+ name = TextLine(title=u'Name',
+ description=u'The name of the publication factory.')
+
+ factory = GlobalObject(title=u'Factory',
+ description=u'The request-publication factory')
+
+ method = TextLine(title=u'Method',
+ description=u'The name of the request method.',
+ required=False)
+
+ mimetype = TextLine(title=u'MimeType',
+ description=u'The content type of the request.',
+ required=False)
+
+ priority = Int(title=u'Priority',
+ description=(u'A priority key used to concurrent'
+ ' publication factories.'),
+ required=False)
More information about the Zope3-Checkins
mailing list