[Checkins] SVN: zope.generic/trunk/src/zope/generic/ additional handler directive that combines object events and operation handlers

Dominik Huber dominik.huber at perse.ch
Wed Apr 26 09:33:13 EDT 2006


Log message for revision 67617:
  additional handler directive that combines object events and operation handlers
  
  type:
  - handler subdirective

Changed:
  U   zope.generic/trunk/src/zope/generic/adapter/PUBLICATION.cfg
  U   zope.generic/trunk/src/zope/generic/adapter/testing.py
  A   zope.generic/trunk/src/zope/generic/handler/
  A   zope.generic/trunk/src/zope/generic/handler/DEPENDENCIES.cfg
  A   zope.generic/trunk/src/zope/generic/handler/PUBLICATION.cfg
  A   zope.generic/trunk/src/zope/generic/handler/README.txt
  A   zope.generic/trunk/src/zope/generic/handler/SETUP.cfg
  A   zope.generic/trunk/src/zope/generic/handler/__init__.py
  A   zope.generic/trunk/src/zope/generic/handler/api.py
  A   zope.generic/trunk/src/zope/generic/handler/configure.zcml
  A   zope.generic/trunk/src/zope/generic/handler/interfaces.py
  A   zope.generic/trunk/src/zope/generic/handler/meta.zcml
  A   zope.generic/trunk/src/zope/generic/handler/metaconfigure.py
  A   zope.generic/trunk/src/zope/generic/handler/metadirectives.py
  A   zope.generic/trunk/src/zope/generic/handler/testing.py
  A   zope.generic/trunk/src/zope/generic/handler/tests.py
  A   zope.generic/trunk/src/zope/generic/handler/zope.generic.handler-configure.zcml
  A   zope.generic/trunk/src/zope/generic/handler/zope.generic.handler-meta.zcml
  U   zope.generic/trunk/src/zope/generic/informationprovider/metadirectives.py
  U   zope.generic/trunk/src/zope/generic/keyface/metadirectives.py
  A   zope.generic/trunk/src/zope/generic/site/
  A   zope.generic/trunk/src/zope/generic/site/__init__.py
  A   zope.generic/trunk/src/zope/generic/site/api.py
  A   zope.generic/trunk/src/zope/generic/site/helper.py
  A   zope.generic/trunk/src/zope/generic/site/interfaces.py
  U   zope.generic/trunk/src/zope/generic/type/README.txt
  U   zope.generic/trunk/src/zope/generic/type/meta.zcml
  U   zope.generic/trunk/src/zope/generic/type/metaconfigure.py
  U   zope.generic/trunk/src/zope/generic/type/metadirectives.py
  U   zope.generic/trunk/src/zope/generic/type/testing.py

-=-
Modified: zope.generic/trunk/src/zope/generic/adapter/PUBLICATION.cfg
===================================================================
--- zope.generic/trunk/src/zope/generic/adapter/PUBLICATION.cfg	2006-04-26 11:34:51 UTC (rev 67616)
+++ zope.generic/trunk/src/zope/generic/adapter/PUBLICATION.cfg	2006-04-26 13:33:11 UTC (rev 67617)
@@ -1,10 +1,8 @@
 Metadata-Version: 1.0
 Name: zope.generic.adapter
-Summary: Configuratons stores schema based configuration data using the schema as key.
+Summary: Convenience adapter directive
 Author: Dominik Huber, Perse Engineering GmbH, Switzerland
 Author-email: dominik.huber at perse.ch
 License: ZPL 2.1
 Description:
-        This package offers a mechanism to declare a key interface (IKeyface).
-		The key interface can be used to lookup corresponding information providers
-		explicitly. 
+        n/a 

Modified: zope.generic/trunk/src/zope/generic/adapter/testing.py
===================================================================
--- zope.generic/trunk/src/zope/generic/adapter/testing.py	2006-04-26 11:34:51 UTC (rev 67616)
+++ zope.generic/trunk/src/zope/generic/adapter/testing.py	2006-04-26 13:33:11 UTC (rev 67617)
@@ -20,8 +20,6 @@
 
 import zope.app.testing.placelesssetup
 from zope.configuration.xmlconfig import XMLConfig
-from zope.interface import Interface
-from zope.schema import TextLine
 
 import zope.generic.adapter.testing
 import zope.generic.configuration.testing
