Mercurial > public > mercurial-scm > hg
comparison mercurial/thirdparty/zope/interface/interface.py @ 37178:68ee61822182
thirdparty: port zope.interface to relative imports
By using relative imports, we're guaranteed to get modules
vendored with Mercurial rather than other random modules
that might be in sys.path.
My editor strips trailing whitespace on save. So some minor
source code cleanup was also performed as part of this commit.
# no-check-commit because some modified lines have double newlines
Differential Revision: https://phab.mercurial-scm.org/D2930
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Wed, 21 Mar 2018 19:52:30 -0700 |
parents | 943d77fc07a3 |
children | 7862a5ac35cf |
comparison
equal
deleted
inserted
replaced
37177:338367d44d34 | 37178:68ee61822182 |
---|---|
11 # FOR A PARTICULAR PURPOSE. | 11 # FOR A PARTICULAR PURPOSE. |
12 # | 12 # |
13 ############################################################################## | 13 ############################################################################## |
14 """Interface object implementation | 14 """Interface object implementation |
15 """ | 15 """ |
16 from __future__ import generators | 16 from __future__ import absolute_import, generators |
17 | 17 |
18 import sys | 18 import sys |
19 from types import MethodType | 19 from types import MethodType |
20 from types import FunctionType | 20 from types import FunctionType |
21 import warnings | 21 import warnings |
22 import weakref | 22 import weakref |
23 | 23 |
24 from zope.interface.exceptions import Invalid | 24 from .exceptions import Invalid |
25 from zope.interface.ro import ro | 25 from .ro import ro |
26 | 26 |
27 | 27 |
28 CO_VARARGS = 4 | 28 CO_VARARGS = 4 |
29 CO_VARKEYWORDS = 8 | 29 CO_VARKEYWORDS = 8 |
30 TAGGED_DATA = '__interface_tagged_values__' | 30 TAGGED_DATA = '__interface_tagged_values__' |
112 | 112 |
113 __call__ = isOrExtends | 113 __call__ = isOrExtends |
114 | 114 |
115 SpecificationBase = SpecificationBasePy | 115 SpecificationBase = SpecificationBasePy |
116 try: | 116 try: |
117 from zope.interface._zope_interface_coptimizations import SpecificationBase | 117 from ._zope_interface_coptimizations import SpecificationBase |
118 except ImportError: | 118 except ImportError: |
119 pass | 119 pass |
120 | 120 |
121 _marker = object() | 121 _marker = object() |
122 class InterfaceBasePy(object): | 122 class InterfaceBasePy(object): |
153 return adapter | 153 return adapter |
154 | 154 |
155 | 155 |
156 InterfaceBase = InterfaceBasePy | 156 InterfaceBase = InterfaceBasePy |
157 try: | 157 try: |
158 from zope.interface._zope_interface_coptimizations import InterfaceBase | 158 from ._zope_interface_coptimizations import InterfaceBase |
159 except ImportError: | 159 except ImportError: |
160 pass | 160 pass |
161 | 161 |
162 | 162 |
163 adapter_hooks = [] | 163 adapter_hooks = [] |
164 try: | 164 try: |
165 from zope.interface._zope_interface_coptimizations import adapter_hooks | 165 from ._zope_interface_coptimizations import adapter_hooks |
166 except ImportError: | 166 except ImportError: |
167 pass | 167 pass |
168 | 168 |
169 | 169 |
170 class Specification(SpecificationBase): | 170 class Specification(SpecificationBase): |
663 return fromFunction(func, interface, imlevel=1, name=name) | 663 return fromFunction(func, interface, imlevel=1, name=name) |
664 | 664 |
665 | 665 |
666 # Now we can create the interesting interfaces and wire them up: | 666 # Now we can create the interesting interfaces and wire them up: |
667 def _wire(): | 667 def _wire(): |
668 from zope.interface.declarations import classImplements | 668 from .declarations import classImplements |
669 | 669 |
670 from zope.interface.interfaces import IAttribute | 670 from .interfaces import IAttribute |
671 classImplements(Attribute, IAttribute) | 671 classImplements(Attribute, IAttribute) |
672 | 672 |
673 from zope.interface.interfaces import IMethod | 673 from .interfaces import IMethod |
674 classImplements(Method, IMethod) | 674 classImplements(Method, IMethod) |
675 | 675 |
676 from zope.interface.interfaces import IInterface | 676 from .interfaces import IInterface |
677 classImplements(InterfaceClass, IInterface) | 677 classImplements(InterfaceClass, IInterface) |
678 | 678 |
679 from zope.interface.interfaces import ISpecification | 679 from .interfaces import ISpecification |
680 classImplements(Specification, ISpecification) | 680 classImplements(Specification, ISpecification) |
681 | 681 |
682 # We import this here to deal with module dependencies. | 682 # We import this here to deal with module dependencies. |
683 from zope.interface.declarations import implementedBy | 683 from .declarations import implementedBy |
684 from zope.interface.declarations import providedBy | 684 from .declarations import providedBy |
685 from zope.interface.exceptions import InvalidInterface | 685 from .exceptions import InvalidInterface |
686 from zope.interface.exceptions import BrokenImplementation | 686 from .exceptions import BrokenImplementation |