7 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED |
7 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED |
8 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
8 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
9 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS |
9 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS |
10 # FOR A PARTICULAR PURPOSE. |
10 # FOR A PARTICULAR PURPOSE. |
11 # |
11 # |
|
12 # pylint: disable=no-name-in-module |
12 |
13 |
13 """PyAMS_utils.container module |
14 """PyAMS_utils.container module |
14 |
15 |
15 This module provides several classes, adapters and functions about containers. |
16 This module provides several classes, adapters and functions about containers. |
16 """ |
17 """ |
17 |
|
18 __docformat__ = 'restructuredtext' |
|
19 |
18 |
20 from BTrees.OOBTree import OOBTree |
19 from BTrees.OOBTree import OOBTree |
21 from persistent.list import PersistentList |
20 from persistent.list import PersistentList |
22 from pyramid.threadlocal import get_current_registry |
21 from pyramid.threadlocal import get_current_registry |
23 from zope.container.interfaces import IContained, IContainer |
22 from zope.container.interfaces import IContained, IContainer |
26 from zope.location.interfaces import ISublocations |
25 from zope.location.interfaces import ISublocations |
27 |
26 |
28 from pyams_utils.adapter import ContextAdapter, adapter_config |
27 from pyams_utils.adapter import ContextAdapter, adapter_config |
29 |
28 |
30 |
29 |
|
30 __docformat__ = 'restructuredtext' |
|
31 |
|
32 |
31 class BTreeOrderedContainer(OrderedContainer): |
33 class BTreeOrderedContainer(OrderedContainer): |
32 """BTree based ordered container |
34 """BTree based ordered container |
33 |
35 |
34 This container maintain a manual order of it's contents |
36 This container maintain a manual order of it's contents |
35 """ |
37 """ |
36 |
38 |
37 def __init__(self): |
39 def __init__(self): |
|
40 # pylint: disable=super-init-not-called |
38 self._data = OOBTree() |
41 self._data = OOBTree() |
39 self._order = PersistentList() |
42 self._order = PersistentList() |
40 |
43 |
41 |
44 |
42 class ParentSelector(object): |
45 class ParentSelector: |
43 """Interface based parent selector |
46 """Interface based parent selector |
44 |
47 |
45 This selector can be used as a subscriber predicate on IObjectAddedEvent to define |
48 This selector can be used as a subscriber predicate on IObjectAddedEvent to define |
46 an interface that the new parent must support for the event to be applied:: |
49 an interface that the new parent must support for the event to be applied:: |
47 |
50 |
53 def siteroot_object_added_event_handler(event): |
56 def siteroot_object_added_event_handler(event): |
54 '''This is an event handler for an ISiteRoot object added event''' |
57 '''This is an event handler for an ISiteRoot object added event''' |
55 """ |
58 """ |
56 |
59 |
57 def __init__(self, ifaces, config): |
60 def __init__(self, ifaces, config): |
|
61 # pylint: disable=unused-argument |
58 if not isinstance(ifaces, (list, tuple, set)): |
62 if not isinstance(ifaces, (list, tuple, set)): |
59 ifaces = (ifaces,) |
63 ifaces = (ifaces,) |
60 self.interfaces = ifaces |
64 self.interfaces = ifaces |
61 |
65 |
62 def text(self): |
66 def text(self): |
|
67 """Predicate string output""" |
63 return 'parent_selector = %s' % str(self.interfaces) |
68 return 'parent_selector = %s' % str(self.interfaces) |
64 |
69 |
65 phash = text |
70 phash = text |
66 |
71 |
67 def __call__(self, event): |
72 def __call__(self, event): |
117 """ |
122 """ |
118 if (not ignore_root) and condition(root): |
123 if (not ignore_root) and condition(root): |
119 yield root |
124 yield root |
120 locations = ISublocations(root, None) |
125 locations = ISublocations(root, None) |
121 if locations is not None: |
126 if locations is not None: |
122 for location in locations.sublocations(): |
127 for location in locations.sublocations(): # pylint: disable=too-many-function-args |
123 if condition(location): |
128 if condition(location): |
124 yield location |
129 yield location |
125 yield from find_objects_matching(location, condition, ignore_root=True) |
130 yield from find_objects_matching(location, condition, ignore_root=True) |
126 |
131 |
127 |
132 |