[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/OFS/Container/Find - FindAdapter.py:1.1.2.1 IFind.py:1.1.2.1 __init__.py:1.1.2.1 find.zcml:1.1.2.1
Martijn Faassen
m.faassen@vet.uu.nl
Tue, 9 Apr 2002 11:24:33 -0400
Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/Container/Find
In directory cvs.zope.org:/tmp/cvs-serv21631/OFS/Container/Find
Added Files:
Tag: Zope-3x-branch
FindAdapter.py IFind.py __init__.py find.zcml
Log Message:
Added a basic framework for finding objects. The UI right now only exposes
looking for ids (see find;view).
=== Added File Zope3/lib/python/Zope/App/OFS/Container/Find/FindAdapter.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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.
#
##############################################################################
"""
$Id: FindAdapter.py,v 1.1.2.1 2002/04/09 15:24:30 faassen Exp $
"""
from Zope.App.OFS.Container.Find.IFind import IFind, IIdFindFilter
from Zope.App.OFS.Container.IContainer import IReadContainer
# XXX need to do this manually to wrap objects
from Zope.ContextWrapper import Wrapper
class FindAdapter(object):
__implements__ = IFind
__used_for__ = IReadContainer
def __init__(self, context):
self._context = context
############################################################
# Implementation methods for interface
# Zope.App.OFS.Container.Find.IFind.IFind
def find(self, id_filters=None, object_filters=None):
'See Zope.App.OFS.Container.Find.IFind.IFind'
id_filters = id_filters or []
object_filters = object_filters or []
result = []
container = self._context
for id, object in container.objectItems():
_find_helper(id, object, container,
id_filters, object_filters,
result)
return result
#
############################################################
def _find_helper(id, object, container, id_filters, object_filters, result):
for id_filter in id_filters:
if not id_filter.matches(id):
break
else:
# if we didn't break out of the loop, all name filters matched
# now check all object filters
for object_filter in object_filters:
if not object_filter.matches(object):
break
else:
# XXX wrap object
object = Wrapper(object, container, name=id)
# if we didn't break out of the loop, all filters matched
result.append(object)
if not IReadContainer.isImplementedBy(object):
return
container = object
for id, object in container.objectItems():
_find_helper(id, object, container, id_filters, object_filters, result)
class SimpleIdFindFilter(object):
__implements__ = IIdFindFilter
def __init__(self, ids):
self._ids = ids
############################################################
# Implementation methods for interface
# Zope.App.OFS.Container.Find.IFind.INameFindFilter
def matches(self, id):
'See Zope.App.OFS.Container.Find.IFind.INameFindFilter'
return id in self._ids
#
############################################################
=== Added File Zope3/lib/python/Zope/App/OFS/Container/Find/IFind.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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.
#
##############################################################################
"""
$Id: IFind.py,v 1.1.2.1 2002/04/09 15:24:30 faassen Exp $
"""
from Interface import Interface
class IFind(Interface):
"""
Find support for containers.
"""
def find(id_filters=None, object_filters=None):
"""Find object that matches all filters in all sub objects,
not including this container itself.
"""
class IObjectFindFilter(Interface):
def matches(object):
"""Returns true if the object matches the filter criteria.
"""
class IIdFindFilter(Interface):
def matches(id):
"""Returns true if the id matches the filter criteria.
"""
=== Added File Zope3/lib/python/Zope/App/OFS/Container/Find/__init__.py ===
# make this a package
=== Added File Zope3/lib/python/Zope/App/OFS/Container/Find/find.zcml ===
<zopeConfigure
xmlns='http://namespaces.zope.org/zope'
xmlns:security='http://namespaces.zope.org/security'
>
<security:protectClass
name=".FindAdapter."
permission_id="Zope.ManageContent"
interface=".IFind." />
<adapter
provides=".IFind."
for="Zope.App.OFS.Container.IContainer.IReadContainer"
factory=".FindAdapter." />
<include package=".Views" file="views.zcml" />
</zopeConfigure>