@@ -35,33 +33,7 @@
 #
 ################################################################################
 
-class IMarker(Interface):
-    """Demo marker."""
 
-
-class IBarConfiguration(Interface):
-
-    bar = TextLine(title=u'Bar')
-
-
-class IInputConfiguration(Interface):
-
-    foo = TextLine(title=u'Foo')
-
-    bar = TextLine(title=u'Bar')
-
-
-class IFooConfiguration(Interface):
-
-    foo = TextLine(title=u'Foo')
-    
-    fo = TextLine(title=u'Fo', required=False, readonly=True, default=u'fo default')
-
-
-class TestKeyfaceAttriute(object):
-    __keyface__ = IFooConfiguration
-
-
 ################################################################################
 #
 # Placeless setup

Added: zope.generic/trunk/src/zope/generic/handler/DEPENDENCIES.cfg
===================================================================
--- zope.generic/trunk/src/zope/generic/handler/DEPENDENCIES.cfg	2006-04-26 11:34:51 UTC (rev 67616)
+++ zope.generic/trunk/src/zope/generic/handler/DEPENDENCIES.cfg	2006-04-26 13:33:11 UTC (rev 67617)
@@ -0,0 +1,13 @@
+zope.app.component
+zope.app.location
+zope.app.security
+zope.app.testing
+zope.component
+zope.configuration
+zope.generic.configuration
+zope.generic.directlyprovides
+zope.generic.keyface
+zope.generic.testing
+zope.interface
+zope.schema
+zope.testing
\ No newline at end of file


Property changes on: zope.generic/trunk/src/zope/generic/handler/DEPENDENCIES.cfg
___________________________________________________________________
Name: svn:keywords
   + Id

Added: zope.generic/trunk/src/zope/generic/handler/PUBLICATION.cfg
===================================================================
--- zope.generic/trunk/src/zope/generic/handler/PUBLICATION.cfg	2006-04-26 11:34:51 UTC (rev 67616)
+++ zope.generic/trunk/src/zope/generic/handler/PUBLICATION.cfg	2006-04-26 13:33:11 UTC (rev 67617)
@@ -0,0 +1,10 @@
+Metadata-Version: 1.0
+Name: zope.generic.handler
+Summary: Configuratons stores schema based configuration data using the schema as key.
+Author: Dominik Huber, Perse Engineering GmbH, Switzerland
+Author-email: dominik.huber at perse.ch
+License: ZPL 2.1
+Description:
+        This package offers a mechanism to declare a key interface (IKeyface).
+		The key interface can be used to lookup corresponding information providers
+		explicitly. 


Property changes on: zope.generic/trunk/src/zope/generic/handler/PUBLICATION.cfg
___________________________________________________________________
Name: svn:keywords
   + Id

Added: zope.generic/trunk/src/zope/generic/handler/README.txt
===================================================================
--- zope.generic/trunk/src/zope/generic/handler/README.txt	2006-04-26 11:34:51 UTC (rev 67616)
+++ zope.generic/trunk/src/zope/generic/handler/README.txt	2006-04-26 13:33:11 UTC (rev 67617)
@@ -0,0 +1,57 @@
+===============
+Generic Handler
+===============
+
+The directive generic:handler allows to register operation-based object event
+handlers.
+
+
+Hander convenience subscriber
+-----------------------------
+
+First we declare a key interface:
+
+    >>> class IFoo(interface.Interface):
+    ...    """The key interface."""
+
+    >>> registerDirective('''
+    ... <generic:keyface
+    ...     keyface="example.IFoo"
+    ...     />
+    ... ''')
+
+During the notification process we invoke the declared operations. In our example
+we are defining a simple handler, but you could use object providing IOperation
+or interfaces providing IOperationType too:
+
+    >>> def simplehandler(context, event):
+    ...    print 'Guguseli!'
+
+
+That we can register the generic:handler directive we have also to choose a
+certain event-interface or -class:
+
+    >>> registerDirective('''
+    ... <generic:handler
+    ...     keyface="example.IFoo"
+    ...     event="zope.app.event.interfaces.IObjectEvent"
+    ...     operations="example.simplehandler"
+    ...     />
+    ... ''') 
+
+Now we can check out the registered handler:
+
+    >>> class Foo(object):
+    ...     interface.implements(IFoo)
+
+    >>> foo = Foo()
+
+    >>> from zope.app.event.interfaces import IObjectEvent
+    >>> from zope.app.event.objectevent import ObjectEvent
+    >>> from zope.event import notify
+
+    >>> event = ObjectEvent(foo)
+    >>> notify(event)
+    Guguseli!
+    
+    >>> notify(ObjectEvent(object()))


