[Zope3-checkins] CVS: Zope3/src/zope/app/services - field.py:1.9
Jim Fulton
jim@zope.com
Mon, 30 Jun 2003 12:24:04 -0400
Update of /cvs-repository/Zope3/src/zope/app/services
In directory cvs.zope.org:/tmp/cvs-serv18263/src/zope/app/services
Modified Files:
field.py
Log Message:
Removed unused component location field and associated widgets and
tests.
=== Zope3/src/zope/app/services/field.py 1.8 => 1.9 ===
--- Zope3/src/zope/app/services/field.py:1.8 Sat Jun 7 01:31:58 2003
+++ Zope3/src/zope/app/services/field.py Mon Jun 30 12:23:33 2003
@@ -17,13 +17,11 @@
"""
__metaclass__ = type
+from zope.app import zapi
from zope.schema import Field
from zope.schema.interfaces import ValidationError
-from zope.app.traversing import traverse
from zope.exceptions import NotFoundError
from zope.app.interfaces.services.field import IComponentPath
-from zope.app.interfaces.services.field import IComponentLocation
-from zope.component import getServiceManager, getAdapter
from zope.app.interfaces.services.module import IModuleService
from zope.interface import implements
@@ -44,57 +42,10 @@
raise ValidationError("Not an absolute path", value)
try:
- component = traverse(self.context, value)
+ component = zapi.traverse(self.context, value)
except NotFoundError:
raise ValidationError("Path for non-existent object", value)
if not self.type.isImplementedBy(component):
raise ValidationError("Wrong component type", value)
-class ComponentLocation(Field):
-
- implements(IComponentLocation)
-
- _type = unicode
-
- def __init__(self, type, *args, **kw):
- self.type = type
- super(ComponentLocation, self).__init__(*args, **kw)
-
- def _validate(self, value):
- super(ComponentLocation, self)._validate(value)
- component = locateComponent(value, self.context, self.type)
-
-
-def locateComponent(location, context, interface=None):
- '''Locate a component by traversal, or by a dotted module name.
-
- If 'interface' is given, check that the located componenent implements
- the given interface.
- '''
- if location.startswith('/'):
- try:
- component = traverse(context, location)
- except NotFoundError:
- raise ValidationError('Path for non-existent object', location)
- else:
- # Assume location is a dotted module name
- if location.startswith('.'):
- # Catch the error of thinking that this is just like
- # a leading dot in zcml.
- raise ValidationError(
- "Module name must not start with a '.'", location)
- # XXX Need to be careful here. Jim was going to look
- # at whether a checkedResolve method is needed.
- servicemanager = getServiceManager(context)
- resolver = getAdapter(servicemanager, IModuleService)
- try:
- component = resolver.resolve(location)
- except ImportError:
- raise ValidationError("Cannot resolve module name", location)
-
- if interface is not None and not interface.isImplementedBy(component):
- raise ValidationError(
- 'Component must be %s' % interface, location)
-
- return component