[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/component/fields.py
Bugfix: <browser:page layer=".relative_module_name.Layer" />
used to fail
Marius Gedminas
marius at pov.lt
Fri Sep 24 06:20:07 EDT 2004
Log message for revision 27671:
Bugfix: <browser:page layer=".relative_module_name.Layer" /> used to fail
with a ValueError: Empty module name.
Changed:
U Zope3/trunk/src/zope/app/component/fields.py
-=-
Modified: Zope3/trunk/src/zope/app/component/fields.py
===================================================================
--- Zope3/trunk/src/zope/app/component/fields.py 2004-09-24 09:13:26 UTC (rev 27670)
+++ Zope3/trunk/src/zope/app/component/fields.py 2004-09-24 10:20:07 UTC (rev 27671)
@@ -44,9 +44,12 @@
>>> layers = None
>>> class Resolver(object):
... def resolve(self, path):
- ... if path.startswith('zope.app.layers') and \
- ... hasattr(layers, 'layer1') or \
- ... path == 'zope.app.component.fields.layer1':
+ ... if '..' in path:
+ ... raise ValueError('Empty module name')
+ ... if (path.startswith('zope.app.layers') and
+ ... hasattr(layers, 'layer1') or
+ ... path == 'zope.app.component.fields.layer1' or
+ ... path == '.fields.layer1'):
... return layer1
... raise ConfigurationError, 'layer1'
@@ -77,12 +80,18 @@
Test 3: Get the layer from the utility service
----------------------------------------------
-
+
>>> from zope.app.tests import ztapi
>>> ztapi.provideUtility(ILayer, layer1, 'layer1')
>>> field.fromUnicode('layer1') is layer1
True
+
+ Test 4: Import the layer by using a short name
+ ----------------------------------------------
+
+ >>> field.fromUnicode('.fields.layer1') is layer1
+ True
"""
def fromUnicode(self, u):
@@ -93,17 +102,17 @@
except ComponentLookupError:
# The component architecture is not up and running.
pass
- else:
+ else:
if value is not None:
return value
try:
value = self.context.resolve('zope.app.layers.'+name)
- except ConfigurationError, v:
+ except (ConfigurationError, ValueError), v:
try:
value = self.context.resolve(name)
except ConfigurationError, v:
raise zope.schema.ValidationError(v)
-
+
self.validate(value)
return value
More information about the Zope3-Checkins
mailing list