Property changes on: zope.generic/trunk/src/zope/generic/handler/README.txt
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: zope.generic/trunk/src/zope/generic/handler/SETUP.cfg
===================================================================
--- zope.generic/trunk/src/zope/generic/handler/SETUP.cfg	2006-04-26 11:34:51 UTC (rev 67616)
+++ zope.generic/trunk/src/zope/generic/handler/SETUP.cfg	2006-04-26 13:33:11 UTC (rev 67617)
@@ -0,0 +1,3 @@
+<data-files zopeskel/etc/package-includes>
+  zope.generic.handler-*.zcml
+</data-files>
\ No newline at end of file


Property changes on: zope.generic/trunk/src/zope/generic/handler/SETUP.cfg
___________________________________________________________________
Name: svn:keywords
   + Id

Added: zope.generic/trunk/src/zope/generic/handler/__init__.py
===================================================================
--- zope.generic/trunk/src/zope/generic/handler/__init__.py	2006-04-26 11:34:51 UTC (rev 67616)
+++ zope.generic/trunk/src/zope/generic/handler/__init__.py	2006-04-26 13:33:11 UTC (rev 67617)
@@ -0,0 +1,19 @@
+##############################################################################
+#
+# Copyright (c) 2005, 2006 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.
+#
+##############################################################################
+
+"""
+$Id$
+"""
+
+from zope.generic.handler.interfaces import *
\ No newline at end of file


Property changes on: zope.generic/trunk/src/zope/generic/handler/__init__.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: zope.generic/trunk/src/zope/generic/handler/api.py
===================================================================
--- zope.generic/trunk/src/zope/generic/handler/api.py	2006-04-26 11:34:51 UTC (rev 67616)
+++ zope.generic/trunk/src/zope/generic/handler/api.py	2006-04-26 13:33:11 UTC (rev 67617)
@@ -0,0 +1,21 @@
+##############################################################################
+#
+# Copyright (c) 2005, 2006 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.
+#
+##############################################################################
+
+"""
+$Id$
+"""
+
+__docformat__ = 'restructuredtext'
+
+from zope.generic.handler import *


Property changes on: zope.generic/trunk/src/zope/generic/handler/api.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: zope.generic/trunk/src/zope/generic/handler/configure.zcml
===================================================================
--- zope.generic/trunk/src/zope/generic/handler/configure.zcml	2006-04-26 11:34:51 UTC (rev 67616)
+++ zope.generic/trunk/src/zope/generic/handler/configure.zcml	2006-04-26 13:33:11 UTC (rev 67617)
@@ -0,0 +1,6 @@
+<configure
+  xmlns="http://namespaces.zope.org/zope"
+  xmlns:generic="http://namespaces.zope.org/generic"
+  i18n_domain="zope">
+
+</configure>


Property changes on: zope.generic/trunk/src/zope/generic/handler/configure.zcml
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: zope.generic/trunk/src/zope/generic/handler/interfaces.py
===================================================================
--- zope.generic/trunk/src/zope/generic/handler/interfaces.py	2006-04-26 11:34:51 UTC (rev 67616)
+++ zope.generic/trunk/src/zope/generic/handler/interfaces.py	2006-04-26 13:33:11 UTC (rev 67617)
@@ -0,0 +1,19 @@
+##############################################################################
+#
+# Copyright (c) 2005, 2006 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.
+#
+##############################################################################
+
+"""
+$Id$
+"""
+
+__docformat__ = 'restructuredtext'


Property changes on: zope.generic/trunk/src/zope/generic/handler/interfaces.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: zope.generic/trunk/src/zope/generic/handler/meta.zcml
===================================================================
--- zope.generic/trunk/src/zope/generic/handler/meta.zcml	2006-04-26 11:34:51 UTC (rev 67616)
+++ zope.generic/trunk/src/zope/generic/handler/meta.zcml	2006-04-26 13:33:11 UTC (rev 67617)
@@ -0,0 +1,15 @@
+<configure
+    xmlns="http://namespaces.zope.org/zope"
+    xmlns:meta="http://namespaces.zope.org/meta">
+
+  <meta:directives namespace="http://namespaces.zope.org/generic">
+
+    <meta:directive
+        name="handler"
+        schema=".metadirectives.IHandlerDirective"
+        handler=".metaconfigure.handlerDirective"
+        />
+
+  </meta:directives>
+
+</configure>


