[Checkins] SVN: zope.app.dependable/trunk/ Moved CheckDependency event handler and its tests into this package from its former place in zope.container.
Hanno Schlichting
hannosch at hannosch.eu
Tue Dec 15 16:19:36 EST 2009
Log message for revision 106578:
Moved CheckDependency event handler and its tests into this package from its former place in zope.container.
Changed:
U zope.app.dependable/trunk/CHANGES.txt
U zope.app.dependable/trunk/setup.py
U zope.app.dependable/trunk/src/zope/app/dependable/configure.zcml
A zope.app.dependable/trunk/src/zope/app/dependable/dependency.py
U zope.app.dependable/trunk/src/zope/app/dependable/tests.py
-=-
Modified: zope.app.dependable/trunk/CHANGES.txt
===================================================================
--- zope.app.dependable/trunk/CHANGES.txt 2009-12-15 20:58:15 UTC (rev 106577)
+++ zope.app.dependable/trunk/CHANGES.txt 2009-12-15 21:19:35 UTC (rev 106578)
@@ -2,6 +2,12 @@
CHANGES
=======
+3.5.0 (unreleased)
+------------------
+
+- Moved CheckDependency event handler and its tests into this package from
+ its former place in zope.container.
+
3.4.0 (2007-10-23)
------------------
Modified: zope.app.dependable/trunk/setup.py
===================================================================
--- zope.app.dependable/trunk/setup.py 2009-12-15 20:58:15 UTC (rev 106577)
+++ zope.app.dependable/trunk/setup.py 2009-12-15 21:19:35 UTC (rev 106578)
@@ -27,9 +27,9 @@
return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
setup(name='zope.app.dependable',
- version = '3.4.1',
+ version = '3.5.0dev',
author='Zope Corporation and Contributors',
- author_email='zope3-dev at zope.org',
+ author_email='zope-dev at zope.org',
description='Simple Dependency API',
long_description=(
read('README.txt')
@@ -47,17 +47,20 @@
'Operating System :: OS Independent',
'Topic :: Internet :: WWW/HTTP',
'Framework :: Zope3'],
- url='http://cheeseshop.python.org/pypi/zope.app.dependable',
+ url='http://pypi.python.org/pypi/zope.app.dependable',
license='ZPL 2.1',
packages=find_packages('src'),
package_dir = {'': 'src'},
namespace_packages=['zope', 'zope.app'],
extras_require=dict(test=['zope.app.testing']),
install_requires=['setuptools',
+ 'zope.annotation',
+ 'zope.exceptions',
+ 'zope.i18nmessageid',
'zope.interface',
+ 'zope.lifecycleevent',
+ 'zope.location',
'zope.traversing',
- 'zope.annotation',
- 'zope.exceptions',
],
include_package_data = True,
zip_safe = False,
Modified: zope.app.dependable/trunk/src/zope/app/dependable/configure.zcml
===================================================================
--- zope.app.dependable/trunk/src/zope/app/dependable/configure.zcml 2009-12-15 20:58:15 UTC (rev 106577)
+++ zope.app.dependable/trunk/src/zope/app/dependable/configure.zcml 2009-12-15 21:19:35 UTC (rev 106578)
@@ -7,4 +7,11 @@
provides="zope.app.dependable.interfaces.IDependable"
for="zope.annotation.interfaces.IAnnotatable" />
-</configure>
\ No newline at end of file
+ <subscriber
+ zcml:condition="installed zope.container"
+ handler=".dependency.CheckDependency"
+ for="zope.lifecycleevent.interfaces.IObjectRemovedEvent"
+ trusted="y"
+ />
+
+</configure>
Added: zope.app.dependable/trunk/src/zope/app/dependable/dependency.py
===================================================================
--- zope.app.dependable/trunk/src/zope/app/dependable/dependency.py (rev 0)
+++ zope.app.dependable/trunk/src/zope/app/dependable/dependency.py 2009-12-15 21:19:35 UTC (rev 106578)
@@ -0,0 +1,47 @@
+##############################################################################
+#
+# Copyright (c) 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.
+#
+##############################################################################
+
+"""Subscriber function checking dependencies if a removal is performed
+on an object having dependencies. It raises an exception if it's the
+case.
+"""
+__docformat__ = 'restructuredtext'
+
+from zope.i18nmessageid import Message
+from zope.i18nmessageid import MessageFactory
+from zope.location.interfaces import ILocationInfo
+
+from zope.app.dependable.interfaces import IDependable, DependencyError
+
+_ = MessageFactory('zope')
+
+exception_msg = _("""
+Removal of object (${object}) which has dependents (${dependents})
+is not possible !
+
+You must deactivate this object before trying to remove it.
+""")
+
+def CheckDependency(event):
+ object = event.object
+ dependency = IDependable(object, None)
+ if dependency is not None:
+ dependents = dependency.dependents()
+ if dependents:
+ mapping = {
+ "object": ILocationInfo(object).getPath(),
+ "dependents": ", ".join(dependents)
+ }
+ raise DependencyError(Message(exception_msg, mapping=mapping))
+
Property changes on: zope.app.dependable/trunk/src/zope/app/dependable/dependency.py
___________________________________________________________________
Added: svn:eol-style
+ native
Modified: zope.app.dependable/trunk/src/zope/app/dependable/tests.py
===================================================================
--- zope.app.dependable/trunk/src/zope/app/dependable/tests.py 2009-12-15 20:58:15 UTC (rev 106577)
+++ zope.app.dependable/trunk/src/zope/app/dependable/tests.py 2009-12-15 21:19:35 UTC (rev 106578)
@@ -16,12 +16,32 @@
$Id$
"""
from unittest import TestCase, TestSuite, main, makeSuite
+
from zope.annotation.attribute import AttributeAnnotations
from zope.app.testing.placelesssetup import PlacelessSetup
+from zope.interface import implements
+from zope.lifecycleevent import ObjectRemovedEvent
+from zope.traversing.interfaces import IPhysicallyLocatable
+from zope.app.dependable.dependency import CheckDependency
+from zope.app.dependable.interfaces import IDependable, DependencyError
+
+
class C(object):
pass
+
+class DummyObject(object):
+
+ implements(IDependable, IPhysicallyLocatable)
+
+ def dependents(self):
+ return ['dependency1', 'dependency2']
+
+ def getPath(self):
+ return '/dummy-object'
+
+
class Test(PlacelessSetup, TestCase):
def factory(self):
@@ -67,6 +87,13 @@
obj.removeDependent("bar")
self.assertEqual(obj.dependents(), ())
+ def testCheckDependency(self):
+ obj = DummyObject()
+ parent = object()
+ event = ObjectRemovedEvent(obj, parent, 'oldName')
+ self.assertRaises(DependencyError, CheckDependency, event)
+
+
def test_suite():
return TestSuite((
makeSuite(Test),
More information about the checkins
mailing list