[Checkins] SVN: grok/branches/1.1/ Corrected the use of DuplicationError by adding it or replacing by KeyError.
Souheil CHELFOUH
souheil at chelfouh.com
Sun Jul 4 09:08:36 EDT 2010
Log message for revision 114183:
Corrected the use of DuplicationError by adding it or replacing by KeyError.
Changed:
U grok/branches/1.1/CHANGES.txt
U grok/branches/1.1/src/grok/ftests/catalog/indexes_multiple_conflict.py
U grok/branches/1.1/src/grok/ftests/lifecycle/create_application.py
U grok/branches/1.1/src/grok/meta.py
U grok/branches/1.1/src/grok/tests/container/orderedcontainer.py
U grok/branches/1.1/src/grok/util.py
-=-
Modified: grok/branches/1.1/CHANGES.txt
===================================================================
--- grok/branches/1.1/CHANGES.txt 2010-07-04 12:50:26 UTC (rev 114182)
+++ grok/branches/1.1/CHANGES.txt 2010-07-04 13:08:35 UTC (rev 114183)
@@ -4,8 +4,12 @@
1.1.2 (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.
+- Added `KeyError` error handling to the existing `DuplicationError`,
+ to fit the ``zope.container`` changes. Tests have been adapted accordingly.
1.1.1 (2010-05-30)
==================
Modified: grok/branches/1.1/src/grok/ftests/catalog/indexes_multiple_conflict.py
===================================================================
--- grok/branches/1.1/src/grok/ftests/catalog/indexes_multiple_conflict.py 2010-07-04 12:50:26 UTC (rev 114182)
+++ grok/branches/1.1/src/grok/ftests/catalog/indexes_multiple_conflict.py 2010-07-04 13:08:35 UTC (rev 114183)
@@ -9,8 +9,8 @@
>>> herd = Herd()
>>> getRootFolder()['herd'] = herd
Traceback (most recent call last):
- ...
- KeyError: u'name'
+ ...
+ GrokError: grok.Indexes in module <module 'grok.ftests.catalog.indexes_multiple_conflict' from ...> causes creation of catalog index 'name' in catalog u'', but an index with that name is already present.
>>> from zope.site.hooks import setSite
>>> setSite(herd)
Modified: grok/branches/1.1/src/grok/ftests/lifecycle/create_application.py
===================================================================
--- grok/branches/1.1/src/grok/ftests/lifecycle/create_application.py 2010-07-04 12:50:26 UTC (rev 114182)
+++ grok/branches/1.1/src/grok/ftests/lifecycle/create_application.py 2010-07-04 13:08:35 UTC (rev 114183)
@@ -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/branches/1.1/src/grok/meta.py
===================================================================
--- grok/branches/1.1/src/grok/meta.py 2010-07-04 12:50:26 UTC (rev 114182)
+++ grok/branches/1.1/src/grok/meta.py 2010-07-04 13:08:35 UTC (rev 114183)
@@ -362,7 +362,7 @@
for name, index in self.indexes.items():
try:
index.setup(catalog, name, self.context, self.module_info)
- except DuplicationError:
+ except (DuplicationError, KeyError):
raise GrokError(
"grok.Indexes in module %r causes "
"creation of catalog index %r in catalog %r, "
Modified: grok/branches/1.1/src/grok/tests/container/orderedcontainer.py
===================================================================
--- grok/branches/1.1/src/grok/tests/container/orderedcontainer.py 2010-07-04 12:50:26 UTC (rev 114182)
+++ grok/branches/1.1/src/grok/tests/container/orderedcontainer.py 2010-07-04 13:08:35 UTC (rev 114183)
@@ -52,7 +52,7 @@
>>> bones.keys()
['ankle', 'shin', 'thigh', 'toe']
-Adding a new object under an existing key, raises a DuplicationError::
+Adding a new object under an existing key, raises a KeyError::
>>> bones['shin'] = Bone('Another Shin Bone')
Traceback (most recent call last):
Modified: grok/branches/1.1/src/grok/util.py
===================================================================
--- grok/branches/1.1/src/grok/util.py 2010-07-04 12:50:26 UTC (rev 114182)
+++ grok/branches/1.1/src/grok/util.py 2010-07-04 13:08:35 UTC (rev 114183)
@@ -19,12 +19,11 @@
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 +64,7 @@
ifaces.append(skin)
interface.directlyProvides(request, *ifaces)
+
def getApplication():
"""Return the nearest enclosing `grok.Application`.
@@ -82,6 +82,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 +90,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 +101,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 +110,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