Property changes on: zope.generic/trunk/src/zope/generic/handler/meta.zcml
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: zope.generic/trunk/src/zope/generic/handler/metaconfigure.py
===================================================================
--- zope.generic/trunk/src/zope/generic/handler/metaconfigure.py	2006-04-26 11:34:51 UTC (rev 67616)
+++ zope.generic/trunk/src/zope/generic/handler/metaconfigure.py	2006-04-26 13:33:11 UTC (rev 67617)
@@ -0,0 +1,42 @@
+##############################################################################
+#
+# Copyright (c) 2005, 2006 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.
+#
+##############################################################################
+
+"""
+$Id$
+"""
+
+__docformat__ = 'restructuredtext'
+
+from zope.app.component.metaconfigure import subscriber
+
+from zope.generic.keyface import IKeyfaceType
+from zope.generic.operation.api import assertOperation
+
+
+def handlerDirective(_context, keyface, event, operations=(), input=None):
+    """Provide a generic trusted handler."""
+
+    # TODO: to be finished...
+    if input:
+        raise NotImplementedError('Missing feature: You cannot use the input attribute yet.')
+
+    # evaluate the operation
+    operation = assertOperation(operations, keyface, input, None)
+
+    def handler(component, event):
+        operation(component, event)
+
+    subscriber(_context, for_=[keyface, event], factory=None, handler=handler, 
+        provides=None, permission=None, trusted=True, locate=False)
+


Property changes on: zope.generic/trunk/src/zope/generic/handler/metaconfigure.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: zope.generic/trunk/src/zope/generic/handler/metadirectives.py
===================================================================
--- zope.generic/trunk/src/zope/generic/handler/metadirectives.py	2006-04-26 11:34:51 UTC (rev 67616)
+++ zope.generic/trunk/src/zope/generic/handler/metadirectives.py	2006-04-26 13:33:11 UTC (rev 67617)
@@ -0,0 +1,41 @@
+##############################################################################
+#
+# Copyright (c) 2005, 2006 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.
+#
+##############################################################################
+
+"""
+$Id$
+"""
+
+__docformat__ = 'restructuredtext'
+
+from zope.app.i18n import ZopeMessageFactory as _
+from zope.configuration.fields import GlobalInterface
+from zope.interface import Interface
+
+from zope.generic.keyface.metadirectives import IBaseKeyfaceDirective
+from zope.generic.operation.metadirectives import IBaseOperationDirective
+
+
+
+class IBaseHandlerDirective(Interface):
+    """Base handler directive."""
+
+    event = GlobalInterface(
+        title=_('Event'),
+        description=_('The event to be listened.'),
+        required=True
+        )
+
+
+class IHandlerDirective(IBaseKeyfaceDirective, IBaseHandlerDirective, IBaseOperationDirective):
+    """Provide trusted locatable handler that invoke operations."""


