[Checkins] SVN: grok/trunk/ `create_application` util function now raises KeyError instead of DuplicationError, to match the ``zope.container`` behavior.
Souheil CHELFOUH
souheil at chelfouh.com
Sun Jul 4 08:35:13 EDT 2010
Log message for revision 114179:
`create_application` util function now raises KeyError instead of DuplicationError, to match the ``zope.container`` behavior.
Changed:
U grok/trunk/CHANGES.txt
U grok/trunk/src/grok/ftests/lifecycle/create_application.py
U grok/trunk/src/grok/util.py
-=-
Modified: grok/trunk/CHANGES.txt
===================================================================
--- grok/trunk/CHANGES.txt 2010-07-04 12:28:35 UTC (rev 114178)
+++ grok/trunk/CHANGES.txt 2010-07-04 12:35:13 UTC (rev 114179)
@@ -4,9 +4,10 @@
1.1 (unreleased)
================
-- Nothing changed yet.
+* `create_application` now raises a `KeyError`, in cases of key
+ duplication, to match the ``zope.container`` behavior. Tests have
+ been adapted accordingly.
-
1.1rc1 (2010-02-25)
===================
Modified: grok/trunk/src/grok/ftests/lifecycle/create_application.py
===================================================================
--- grok/trunk/src/grok/ftests/lifecycle/create_application.py 2010-07-04 12:28:35 UTC (rev 114178)
+++ grok/trunk/src/grok/ftests/lifecycle/create_application.py 2010-07-04 12:35:13 UTC (rev 114179)
@@ -38,7 +38,7 @@
>>> app = grok.util.create_application(Cave, root, 'mycave')
Traceback (most recent call last):
...
- DuplicationError: mycave
+ KeyError: 'mycave'
Please note that the `create_application` function will only accept
factories implementing IApplication::
Modified: grok/trunk/src/grok/util.py
===================================================================
--- grok/trunk/src/grok/util.py 2010-07-04 12:28:35 UTC (rev 114178)
+++ grok/trunk/src/grok/util.py 2010-07-04 12:35:13 UTC (rev 114179)
@@ -19,12 +19,12 @@
import zope.location.location
from zope import interface
from zope.schema.interfaces import WrongType
-from zope.exceptions.interfaces import DuplicationError
from zope.security.checker import NamesChecker, defineChecker
from grokcore.view.util import url
from grokcore.security.util import check_permission
+
def make_checker(factory, view_factory, permission, method_names=None):
"""Make a checker for a view_factory associated with factory.
@@ -65,6 +65,7 @@
ifaces.append(skin)
interface.directlyProvides(request, *ifaces)
+
def getApplication():
"""Return the nearest enclosing `grok.Application`.
@@ -82,6 +83,7 @@
obj = obj.__parent__
raise ValueError("No application found.")
+
def application_url(request, obj, name=None, data={}):
"""Return the URL of the nearest enclosing `grok.Application`.
@@ -89,6 +91,7 @@
"""
return url(request, getApplication(), name, data)
+
def create_application(factory, container, name):
"""Creates an application and triggers the events from
the application lifecycle.
@@ -99,7 +102,7 @@
# Check the availability of the name in the container.
if name in container:
- raise DuplicationError(name)
+ raise KeyError(name)
# Instanciate the application
application = factory()
@@ -108,7 +111,7 @@
grok.notify(grok.ObjectCreatedEvent(application))
# Persist the application.
- # This may raise a DuplicationError.
+ # This may raise a KeyError.
container[name] = application
# Trigger the initialization event.
More information about the checkins
mailing list