-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Phil Ruggera
committed
Sep 2, 2004
1 parent
5559f3a
commit a8355db
Showing
13 changed files
with
785 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
############################################################################## | ||
# | ||
# 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.1 (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. | ||
# | ||
############################################################################## | ||
"""Find Support | ||
$Id$ | ||
""" | ||
__docformat__ = 'restructuredtext' | ||
|
||
from zope.interface import implements | ||
from interfaces import IFind, IIdFindFilter | ||
from interfaces import IReadContainer | ||
|
||
class FindAdapter(object): | ||
|
||
implements(IFind) | ||
|
||
__used_for__ = IReadContainer | ||
|
||
def __init__(self, context): | ||
self._context = context | ||
|
||
def find(self, id_filters=None, object_filters=None): | ||
'See IFind' | ||
id_filters = id_filters or [] | ||
object_filters = object_filters or [] | ||
result = [] | ||
container = self._context | ||
for id, object in container.items(): | ||
_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: | ||
# if we didn't break out of the loop, all filters matched | ||
result.append(object) | ||
|
||
if not IReadContainer.providedBy(object): | ||
return | ||
|
||
container = object | ||
for id, object in container.items(): | ||
_find_helper(id, object, container, id_filters, object_filters, result) | ||
|
||
class SimpleIdFindFilter(object): | ||
|
||
implements(IIdFindFilter) | ||
|
||
def __init__(self, ids): | ||
self._ids = ids | ||
|
||
def matches(self, id): | ||
'See INameFindFilter' | ||
return id in self._ids |
Oops, something went wrong.