Property changes on: zope.generic/trunk/src/zope/generic/handler/metadirectives.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: zope.generic/trunk/src/zope/generic/handler/testing.py
===================================================================
--- zope.generic/trunk/src/zope/generic/handler/testing.py	2006-04-26 11:34:51 UTC (rev 67616)
+++ zope.generic/trunk/src/zope/generic/handler/testing.py	2006-04-26 13:33:11 UTC (rev 67617)
@@ -0,0 +1,79 @@
+##############################################################################
+#
+# Copyright (c) 2005, 2006 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.
+#
+##############################################################################
+
+"""
+$Id$
+"""
+
+__docformat__ = 'restructuredtext'
+
+import zope.app.testing.placelesssetup
+from zope.configuration.xmlconfig import XMLConfig
+
+import zope.generic.handler.testing
+import zope.generic.configuration.testing
+import zope.generic.directlyprovides.testing
+import zope.generic.keyface.testing
+import zope.generic.testing.testing
+
+################################################################################
+#
+# Public Test implementations
+#
+################################################################################
+
+
+
+################################################################################
+#
+# Placeless setup
+#
+################################################################################
+
+# specific tests
+def setUp(doctest=None):
+    # register the directive of this package
+    import zope.generic.handler
+    XMLConfig('meta.zcml', zope.generic.handler)()
+
+def tearDown(doctest=None):
+    pass
+
+
+
+class PlacelessSetup(zope.app.testing.placelesssetup.PlacelessSetup):
+
+    def setUp(self, doctest=None):
+        super(PlacelessSetup, self).setUp(doctest)
+        # external setup
+        zope.generic.testing.testing.setUp(doctest)
+        zope.generic.directlyprovides.testing.setUp(doctest)
+        zope.generic.keyface.testing.setUp(doctest)
+        zope.generic.configuration.testing.setUp(doctest)
+        zope.generic.handler.testing.setUp(doctest)
+        # internal setup
+        setUp(doctest)
+
+    def tearDown(self, doctest=None):
+        # internal teardown
+        tearDown(doctest)
+        # external teardown
+        zope.generic.handler.testing.tearDown(doctest)
+        zope.generic.configuration.testing.tearDown(doctest)
+        zope.generic.keyface.testing.tearDown(doctest)
+        zope.generic.directlyprovides.testing.tearDown(doctest)
+        zope.generic.testing.testing.tearDown(doctest)
+        super(PlacelessSetup, self).tearDown()
+
+placelesssetup = PlacelessSetup()


Property changes on: zope.generic/trunk/src/zope/generic/handler/testing.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: zope.generic/trunk/src/zope/generic/handler/tests.py
===================================================================
--- zope.generic/trunk/src/zope/generic/handler/tests.py	2006-04-26 11:34:51 UTC (rev 67616)
+++ zope.generic/trunk/src/zope/generic/handler/tests.py	2006-04-26 13:33:11 UTC (rev 67617)
@@ -0,0 +1,50 @@
+##############################################################################
+#
+# Copyright (c) 2005, 2006 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.
+#
+##############################################################################
+
+"""
+$Id$
+"""
+
+import unittest
+
+from zope import component
+from zope import interface
+from zope.testing import doctest
+
+from zope.generic.testing.testing import registerDirective
+
+from zope.generic.handler import api
+from zope.generic.handler import testing
+
+
+###############################################################################
+#
+# Unit tests  
+#
+###############################################################################
+
+
+def test_suite():
+    return unittest.TestSuite((
+        doctest.DocFileSuite('README.txt',
+                             setUp=testing.placelesssetup.setUp,
+                             tearDown=testing.placelesssetup.tearDown,
+                             globs={'component': component, 'interface': interface,
+                             'registerDirective': registerDirective,
+                             'testing': testing, 'api': api},
+                             optionflags=doctest.NORMALIZE_WHITESPACE+
+                                            doctest.ELLIPSIS),
+        ))
+
+if __name__ == '__main__': unittest.main()


Property changes on: zope.generic/trunk/src/zope/generic/handler/tests.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: zope.generic/trunk/src/zope/generic/handler/zope.generic.handler-configure.zcml
===================================================================
--- zope.generic/trunk/src/zope/generic/handler/zope.generic.handler-configure.zcml	2006-04-26 11:34:51 UTC (rev 67616)
+++ zope.generic/trunk/src/zope/generic/handler/zope.generic.handler-configure.zcml	2006-04-26 13:33:11 UTC (rev 67617)
@@ -0,0 +1,5 @@
+<configure xmlns="http://namespaces.zope.org/zope">
+
+  <include package="zope.generic.handler" />
+
+</configure>


Property changes on: zope.generic/trunk/src/zope/generic/handler/zope.generic.handler-configure.zcml
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: zope.generic/trunk/src/zope/generic/handler/zope.generic.handler-meta.zcml
===================================================================
--- zope.generic/trunk/src/zope/generic/handler/zope.generic.handler-meta.zcml	2006-04-26 11:34:51 UTC (rev 67616)
+++ zope.generic/trunk/src/zope/generic/handler/zope.generic.handler-meta.zcml	2006-04-26 13:33:11 UTC (rev 67617)
@@ -0,0 +1,5 @@
+<configure xmlns="http://namespaces.zope.org/zope">
+
+  <include package="zope.generic.handler" file="meta.zcml" />
+
+</configure>


