Mercurial > hg
annotate mercurial/thirdparty/zope/interface/adapter.py @ 51017:edc44ab7437a
debug-revlog: keep the revlog open for the analysis duration
This is more explicit. No performance differences were observed.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Mon, 25 Sep 2023 16:57:53 +0200 |
parents | 68ee61822182 |
children |
rev | line source |
---|---|
37176
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1 ############################################################################## |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2 # |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3 # Copyright (c) 2004 Zope Foundation and Contributors. |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
4 # All Rights Reserved. |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
5 # |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
6 # This software is subject to the provisions of the Zope Public License, |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
7 # Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
8 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
9 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
10 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
11 # FOR A PARTICULAR PURPOSE. |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
12 # |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
13 ############################################################################## |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
14 """Adapter management |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
15 """ |
37178
68ee61822182
thirdparty: port zope.interface to relative imports
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37176
diff
changeset
|
16 from __future__ import absolute_import |
68ee61822182
thirdparty: port zope.interface to relative imports
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37176
diff
changeset
|
17 |
37176
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
18 import weakref |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
19 |
37178
68ee61822182
thirdparty: port zope.interface to relative imports
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37176
diff
changeset
|
20 from . import implementer |
68ee61822182
thirdparty: port zope.interface to relative imports
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37176
diff
changeset
|
21 from . import providedBy |
68ee61822182
thirdparty: port zope.interface to relative imports
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37176
diff
changeset
|
22 from . import Interface |
68ee61822182
thirdparty: port zope.interface to relative imports
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37176
diff
changeset
|
23 from . import ro |
68ee61822182
thirdparty: port zope.interface to relative imports
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37176
diff
changeset
|
24 from .interfaces import IAdapterRegistry |
37176
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
25 |
37178
68ee61822182
thirdparty: port zope.interface to relative imports
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37176
diff
changeset
|
26 from ._compat import _normalize_name |
68ee61822182
thirdparty: port zope.interface to relative imports
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37176
diff
changeset
|
27 from ._compat import STRING_TYPES |
37176
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
28 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
29 _BLANK = u'' |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
30 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
31 class BaseAdapterRegistry(object): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
32 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
33 # List of methods copied from lookup sub-objects: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
34 _delegated = ('lookup', 'queryMultiAdapter', 'lookup1', 'queryAdapter', |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
35 'adapter_hook', 'lookupAll', 'names', |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
36 'subscriptions', 'subscribers') |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
37 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
38 # All registries maintain a generation that can be used by verifying |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
39 # registries |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
40 _generation = 0 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
41 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
42 def __init__(self, bases=()): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
43 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
44 # The comments here could be improved. Possibly this bit needs |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
45 # explaining in a separate document, as the comments here can |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
46 # be quite confusing. /regebro |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
47 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
48 # {order -> {required -> {provided -> {name -> value}}}} |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
49 # Here "order" is actually an index in a list, "required" and |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
50 # "provided" are interfaces, and "required" is really a nested |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
51 # key. So, for example: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
52 # for order == 0 (that is, self._adapters[0]), we have: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
53 # {provided -> {name -> value}} |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
54 # but for order == 2 (that is, self._adapters[2]), we have: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
55 # {r1 -> {r2 -> {provided -> {name -> value}}}} |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
56 # |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
57 self._adapters = [] |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
58 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
59 # {order -> {required -> {provided -> {name -> [value]}}}} |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
60 # where the remarks about adapters above apply |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
61 self._subscribers = [] |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
62 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
63 # Set, with a reference count, keeping track of the interfaces |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
64 # for which we have provided components: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
65 self._provided = {} |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
66 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
67 # Create ``_v_lookup`` object to perform lookup. We make this a |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
68 # separate object to to make it easier to implement just the |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
69 # lookup functionality in C. This object keeps track of cache |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
70 # invalidation data in two kinds of registries. |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
71 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
72 # Invalidating registries have caches that are invalidated |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
73 # when they or their base registies change. An invalidating |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
74 # registry can only have invalidating registries as bases. |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
75 # See LookupBaseFallback below for the pertinent logic. |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
76 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
77 # Verifying registies can't rely on getting invalidation messages, |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
78 # so have to check the generations of base registries to determine |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
79 # if their cache data are current. See VerifyingBasePy below |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
80 # for the pertinent object. |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
81 self._createLookup() |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
82 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
83 # Setting the bases causes the registries described above |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
84 # to be initialized (self._setBases -> self.changed -> |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
85 # self._v_lookup.changed). |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
86 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
87 self.__bases__ = bases |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
88 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
89 def _setBases(self, bases): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
90 self.__dict__['__bases__'] = bases |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
91 self.ro = ro.ro(self) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
92 self.changed(self) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
93 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
94 __bases__ = property(lambda self: self.__dict__['__bases__'], |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
95 lambda self, bases: self._setBases(bases), |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
96 ) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
97 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
98 def _createLookup(self): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
99 self._v_lookup = self.LookupClass(self) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
100 for name in self._delegated: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
101 self.__dict__[name] = getattr(self._v_lookup, name) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
102 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
103 def changed(self, originally_changed): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
104 self._generation += 1 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
105 self._v_lookup.changed(originally_changed) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
106 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
107 def register(self, required, provided, name, value): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
108 if not isinstance(name, STRING_TYPES): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
109 raise ValueError('name is not a string') |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
110 if value is None: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
111 self.unregister(required, provided, name, value) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
112 return |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
113 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
114 required = tuple(map(_convert_None_to_Interface, required)) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
115 name = _normalize_name(name) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
116 order = len(required) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
117 byorder = self._adapters |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
118 while len(byorder) <= order: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
119 byorder.append({}) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
120 components = byorder[order] |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
121 key = required + (provided,) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
122 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
123 for k in key: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
124 d = components.get(k) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
125 if d is None: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
126 d = {} |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
127 components[k] = d |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
128 components = d |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
129 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
130 if components.get(name) is value: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
131 return |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
132 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
133 components[name] = value |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
134 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
135 n = self._provided.get(provided, 0) + 1 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
136 self._provided[provided] = n |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
137 if n == 1: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
138 self._v_lookup.add_extendor(provided) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
139 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
140 self.changed(self) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
141 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
142 def registered(self, required, provided, name=_BLANK): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
143 required = tuple(map(_convert_None_to_Interface, required)) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
144 name = _normalize_name(name) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
145 order = len(required) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
146 byorder = self._adapters |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
147 if len(byorder) <= order: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
148 return None |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
149 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
150 components = byorder[order] |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
151 key = required + (provided,) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
152 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
153 for k in key: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
154 d = components.get(k) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
155 if d is None: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
156 return None |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
157 components = d |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
158 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
159 return components.get(name) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
160 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
161 def unregister(self, required, provided, name, value=None): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
162 required = tuple(map(_convert_None_to_Interface, required)) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
163 order = len(required) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
164 byorder = self._adapters |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
165 if order >= len(byorder): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
166 return False |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
167 components = byorder[order] |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
168 key = required + (provided,) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
169 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
170 # Keep track of how we got to `components`: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
171 lookups = [] |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
172 for k in key: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
173 d = components.get(k) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
174 if d is None: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
175 return |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
176 lookups.append((components, k)) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
177 components = d |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
178 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
179 old = components.get(name) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
180 if old is None: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
181 return |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
182 if (value is not None) and (old is not value): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
183 return |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
184 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
185 del components[name] |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
186 if not components: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
187 # Clean out empty containers, since we don't want our keys |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
188 # to reference global objects (interfaces) unnecessarily. |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
189 # This is often a problem when an interface is slated for |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
190 # removal; a hold-over entry in the registry can make it |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
191 # difficult to remove such interfaces. |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
192 for comp, k in reversed(lookups): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
193 d = comp[k] |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
194 if d: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
195 break |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
196 else: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
197 del comp[k] |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
198 while byorder and not byorder[-1]: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
199 del byorder[-1] |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
200 n = self._provided[provided] - 1 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
201 if n == 0: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
202 del self._provided[provided] |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
203 self._v_lookup.remove_extendor(provided) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
204 else: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
205 self._provided[provided] = n |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
206 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
207 self.changed(self) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
208 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
209 def subscribe(self, required, provided, value): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
210 required = tuple(map(_convert_None_to_Interface, required)) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
211 name = _BLANK |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
212 order = len(required) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
213 byorder = self._subscribers |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
214 while len(byorder) <= order: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
215 byorder.append({}) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
216 components = byorder[order] |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
217 key = required + (provided,) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
218 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
219 for k in key: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
220 d = components.get(k) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
221 if d is None: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
222 d = {} |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
223 components[k] = d |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
224 components = d |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
225 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
226 components[name] = components.get(name, ()) + (value, ) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
227 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
228 if provided is not None: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
229 n = self._provided.get(provided, 0) + 1 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
230 self._provided[provided] = n |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
231 if n == 1: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
232 self._v_lookup.add_extendor(provided) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
233 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
234 self.changed(self) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
235 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
236 def unsubscribe(self, required, provided, value=None): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
237 required = tuple(map(_convert_None_to_Interface, required)) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
238 order = len(required) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
239 byorder = self._subscribers |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
240 if order >= len(byorder): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
241 return |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
242 components = byorder[order] |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
243 key = required + (provided,) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
244 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
245 # Keep track of how we got to `components`: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
246 lookups = [] |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
247 for k in key: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
248 d = components.get(k) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
249 if d is None: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
250 return |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
251 lookups.append((components, k)) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
252 components = d |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
253 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
254 old = components.get(_BLANK) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
255 if not old: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
256 # this is belt-and-suspenders against the failure of cleanup below |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
257 return # pragma: no cover |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
258 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
259 if value is None: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
260 new = () |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
261 else: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
262 new = tuple([v for v in old if v is not value]) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
263 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
264 if new == old: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
265 return |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
266 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
267 if new: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
268 components[_BLANK] = new |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
269 else: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
270 # Instead of setting components[_BLANK] = new, we clean out |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
271 # empty containers, since we don't want our keys to |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
272 # reference global objects (interfaces) unnecessarily. This |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
273 # is often a problem when an interface is slated for |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
274 # removal; a hold-over entry in the registry can make it |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
275 # difficult to remove such interfaces. |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
276 del components[_BLANK] |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
277 for comp, k in reversed(lookups): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
278 d = comp[k] |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
279 if d: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
280 break |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
281 else: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
282 del comp[k] |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
283 while byorder and not byorder[-1]: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
284 del byorder[-1] |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
285 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
286 if provided is not None: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
287 n = self._provided[provided] + len(new) - len(old) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
288 if n == 0: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
289 del self._provided[provided] |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
290 self._v_lookup.remove_extendor(provided) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
291 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
292 self.changed(self) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
293 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
294 # XXX hack to fake out twisted's use of a private api. We need to get them |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
295 # to use the new registed method. |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
296 def get(self, _): # pragma: no cover |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
297 class XXXTwistedFakeOut: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
298 selfImplied = {} |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
299 return XXXTwistedFakeOut |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
300 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
301 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
302 _not_in_mapping = object() |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
303 class LookupBaseFallback(object): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
304 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
305 def __init__(self): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
306 self._cache = {} |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
307 self._mcache = {} |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
308 self._scache = {} |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
309 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
310 def changed(self, ignored=None): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
311 self._cache.clear() |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
312 self._mcache.clear() |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
313 self._scache.clear() |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
314 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
315 def _getcache(self, provided, name): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
316 cache = self._cache.get(provided) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
317 if cache is None: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
318 cache = {} |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
319 self._cache[provided] = cache |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
320 if name: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
321 c = cache.get(name) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
322 if c is None: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
323 c = {} |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
324 cache[name] = c |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
325 cache = c |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
326 return cache |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
327 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
328 def lookup(self, required, provided, name=_BLANK, default=None): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
329 if not isinstance(name, STRING_TYPES): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
330 raise ValueError('name is not a string') |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
331 cache = self._getcache(provided, name) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
332 required = tuple(required) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
333 if len(required) == 1: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
334 result = cache.get(required[0], _not_in_mapping) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
335 else: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
336 result = cache.get(tuple(required), _not_in_mapping) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
337 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
338 if result is _not_in_mapping: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
339 result = self._uncached_lookup(required, provided, name) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
340 if len(required) == 1: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
341 cache[required[0]] = result |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
342 else: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
343 cache[tuple(required)] = result |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
344 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
345 if result is None: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
346 return default |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
347 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
348 return result |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
349 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
350 def lookup1(self, required, provided, name=_BLANK, default=None): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
351 if not isinstance(name, STRING_TYPES): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
352 raise ValueError('name is not a string') |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
353 cache = self._getcache(provided, name) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
354 result = cache.get(required, _not_in_mapping) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
355 if result is _not_in_mapping: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
356 return self.lookup((required, ), provided, name, default) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
357 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
358 if result is None: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
359 return default |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
360 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
361 return result |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
362 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
363 def queryAdapter(self, object, provided, name=_BLANK, default=None): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
364 return self.adapter_hook(provided, object, name, default) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
365 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
366 def adapter_hook(self, provided, object, name=_BLANK, default=None): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
367 if not isinstance(name, STRING_TYPES): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
368 raise ValueError('name is not a string') |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
369 required = providedBy(object) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
370 cache = self._getcache(provided, name) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
371 factory = cache.get(required, _not_in_mapping) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
372 if factory is _not_in_mapping: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
373 factory = self.lookup((required, ), provided, name) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
374 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
375 if factory is not None: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
376 result = factory(object) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
377 if result is not None: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
378 return result |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
379 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
380 return default |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
381 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
382 def lookupAll(self, required, provided): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
383 cache = self._mcache.get(provided) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
384 if cache is None: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
385 cache = {} |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
386 self._mcache[provided] = cache |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
387 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
388 required = tuple(required) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
389 result = cache.get(required, _not_in_mapping) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
390 if result is _not_in_mapping: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
391 result = self._uncached_lookupAll(required, provided) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
392 cache[required] = result |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
393 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
394 return result |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
395 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
396 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
397 def subscriptions(self, required, provided): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
398 cache = self._scache.get(provided) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
399 if cache is None: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
400 cache = {} |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
401 self._scache[provided] = cache |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
402 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
403 required = tuple(required) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
404 result = cache.get(required, _not_in_mapping) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
405 if result is _not_in_mapping: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
406 result = self._uncached_subscriptions(required, provided) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
407 cache[required] = result |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
408 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
409 return result |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
410 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
411 LookupBasePy = LookupBaseFallback # BBB |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
412 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
413 try: |
37178
68ee61822182
thirdparty: port zope.interface to relative imports
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37176
diff
changeset
|
414 from ._zope_interface_coptimizations import LookupBase |
37176
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
415 except ImportError: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
416 LookupBase = LookupBaseFallback |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
417 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
418 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
419 class VerifyingBaseFallback(LookupBaseFallback): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
420 # Mixin for lookups against registries which "chain" upwards, and |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
421 # whose lookups invalidate their own caches whenever a parent registry |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
422 # bumps its own '_generation' counter. E.g., used by |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
423 # zope.component.persistentregistry |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
424 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
425 def changed(self, originally_changed): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
426 LookupBaseFallback.changed(self, originally_changed) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
427 self._verify_ro = self._registry.ro[1:] |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
428 self._verify_generations = [r._generation for r in self._verify_ro] |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
429 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
430 def _verify(self): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
431 if ([r._generation for r in self._verify_ro] |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
432 != self._verify_generations): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
433 self.changed(None) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
434 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
435 def _getcache(self, provided, name): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
436 self._verify() |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
437 return LookupBaseFallback._getcache(self, provided, name) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
438 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
439 def lookupAll(self, required, provided): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
440 self._verify() |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
441 return LookupBaseFallback.lookupAll(self, required, provided) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
442 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
443 def subscriptions(self, required, provided): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
444 self._verify() |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
445 return LookupBaseFallback.subscriptions(self, required, provided) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
446 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
447 VerifyingBasePy = VerifyingBaseFallback #BBB |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
448 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
449 try: |
37178
68ee61822182
thirdparty: port zope.interface to relative imports
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37176
diff
changeset
|
450 from ._zope_interface_coptimizations import VerifyingBase |
37176
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
451 except ImportError: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
452 VerifyingBase = VerifyingBaseFallback |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
453 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
454 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
455 class AdapterLookupBase(object): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
456 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
457 def __init__(self, registry): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
458 self._registry = registry |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
459 self._required = {} |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
460 self.init_extendors() |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
461 super(AdapterLookupBase, self).__init__() |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
462 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
463 def changed(self, ignored=None): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
464 super(AdapterLookupBase, self).changed(None) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
465 for r in self._required.keys(): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
466 r = r() |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
467 if r is not None: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
468 r.unsubscribe(self) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
469 self._required.clear() |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
470 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
471 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
472 # Extendors |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
473 # --------- |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
474 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
475 # When given an target interface for an adapter lookup, we need to consider |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
476 # adapters for interfaces that extend the target interface. This is |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
477 # what the extendors dictionary is about. It tells us all of the |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
478 # interfaces that extend an interface for which there are adapters |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
479 # registered. |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
480 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
481 # We could separate this by order and name, thus reducing the |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
482 # number of provided interfaces to search at run time. The tradeoff, |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
483 # however, is that we have to store more information. For example, |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
484 # if the same interface is provided for multiple names and if the |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
485 # interface extends many interfaces, we'll have to keep track of |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
486 # a fair bit of information for each name. It's better to |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
487 # be space efficient here and be time efficient in the cache |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
488 # implementation. |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
489 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
490 # TODO: add invalidation when a provided interface changes, in case |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
491 # the interface's __iro__ has changed. This is unlikely enough that |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
492 # we'll take our chances for now. |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
493 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
494 def init_extendors(self): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
495 self._extendors = {} |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
496 for p in self._registry._provided: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
497 self.add_extendor(p) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
498 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
499 def add_extendor(self, provided): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
500 _extendors = self._extendors |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
501 for i in provided.__iro__: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
502 extendors = _extendors.get(i, ()) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
503 _extendors[i] = ( |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
504 [e for e in extendors if provided.isOrExtends(e)] |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
505 + |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
506 [provided] |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
507 + |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
508 [e for e in extendors if not provided.isOrExtends(e)] |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
509 ) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
510 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
511 def remove_extendor(self, provided): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
512 _extendors = self._extendors |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
513 for i in provided.__iro__: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
514 _extendors[i] = [e for e in _extendors.get(i, ()) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
515 if e != provided] |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
516 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
517 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
518 def _subscribe(self, *required): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
519 _refs = self._required |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
520 for r in required: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
521 ref = r.weakref() |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
522 if ref not in _refs: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
523 r.subscribe(self) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
524 _refs[ref] = 1 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
525 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
526 def _uncached_lookup(self, required, provided, name=_BLANK): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
527 required = tuple(required) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
528 result = None |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
529 order = len(required) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
530 for registry in self._registry.ro: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
531 byorder = registry._adapters |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
532 if order >= len(byorder): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
533 continue |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
534 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
535 extendors = registry._v_lookup._extendors.get(provided) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
536 if not extendors: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
537 continue |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
538 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
539 components = byorder[order] |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
540 result = _lookup(components, required, extendors, name, 0, |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
541 order) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
542 if result is not None: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
543 break |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
544 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
545 self._subscribe(*required) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
546 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
547 return result |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
548 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
549 def queryMultiAdapter(self, objects, provided, name=_BLANK, default=None): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
550 factory = self.lookup(map(providedBy, objects), provided, name) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
551 if factory is None: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
552 return default |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
553 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
554 result = factory(*objects) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
555 if result is None: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
556 return default |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
557 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
558 return result |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
559 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
560 def _uncached_lookupAll(self, required, provided): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
561 required = tuple(required) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
562 order = len(required) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
563 result = {} |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
564 for registry in reversed(self._registry.ro): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
565 byorder = registry._adapters |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
566 if order >= len(byorder): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
567 continue |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
568 extendors = registry._v_lookup._extendors.get(provided) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
569 if not extendors: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
570 continue |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
571 components = byorder[order] |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
572 _lookupAll(components, required, extendors, result, 0, order) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
573 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
574 self._subscribe(*required) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
575 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
576 return tuple(result.items()) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
577 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
578 def names(self, required, provided): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
579 return [c[0] for c in self.lookupAll(required, provided)] |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
580 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
581 def _uncached_subscriptions(self, required, provided): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
582 required = tuple(required) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
583 order = len(required) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
584 result = [] |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
585 for registry in reversed(self._registry.ro): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
586 byorder = registry._subscribers |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
587 if order >= len(byorder): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
588 continue |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
589 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
590 if provided is None: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
591 extendors = (provided, ) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
592 else: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
593 extendors = registry._v_lookup._extendors.get(provided) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
594 if extendors is None: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
595 continue |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
596 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
597 _subscriptions(byorder[order], required, extendors, _BLANK, |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
598 result, 0, order) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
599 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
600 self._subscribe(*required) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
601 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
602 return result |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
603 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
604 def subscribers(self, objects, provided): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
605 subscriptions = self.subscriptions(map(providedBy, objects), provided) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
606 if provided is None: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
607 result = () |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
608 for subscription in subscriptions: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
609 subscription(*objects) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
610 else: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
611 result = [] |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
612 for subscription in subscriptions: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
613 subscriber = subscription(*objects) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
614 if subscriber is not None: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
615 result.append(subscriber) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
616 return result |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
617 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
618 class AdapterLookup(AdapterLookupBase, LookupBase): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
619 pass |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
620 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
621 @implementer(IAdapterRegistry) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
622 class AdapterRegistry(BaseAdapterRegistry): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
623 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
624 LookupClass = AdapterLookup |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
625 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
626 def __init__(self, bases=()): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
627 # AdapterRegisties are invalidating registries, so |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
628 # we need to keep track of out invalidating subregistries. |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
629 self._v_subregistries = weakref.WeakKeyDictionary() |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
630 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
631 super(AdapterRegistry, self).__init__(bases) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
632 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
633 def _addSubregistry(self, r): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
634 self._v_subregistries[r] = 1 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
635 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
636 def _removeSubregistry(self, r): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
637 if r in self._v_subregistries: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
638 del self._v_subregistries[r] |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
639 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
640 def _setBases(self, bases): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
641 old = self.__dict__.get('__bases__', ()) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
642 for r in old: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
643 if r not in bases: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
644 r._removeSubregistry(self) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
645 for r in bases: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
646 if r not in old: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
647 r._addSubregistry(self) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
648 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
649 super(AdapterRegistry, self)._setBases(bases) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
650 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
651 def changed(self, originally_changed): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
652 super(AdapterRegistry, self).changed(originally_changed) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
653 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
654 for sub in self._v_subregistries.keys(): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
655 sub.changed(originally_changed) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
656 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
657 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
658 class VerifyingAdapterLookup(AdapterLookupBase, VerifyingBase): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
659 pass |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
660 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
661 @implementer(IAdapterRegistry) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
662 class VerifyingAdapterRegistry(BaseAdapterRegistry): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
663 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
664 LookupClass = VerifyingAdapterLookup |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
665 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
666 def _convert_None_to_Interface(x): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
667 if x is None: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
668 return Interface |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
669 else: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
670 return x |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
671 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
672 def _lookup(components, specs, provided, name, i, l): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
673 if i < l: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
674 for spec in specs[i].__sro__: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
675 comps = components.get(spec) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
676 if comps: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
677 r = _lookup(comps, specs, provided, name, i+1, l) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
678 if r is not None: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
679 return r |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
680 else: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
681 for iface in provided: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
682 comps = components.get(iface) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
683 if comps: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
684 r = comps.get(name) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
685 if r is not None: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
686 return r |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
687 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
688 return None |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
689 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
690 def _lookupAll(components, specs, provided, result, i, l): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
691 if i < l: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
692 for spec in reversed(specs[i].__sro__): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
693 comps = components.get(spec) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
694 if comps: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
695 _lookupAll(comps, specs, provided, result, i+1, l) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
696 else: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
697 for iface in reversed(provided): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
698 comps = components.get(iface) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
699 if comps: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
700 result.update(comps) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
701 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
702 def _subscriptions(components, specs, provided, name, result, i, l): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
703 if i < l: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
704 for spec in reversed(specs[i].__sro__): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
705 comps = components.get(spec) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
706 if comps: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
707 _subscriptions(comps, specs, provided, name, result, i+1, l) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
708 else: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
709 for iface in reversed(provided): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
710 comps = components.get(iface) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
711 if comps: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
712 comps = comps.get(name) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
713 if comps: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
714 result.extend(comps) |