author | Raphaël Gomès <rgomes@octobus.net> |
Fri, 29 Nov 2019 18:33:56 +0100 | |
changeset 43832 | 1bb4e9b02984 |
parent 37178 | 68ee61822182 |
child 52090 | 7862a5ac35cf |
permissions | -rw-r--r-- |
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) 2001, 2002 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 |
"""Interface object implementation |
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, generators |
37176
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
17 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
18 |
import sys |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
19 |
from types import MethodType |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
20 |
from types import FunctionType |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
21 |
import warnings |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
22 |
import weakref |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
23 |
|
37178
68ee61822182
thirdparty: port zope.interface to relative imports
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37176
diff
changeset
|
24 |
from .exceptions import Invalid |
68ee61822182
thirdparty: port zope.interface to relative imports
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37176
diff
changeset
|
25 |
from .ro import ro |
37176
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
26 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
27 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
28 |
CO_VARARGS = 4 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
29 |
CO_VARKEYWORDS = 8 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
30 |
TAGGED_DATA = '__interface_tagged_values__' |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
31 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
32 |
_decorator_non_return = object() |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
33 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
34 |
def invariant(call): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
35 |
f_locals = sys._getframe(1).f_locals |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
36 |
tags = f_locals.setdefault(TAGGED_DATA, {}) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
37 |
invariants = tags.setdefault('invariants', []) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
38 |
invariants.append(call) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
39 |
return _decorator_non_return |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
40 |
|
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 taggedValue(key, value): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
43 |
"""Attaches a tagged value to an interface at definition time.""" |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
44 |
f_locals = sys._getframe(1).f_locals |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
45 |
tagged_values = f_locals.setdefault(TAGGED_DATA, {}) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
46 |
tagged_values[key] = value |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
47 |
return _decorator_non_return |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
48 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
49 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
50 |
class Element(object): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
51 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
52 |
# We can't say this yet because we don't have enough |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
53 |
# infrastructure in place. |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
54 |
# |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
55 |
#implements(IElement) |
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 |
def __init__(self, __name__, __doc__=''): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
58 |
"""Create an 'attribute' description |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
59 |
""" |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
60 |
if not __doc__ and __name__.find(' ') >= 0: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
61 |
__doc__ = __name__ |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
62 |
__name__ = None |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
63 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
64 |
self.__name__=__name__ |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
65 |
self.__doc__=__doc__ |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
66 |
self.__tagged_values = {} |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
67 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
68 |
def getName(self): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
69 |
""" Returns the name of the object. """ |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
70 |
return self.__name__ |
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 |
def getDoc(self): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
73 |
""" Returns the documentation for the object. """ |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
74 |
return self.__doc__ |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
75 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
76 |
def getTaggedValue(self, tag): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
77 |
""" Returns the value associated with 'tag'. """ |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
78 |
return self.__tagged_values[tag] |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
79 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
80 |
def queryTaggedValue(self, tag, default=None): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
81 |
""" Returns the value associated with 'tag'. """ |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
82 |
return self.__tagged_values.get(tag, default) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
83 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
84 |
def getTaggedValueTags(self): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
85 |
""" Returns a list of all tags. """ |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
86 |
return self.__tagged_values.keys() |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
87 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
88 |
def setTaggedValue(self, tag, value): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
89 |
""" Associates 'value' with 'key'. """ |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
90 |
self.__tagged_values[tag] = value |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
91 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
92 |
class SpecificationBasePy(object): |
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 |
def providedBy(self, ob): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
95 |
"""Is the interface implemented by an object |
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 |
spec = providedBy(ob) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
98 |
return self in spec._implied |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
99 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
100 |
def implementedBy(self, cls): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
101 |
"""Test whether the specification is implemented by a class or factory. |
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 |
Raise TypeError if argument is neither a class nor a callable. |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
104 |
""" |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
105 |
spec = implementedBy(cls) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
106 |
return self in spec._implied |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
107 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
108 |
def isOrExtends(self, interface): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
109 |
"""Is the interface the same as or extend the given interface |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
110 |
""" |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
111 |
return interface in self._implied |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
112 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
113 |
__call__ = isOrExtends |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
114 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
115 |
SpecificationBase = SpecificationBasePy |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
116 |
try: |
37178
68ee61822182
thirdparty: port zope.interface to relative imports
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37176
diff
changeset
|
117 |
from ._zope_interface_coptimizations import SpecificationBase |
37176
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
118 |
except ImportError: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
119 |
pass |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
120 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
121 |
_marker = object() |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
122 |
class InterfaceBasePy(object): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
123 |
"""Base class that wants to be replaced with a C base :) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
124 |
""" |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
125 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
126 |
def __call__(self, obj, alternate=_marker): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
127 |
"""Adapt an object to the interface |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
128 |
""" |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
129 |
conform = getattr(obj, '__conform__', None) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
130 |
if conform is not None: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
131 |
adapter = self._call_conform(conform) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
132 |
if adapter is not None: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
133 |
return adapter |
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 |
adapter = self.__adapt__(obj) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
136 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
137 |
if adapter is not None: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
138 |
return adapter |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
139 |
elif alternate is not _marker: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
140 |
return alternate |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
141 |
else: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
142 |
raise TypeError("Could not adapt", obj, self) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
143 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
144 |
def __adapt__(self, obj): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
145 |
"""Adapt an object to the reciever |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
146 |
""" |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
147 |
if self.providedBy(obj): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
148 |
return obj |
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 |
for hook in adapter_hooks: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
151 |
adapter = hook(self, obj) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
152 |
if adapter is not None: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
153 |
return adapter |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
154 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
155 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
156 |
InterfaceBase = InterfaceBasePy |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
157 |
try: |
37178
68ee61822182
thirdparty: port zope.interface to relative imports
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37176
diff
changeset
|
158 |
from ._zope_interface_coptimizations import InterfaceBase |
37176
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
159 |
except ImportError: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
160 |
pass |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
161 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
162 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
163 |
adapter_hooks = [] |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
164 |
try: |
37178
68ee61822182
thirdparty: port zope.interface to relative imports
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37176
diff
changeset
|
165 |
from ._zope_interface_coptimizations import adapter_hooks |
37176
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
166 |
except ImportError: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
167 |
pass |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
168 |
|
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 |
class Specification(SpecificationBase): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
171 |
"""Specifications |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
172 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
173 |
An interface specification is used to track interface declarations |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
174 |
and component registrations. |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
175 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
176 |
This class is a base class for both interfaces themselves and for |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
177 |
interface specifications (declarations). |
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 |
Specifications are mutable. If you reassign their bases, their |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
180 |
relations with other specifications are adjusted accordingly. |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
181 |
""" |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
182 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
183 |
# Copy some base class methods for speed |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
184 |
isOrExtends = SpecificationBase.isOrExtends |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
185 |
providedBy = SpecificationBase.providedBy |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
186 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
187 |
def __init__(self, bases=()): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
188 |
self._implied = {} |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
189 |
self.dependents = weakref.WeakKeyDictionary() |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
190 |
self.__bases__ = tuple(bases) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
191 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
192 |
def subscribe(self, dependent): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
193 |
self.dependents[dependent] = self.dependents.get(dependent, 0) + 1 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
194 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
195 |
def unsubscribe(self, dependent): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
196 |
n = self.dependents.get(dependent, 0) - 1 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
197 |
if not n: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
198 |
del self.dependents[dependent] |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
199 |
elif n > 0: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
200 |
self.dependents[dependent] = n |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
201 |
else: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
202 |
raise KeyError(dependent) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
203 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
204 |
def __setBases(self, bases): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
205 |
# Register ourselves as a dependent of our old bases |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
206 |
for b in self.__bases__: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
207 |
b.unsubscribe(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 |
# Register ourselves as a dependent of our bases |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
210 |
self.__dict__['__bases__'] = bases |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
211 |
for b in bases: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
212 |
b.subscribe(self) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
213 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
214 |
self.changed(self) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
215 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
216 |
__bases__ = property( |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
217 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
218 |
lambda self: self.__dict__.get('__bases__', ()), |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
219 |
__setBases, |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
220 |
) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
221 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
222 |
def changed(self, originally_changed): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
223 |
"""We, or something we depend on, have changed |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
224 |
""" |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
225 |
try: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
226 |
del self._v_attrs |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
227 |
except AttributeError: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
228 |
pass |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
229 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
230 |
implied = self._implied |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
231 |
implied.clear() |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
232 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
233 |
ancestors = ro(self) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
234 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
235 |
try: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
236 |
if Interface not in ancestors: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
237 |
ancestors.append(Interface) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
238 |
except NameError: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
239 |
pass # defining Interface itself |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
240 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
241 |
self.__sro__ = tuple(ancestors) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
242 |
self.__iro__ = tuple([ancestor for ancestor in ancestors |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
243 |
if isinstance(ancestor, InterfaceClass) |
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 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
246 |
for ancestor in ancestors: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
247 |
# We directly imply our ancestors: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
248 |
implied[ancestor] = () |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
249 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
250 |
# Now, advise our dependents of change: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
251 |
for dependent in tuple(self.dependents.keys()): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
252 |
dependent.changed(originally_changed) |
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 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
255 |
def interfaces(self): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
256 |
"""Return an iterator for the interfaces in the specification. |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
257 |
""" |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
258 |
seen = {} |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
259 |
for base in self.__bases__: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
260 |
for interface in base.interfaces(): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
261 |
if interface not in seen: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
262 |
seen[interface] = 1 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
263 |
yield interface |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
264 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
265 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
266 |
def extends(self, interface, strict=True): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
267 |
"""Does the specification extend the given interface? |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
268 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
269 |
Test whether an interface in the specification extends the |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
270 |
given interface |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
271 |
""" |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
272 |
return ((interface in self._implied) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
273 |
and |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
274 |
((not strict) or (self != interface)) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
275 |
) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
276 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
277 |
def weakref(self, callback=None): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
278 |
return weakref.ref(self, callback) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
279 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
280 |
def get(self, name, default=None): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
281 |
"""Query for an attribute description |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
282 |
""" |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
283 |
try: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
284 |
attrs = self._v_attrs |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
285 |
except AttributeError: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
286 |
attrs = self._v_attrs = {} |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
287 |
attr = attrs.get(name) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
288 |
if attr is None: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
289 |
for iface in self.__iro__: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
290 |
attr = iface.direct(name) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
291 |
if attr is not None: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
292 |
attrs[name] = attr |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
293 |
break |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
294 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
295 |
if attr is None: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
296 |
return default |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
297 |
else: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
298 |
return attr |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
299 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
300 |
class InterfaceClass(Element, InterfaceBase, Specification): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
301 |
"""Prototype (scarecrow) Interfaces Implementation.""" |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
302 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
303 |
# We can't say this yet because we don't have enough |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
304 |
# infrastructure in place. |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
305 |
# |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
306 |
#implements(IInterface) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
307 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
308 |
def __init__(self, name, bases=(), attrs=None, __doc__=None, |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
309 |
__module__=None): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
310 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
311 |
if attrs is None: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
312 |
attrs = {} |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
313 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
314 |
if __module__ is None: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
315 |
__module__ = attrs.get('__module__') |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
316 |
if isinstance(__module__, str): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
317 |
del attrs['__module__'] |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
318 |
else: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
319 |
try: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
320 |
# Figure out what module defined the interface. |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
321 |
# This is how cPython figures out the module of |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
322 |
# a class, but of course it does it in C. :-/ |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
323 |
__module__ = sys._getframe(1).f_globals['__name__'] |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
324 |
except (AttributeError, KeyError): # pragma: no cover |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
325 |
pass |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
326 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
327 |
self.__module__ = __module__ |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
328 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
329 |
d = attrs.get('__doc__') |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
330 |
if d is not None: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
331 |
if not isinstance(d, Attribute): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
332 |
if __doc__ is None: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
333 |
__doc__ = d |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
334 |
del attrs['__doc__'] |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
335 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
336 |
if __doc__ is None: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
337 |
__doc__ = '' |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
338 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
339 |
Element.__init__(self, name, __doc__) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
340 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
341 |
tagged_data = attrs.pop(TAGGED_DATA, None) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
342 |
if tagged_data is not None: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
343 |
for key, val in tagged_data.items(): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
344 |
self.setTaggedValue(key, val) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
345 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
346 |
for base in bases: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
347 |
if not isinstance(base, InterfaceClass): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
348 |
raise TypeError('Expected base interfaces') |
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 |
Specification.__init__(self, bases) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
351 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
352 |
# Make sure that all recorded attributes (and methods) are of type |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
353 |
# `Attribute` and `Method` |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
354 |
for name, attr in list(attrs.items()): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
355 |
if name in ('__locals__', '__qualname__', '__annotations__'): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
356 |
# __locals__: Python 3 sometimes adds this. |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
357 |
# __qualname__: PEP 3155 (Python 3.3+) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
358 |
# __annotations__: PEP 3107 (Python 3.0+) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
359 |
del attrs[name] |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
360 |
continue |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
361 |
if isinstance(attr, Attribute): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
362 |
attr.interface = self |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
363 |
if not attr.__name__: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
364 |
attr.__name__ = name |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
365 |
elif isinstance(attr, FunctionType): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
366 |
attrs[name] = fromFunction(attr, self, name=name) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
367 |
elif attr is _decorator_non_return: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
368 |
del attrs[name] |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
369 |
else: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
370 |
raise InvalidInterface("Concrete attribute, " + name) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
371 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
372 |
self.__attrs = attrs |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
373 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
374 |
self.__identifier__ = "%s.%s" % (self.__module__, self.__name__) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
375 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
376 |
def interfaces(self): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
377 |
"""Return an iterator for the interfaces in the specification. |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
378 |
""" |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
379 |
yield self |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
380 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
381 |
def getBases(self): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
382 |
return self.__bases__ |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
383 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
384 |
def isEqualOrExtendedBy(self, other): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
385 |
"""Same interface or extends?""" |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
386 |
return self == other or other.extends(self) |
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 |
def names(self, all=False): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
389 |
"""Return the attribute names defined by the interface.""" |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
390 |
if not all: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
391 |
return self.__attrs.keys() |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
392 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
393 |
r = self.__attrs.copy() |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
394 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
395 |
for base in self.__bases__: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
396 |
r.update(dict.fromkeys(base.names(all))) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
397 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
398 |
return r.keys() |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
399 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
400 |
def __iter__(self): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
401 |
return iter(self.names(all=True)) |
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 |
def namesAndDescriptions(self, all=False): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
404 |
"""Return attribute names and descriptions defined by interface.""" |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
405 |
if not all: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
406 |
return self.__attrs.items() |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
407 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
408 |
r = {} |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
409 |
for base in self.__bases__[::-1]: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
410 |
r.update(dict(base.namesAndDescriptions(all))) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
411 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
412 |
r.update(self.__attrs) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
413 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
414 |
return r.items() |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
415 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
416 |
def getDescriptionFor(self, name): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
417 |
"""Return the attribute description for the given name.""" |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
418 |
r = self.get(name) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
419 |
if r is not None: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
420 |
return r |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
421 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
422 |
raise KeyError(name) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
423 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
424 |
__getitem__ = getDescriptionFor |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
425 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
426 |
def __contains__(self, name): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
427 |
return self.get(name) is not None |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
428 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
429 |
def direct(self, name): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
430 |
return self.__attrs.get(name) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
431 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
432 |
def queryDescriptionFor(self, name, default=None): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
433 |
return self.get(name, default) |
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 validateInvariants(self, obj, errors=None): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
436 |
"""validate object to defined invariants.""" |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
437 |
for call in self.queryTaggedValue('invariants', []): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
438 |
try: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
439 |
call(obj) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
440 |
except Invalid as e: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
441 |
if errors is None: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
442 |
raise |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
443 |
else: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
444 |
errors.append(e) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
445 |
for base in self.__bases__: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
446 |
try: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
447 |
base.validateInvariants(obj, errors) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
448 |
except Invalid: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
449 |
if errors is None: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
450 |
raise |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
451 |
if errors: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
452 |
raise Invalid(errors) |
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 |
def __repr__(self): # pragma: no cover |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
455 |
try: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
456 |
return self._v_repr |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
457 |
except AttributeError: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
458 |
name = self.__name__ |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
459 |
m = self.__module__ |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
460 |
if m: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
461 |
name = '%s.%s' % (m, name) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
462 |
r = "<%s %s>" % (self.__class__.__name__, name) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
463 |
self._v_repr = r |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
464 |
return r |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
465 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
466 |
def _call_conform(self, conform): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
467 |
try: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
468 |
return conform(self) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
469 |
except TypeError: # pragma: no cover |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
470 |
# We got a TypeError. It might be an error raised by |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
471 |
# the __conform__ implementation, or *we* may have |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
472 |
# made the TypeError by calling an unbound method |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
473 |
# (object is a class). In the later case, we behave |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
474 |
# as though there is no __conform__ method. We can |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
475 |
# detect this case by checking whether there is more |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
476 |
# than one traceback object in the traceback chain: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
477 |
if sys.exc_info()[2].tb_next is not None: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
478 |
# There is more than one entry in the chain, so |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
479 |
# reraise the error: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
480 |
raise |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
481 |
# This clever trick is from Phillip Eby |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
482 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
483 |
return None # pragma: no cover |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
484 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
485 |
def __reduce__(self): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
486 |
return self.__name__ |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
487 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
488 |
def __cmp(self, other): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
489 |
# Yes, I did mean to name this __cmp, rather than __cmp__. |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
490 |
# It is a private method used by __lt__ and __gt__. |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
491 |
# I don't want to override __eq__ because I want the default |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
492 |
# __eq__, which is really fast. |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
493 |
"""Make interfaces sortable |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
494 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
495 |
TODO: It would ne nice if: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
496 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
497 |
More specific interfaces should sort before less specific ones. |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
498 |
Otherwise, sort on name and module. |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
499 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
500 |
But this is too complicated, and we're going to punt on it |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
501 |
for now. |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
502 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
503 |
For now, sort on interface and module name. |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
504 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
505 |
None is treated as a pseudo interface that implies the loosest |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
506 |
contact possible, no contract. For that reason, all interfaces |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
507 |
sort before None. |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
508 |
|
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 |
if other is None: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
511 |
return -1 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
512 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
513 |
n1 = (getattr(self, '__name__', ''), getattr(self, '__module__', '')) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
514 |
n2 = (getattr(other, '__name__', ''), getattr(other, '__module__', '')) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
515 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
516 |
# This spelling works under Python3, which doesn't have cmp(). |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
517 |
return (n1 > n2) - (n1 < n2) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
518 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
519 |
def __hash__(self): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
520 |
d = self.__dict__ |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
521 |
if '__module__' not in d or '__name__' not in d: # pragma: no cover |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
522 |
warnings.warn('Hashing uninitialized InterfaceClass instance') |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
523 |
return 1 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
524 |
return hash((self.__name__, self.__module__)) |
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 __eq__(self, other): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
527 |
c = self.__cmp(other) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
528 |
return c == 0 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
529 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
530 |
def __ne__(self, other): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
531 |
c = self.__cmp(other) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
532 |
return c != 0 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
533 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
534 |
def __lt__(self, other): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
535 |
c = self.__cmp(other) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
536 |
return c < 0 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
537 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
538 |
def __le__(self, other): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
539 |
c = self.__cmp(other) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
540 |
return c <= 0 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
541 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
542 |
def __gt__(self, other): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
543 |
c = self.__cmp(other) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
544 |
return c > 0 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
545 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
546 |
def __ge__(self, other): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
547 |
c = self.__cmp(other) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
548 |
return c >= 0 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
549 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
550 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
551 |
Interface = InterfaceClass("Interface", __module__ = 'zope.interface') |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
552 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
553 |
class Attribute(Element): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
554 |
"""Attribute descriptions |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
555 |
""" |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
556 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
557 |
# We can't say this yet because we don't have enough |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
558 |
# infrastructure in place. |
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 |
# implements(IAttribute) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
561 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
562 |
interface = None |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
563 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
564 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
565 |
class Method(Attribute): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
566 |
"""Method interfaces |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
567 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
568 |
The idea here is that you have objects that describe methods. |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
569 |
This provides an opportunity for rich meta-data. |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
570 |
""" |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
571 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
572 |
# We can't say this yet because we don't have enough |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
573 |
# infrastructure in place. |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
574 |
# |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
575 |
# implements(IMethod) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
576 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
577 |
positional = required = () |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
578 |
_optional = varargs = kwargs = None |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
579 |
def _get_optional(self): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
580 |
if self._optional is None: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
581 |
return {} |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
582 |
return self._optional |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
583 |
def _set_optional(self, opt): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
584 |
self._optional = opt |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
585 |
def _del_optional(self): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
586 |
self._optional = None |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
587 |
optional = property(_get_optional, _set_optional, _del_optional) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
588 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
589 |
def __call__(self, *args, **kw): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
590 |
raise BrokenImplementation(self.interface, self.__name__) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
591 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
592 |
def getSignatureInfo(self): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
593 |
return {'positional': self.positional, |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
594 |
'required': self.required, |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
595 |
'optional': self.optional, |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
596 |
'varargs': self.varargs, |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
597 |
'kwargs': self.kwargs, |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
598 |
} |
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 |
def getSignatureString(self): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
601 |
sig = [] |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
602 |
for v in self.positional: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
603 |
sig.append(v) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
604 |
if v in self.optional.keys(): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
605 |
sig[-1] += "=" + repr(self.optional[v]) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
606 |
if self.varargs: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
607 |
sig.append("*" + self.varargs) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
608 |
if self.kwargs: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
609 |
sig.append("**" + self.kwargs) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
610 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
611 |
return "(%s)" % ", ".join(sig) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
612 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
613 |
def fromFunction(func, interface=None, imlevel=0, name=None): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
614 |
name = name or func.__name__ |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
615 |
method = Method(name, func.__doc__) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
616 |
defaults = getattr(func, '__defaults__', None) or () |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
617 |
code = func.__code__ |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
618 |
# Number of positional arguments |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
619 |
na = code.co_argcount-imlevel |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
620 |
names = code.co_varnames[imlevel:] |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
621 |
opt = {} |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
622 |
# Number of required arguments |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
623 |
nr = na-len(defaults) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
624 |
if nr < 0: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
625 |
defaults=defaults[-nr:] |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
626 |
nr = 0 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
627 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
628 |
# Determine the optional arguments. |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
629 |
opt.update(dict(zip(names[nr:], defaults))) |
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 |
method.positional = names[:na] |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
632 |
method.required = names[:nr] |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
633 |
method.optional = opt |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
634 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
635 |
argno = na |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
636 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
637 |
# Determine the function's variable argument's name (i.e. *args) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
638 |
if code.co_flags & CO_VARARGS: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
639 |
method.varargs = names[argno] |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
640 |
argno = argno + 1 |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
641 |
else: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
642 |
method.varargs = None |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
643 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
644 |
# Determine the function's keyword argument's name (i.e. **kw) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
645 |
if code.co_flags & CO_VARKEYWORDS: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
646 |
method.kwargs = names[argno] |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
647 |
else: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
648 |
method.kwargs = None |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
649 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
650 |
method.interface = interface |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
651 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
652 |
for key, value in func.__dict__.items(): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
653 |
method.setTaggedValue(key, value) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
654 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
655 |
return method |
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 |
def fromMethod(meth, interface=None, name=None): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
659 |
if isinstance(meth, MethodType): |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
660 |
func = meth.__func__ |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
661 |
else: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
662 |
func = meth |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
663 |
return fromFunction(func, interface, imlevel=1, name=name) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
664 |
|
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 |
# Now we can create the interesting interfaces and wire them up: |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
667 |
def _wire(): |
37178
68ee61822182
thirdparty: port zope.interface to relative imports
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37176
diff
changeset
|
668 |
from .declarations import classImplements |
37176
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
669 |
|
37178
68ee61822182
thirdparty: port zope.interface to relative imports
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37176
diff
changeset
|
670 |
from .interfaces import IAttribute |
37176
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
671 |
classImplements(Attribute, IAttribute) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
672 |
|
37178
68ee61822182
thirdparty: port zope.interface to relative imports
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37176
diff
changeset
|
673 |
from .interfaces import IMethod |
37176
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
674 |
classImplements(Method, IMethod) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
675 |
|
37178
68ee61822182
thirdparty: port zope.interface to relative imports
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37176
diff
changeset
|
676 |
from .interfaces import IInterface |
37176
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
677 |
classImplements(InterfaceClass, IInterface) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
678 |
|
37178
68ee61822182
thirdparty: port zope.interface to relative imports
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37176
diff
changeset
|
679 |
from .interfaces import ISpecification |
37176
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
680 |
classImplements(Specification, ISpecification) |
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
681 |
|
943d77fc07a3
thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
682 |
# We import this here to deal with module dependencies. |
37178
68ee61822182
thirdparty: port zope.interface to relative imports
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37176
diff
changeset
|
683 |
from .declarations import implementedBy |
68ee61822182
thirdparty: port zope.interface to relative imports
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37176
diff
changeset
|
684 |
from .declarations import providedBy |
68ee61822182
thirdparty: port zope.interface to relative imports
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37176
diff
changeset
|
685 |
from .exceptions import InvalidInterface |
68ee61822182
thirdparty: port zope.interface to relative imports
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37176
diff
changeset
|
686 |
from .exceptions import BrokenImplementation |