Property changes on: zope.generic/trunk/src/zope/generic/handler/zope.generic.handler-meta.zcml
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Modified: zope.generic/trunk/src/zope/generic/informationprovider/metadirectives.py
===================================================================
--- zope.generic/trunk/src/zope/generic/informationprovider/metadirectives.py	2006-04-26 11:34:51 UTC (rev 67616)
+++ zope.generic/trunk/src/zope/generic/informationprovider/metadirectives.py	2006-04-26 13:33:11 UTC (rev 67617)
@@ -26,18 +26,13 @@
 from zope.schema import DottedName
 
 from zope.generic.informationprovider import IInformationProvider
+from zope.generic.keyface.metadirectives import IBaseKeyfaceDirective
 
 
 
-class IBaseInformationProviderDirective(Interface):
+class IBaseInformationProviderDirective(IBaseKeyfaceDirective):
     """Base information provider attributes."""
 
-    keyface = GlobalInterface(
-        title=_('Key Interface'),
-        description=_('Key interface that is refered by the information.'),
-        required=True
-        )
-
     label = MessageID(
         title=_('Label'),
         description=_('Label of the information.'),

Modified: zope.generic/trunk/src/zope/generic/keyface/metadirectives.py
===================================================================
--- zope.generic/trunk/src/zope/generic/keyface/metadirectives.py	2006-04-26 11:34:51 UTC (rev 67616)
+++ zope.generic/trunk/src/zope/generic/keyface/metadirectives.py	2006-04-26 13:33:11 UTC (rev 67617)
@@ -23,16 +23,19 @@
 from zope.interface import Interface
 
 
+class IBaseKeyfaceDirective(Interface):
+    """Base keyface directive."""
 
-class IKeyFaceDirective(Interface):
-    """Base information attributes."""
-
     keyface = GlobalInterface(
         title=_('Key Interface'),
         description=_('Interface that represents an information key.'),
         required=True
         )
 
+
+class IKeyFaceDirective(IBaseKeyfaceDirective):
+    """Keyface directive."""
+
     type = GlobalInterface(
         title=_('Key Interface Type'),
         description=_('Type a key interface by an interface derived from ' +

Added: zope.generic/trunk/src/zope/generic/site/__init__.py
===================================================================
--- zope.generic/trunk/src/zope/generic/site/__init__.py	2006-04-26 11:34:51 UTC (rev 67616)
+++ zope.generic/trunk/src/zope/generic/site/__init__.py	2006-04-26 13:33:11 UTC (rev 67617)
@@ -0,0 +1,19 @@
+##############################################################################
+#
+# Copyright (c) 2005, 2006 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.
+#
+##############################################################################
+
+"""
+$Id$
+"""
+
+from zope.generic.site.interfaces import *
\ No newline at end of file


Property changes on: zope.generic/trunk/src/zope/generic/site/__init__.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: zope.generic/trunk/src/zope/generic/site/api.py
===================================================================
--- zope.generic/trunk/src/zope/generic/site/api.py	2006-04-26 11:34:51 UTC (rev 67616)
+++ zope.generic/trunk/src/zope/generic/site/api.py	2006-04-26 13:33:11 UTC (rev 67617)
@@ -0,0 +1,21 @@
+##############################################################################
+#
+# Copyright (c) 2005, 2006 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.
+#
+##############################################################################
+
+"""
+$Id$
+"""
+
+from zope.generic.site.interfaces import *
+from zope.generic.site.helper import addLocalUtility
+from zope.generic.site.helper import addSiteManager
\ No newline at end of file


Property changes on: zope.generic/trunk/src/zope/generic/site/api.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: zope.generic/trunk/src/zope/generic/site/helper.py
===================================================================
--- zope.generic/trunk/src/zope/generic/site/helper.py	2006-04-26 11:34:51 UTC (rev 67616)
+++ zope.generic/trunk/src/zope/generic/site/helper.py	2006-04-26 13:33:11 UTC (rev 67617)
@@ -0,0 +1,73 @@
+##############################################################################
+#
+# Copyright (c) 2005, 2006 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.
+#
+##############################################################################
+
+"""
+$Id$
+"""
+
+__docformat__ = 'restructuredtext'
+
+from zope.app import zapi
+from zope.app.container.interfaces import INameChooser
+from zope.app.component.interfaces.registration import ActiveStatus
+from zope.app.component.interfaces import IPossibleSite
+from zope.app.component.interfaces import ISite
+from zope.app.component.site import LocalSiteManager
+from zope.app.utility import UtilityRegistration
+
+
+
+def addSiteManager(possiblesite):
+    """Extend a possible site to a site."""
+
+    # preconditions
+    if not IPossibleSite.providedBy(possiblesite) or ISite.providedBy(possiblesite):
+        raise TypeError('IPossibleSite required.')
+
+    # essentials
+    sm = LocalSiteManager(possiblesite)
+    possiblesite.setSiteManager(sm)
+
+
+
+def addLocalUtility(site, name, iface, utility, package='default'):
+    """Add a utility to a site
+
+    The utility is added to the package and activated.
+    This assumes the site has already a Utility Service.
+    """
+    # preconditions
+    if not ISite.providedBy(site):
+        raise TypeError('ISite required.')
+
+    # get site manager and site management folder
+    sitemanager = site.getSiteManager()
+    default = sitemanager[package]
+
+    # add utility to site management folder
+    chooser = INameChooser(default)
+    folder_name = chooser.chooseName(utility.__name__, utility)
+    try: 
+        default[folder_name] = utility
+    except Exception, e:
+        # TODO: raise exception
+        print 'XXX', e # adapt to IReference Error
+
+    # create service registration
+    path = zapi.getPath(utility)
+    registration = UtilityRegistration(name, iface, utility)
+    key = default.registrationManager.addRegistration(registration)
+    zapi.traverse(default.registrationManager, key).status = ActiveStatus  
+
+    return zapi.traverse(sitemanager, path)


Property changes on: zope.generic/trunk/src/zope/generic/site/helper.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: zope.generic/trunk/src/zope/generic/site/interfaces.py
===================================================================
--- zope.generic/trunk/src/zope/generic/site/interfaces.py	2006-04-26 11:34:51 UTC (rev 67616)
+++ zope.generic/trunk/src/zope/generic/site/interfaces.py	2006-04-26 13:33:11 UTC (rev 67617)
@@ -0,0 +1,19 @@
+##############################################################################
+#
+# Copyright (c) 2005, 2006 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.
+#
+##############################################################################
+
+"""
+$Id$
+"""
+
+__docformat__ = 'restructuredtext'


Property changes on: zope.generic/trunk/src/zope/generic/site/interfaces.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Modified: zope.generic/trunk/src/zope/generic/type/README.txt
===================================================================
--- zope.generic/trunk/src/zope/generic/type/README.txt	2006-04-26 11:34:51 UTC (rev 67616)
+++ zope.generic/trunk/src/zope/generic/type/README.txt	2006-04-26 13:33:11 UTC (rev 67617)
@@ -147,11 +147,17 @@
 	>>> IAnyConfiguration.providedBy(typedata)
 	True
 
-We can provide a specific intializer:
+We can provide a specific intializer handler:
 
 	>>> def barInitializer(context, *pos, **kws):
 	...		print 'Initializing ...'
 
+Additionaly we can add other operation base object event handlers:
+
+    >>> def objectEventHandler(context, event):
+    ...        print 'Guguseli from object event.'
+
+
 After all we register our component using the type directive:
 
     >>> registerDirective('''
@@ -173,6 +179,10 @@
     ...        provides='example.IAnyConfiguration'
     ...        acquire='True'
     ...        />
+    ...    <handler
+    ...        event='zope.app.event.interfaces.IObjectEvent'
+    ...        operations='example.objectEventHandler'
+    ...        />
     ... </generic:type>
     ... ''')
 
@@ -252,3 +262,15 @@
     >>> IAnyConfiguration(bar).any = u'Guguseli from Object another time!'
     >>> IAnyConfiguration(bar).any
     u'Guguseli from Object another time!'
+
+Now we like to invoke an type-specific event handler:
+
+    >>> from zope.app.event.interfaces import IObjectEvent
+    >>> from zope.app.event.objectevent import ObjectEvent
+    >>> from zope.event import notify
+
+    >>> event = ObjectEvent(bar)
+    >>> notify(event)
+    Guguseli from object event.
+    
+    >>> notify(ObjectEvent(object()))
\ No newline at end of file

Modified: zope.generic/trunk/src/zope/generic/type/meta.zcml
===================================================================
--- zope.generic/trunk/src/zope/generic/type/meta.zcml	2006-04-26 11:34:51 UTC (rev 67616)
+++ zope.generic/trunk/src/zope/generic/type/meta.zcml	2006-04-26 13:33:11 UTC (rev 67617)
@@ -25,6 +25,11 @@
           schema=".metadirectives.IAdapterSubdirective"
           />
 
+      <meta:subdirective
+          name="handler"
+          schema=".metadirectives.IHandlerSubdirective"
+          />
+
     </meta:complexDirective>
 
   </meta:directives>

Modified: zope.generic/trunk/src/zope/generic/type/metaconfigure.py
===================================================================
--- zope.generic/trunk/src/zope/generic/type/metaconfigure.py	2006-04-26 11:34:51 UTC (rev 67616)
+++ zope.generic/trunk/src/zope/generic/type/metaconfigure.py	2006-04-26 13:33:11 UTC (rev 67617)
@@ -23,6 +23,7 @@
 from zope.generic.adapter.metaconfigure import adapterDirective
 from zope.generic.factory.metaconfigure import factoryDirective
 from zope.generic.informationprovider.metaconfigure import InformationProviderDirective
+from zope.generic.handler.metaconfigure import handlerDirective
 
 from zope.generic.type import ITypeInformation
 from zope.generic.type import ITypeType
@@ -62,4 +63,8 @@
 
         adapterDirective(_context, provides, [self._keyface], class_, 
                      writePermission, readPermission, attributes,
-                     set_attributes, key, informationProviders,)
\ No newline at end of file
+                     set_attributes, key, informationProviders,)
+
+    def handler(self, _context, event, operations=(), input=None):
+        """Provide a object event handler."""
+        handlerDirective(_context, self._keyface, event, operations, input)

Modified: zope.generic/trunk/src/zope/generic/type/metadirectives.py
===================================================================
--- zope.generic/trunk/src/zope/generic/type/metadirectives.py	2006-04-26 11:34:51 UTC (rev 67616)
+++ zope.generic/trunk/src/zope/generic/type/metadirectives.py	2006-04-26 13:33:11 UTC (rev 67617)
@@ -24,6 +24,7 @@
 from zope.generic.adapter.metadirectives import IOthersAdapterDirective
 from zope.generic.factory.metadirectives import IBaseFactoryDirective
 from zope.generic.informationprovider.metadirectives import IBaseInformationProviderDirective
+from zope.generic.handler.metadirectives import IBaseHandlerDirective
 from zope.generic.operation.metadirectives import IBaseOperationDirective
 
     
@@ -57,4 +58,7 @@
         description=_('If selected the type information are invoked.'),
         required=False,
         default=False
-        )
\ No newline at end of file
+        )
+
+class IHandlerSubdirective(IBaseHandlerDirective, IBaseOperationDirective):
+    """Provide object event handler for the keyface."""

Modified: zope.generic/trunk/src/zope/generic/type/testing.py
===================================================================
--- zope.generic/trunk/src/zope/generic/type/testing.py	2006-04-26 11:34:51 UTC (rev 67616)
+++ zope.generic/trunk/src/zope/generic/type/testing.py	2006-04-26 13:33:11 UTC (rev 67617)
@@ -22,9 +22,11 @@
 
 import zope.app.testing.placelesssetup
 
+import zope.generic.adapter.testing
 import zope.generic.configuration.testing
 import zope.generic.directlyprovides.testing
 import zope.generic.factory.testing
+import zope.generic.handler.testing
 import zope.generic.keyface.testing
 import zope.generic.operation.testing
 import zope.generic.testing.testing
@@ -68,6 +70,8 @@
         zope.generic.configuration.testing.setUp(doctest)
         zope.generic.operation.testing.setUp(doctest)
         zope.generic.factory.testing.setUp(doctest)
+        zope.generic.adapter.testing.setUp(doctest)
+        zope.generic.handler.testing.setUp(doctest)
         # internal setup
         setUp(doctest)
 
@@ -75,6 +79,8 @@
         # internal teardown
         tearDown(doctest)
         # external teardown
+        zope.generic.handler.testing.tearDown(doctest)
+        zope.generic.adapter.testing.tearDown(doctest)
         zope.generic.factory.testing.tearDown(doctest)
         zope.generic.operation.testing.tearDown(doctest)
         zope.generic.configuration.testing.tearDown(doctest)



More information about the Checkins mailing list