##// END OF EJS Templates
thirdparty: port zope.interface to relative imports...
Gregory Szorc -
r37195:68ee6182 default
parent child Browse files
Show More
@@ -48,42 +48,45 b' The package has several public modules:'
48
48
49 See the module doc strings for more information.
49 See the module doc strings for more information.
50 """
50 """
51
52 from __future__ import absolute_import
53
51 __docformat__ = 'restructuredtext'
54 __docformat__ = 'restructuredtext'
52
55
53 from zope.interface.interface import Interface
56 from .interface import Interface
54 from zope.interface.interface import _wire
57 from .interface import _wire
55
58
56 # Need to actually get the interface elements to implement the right interfaces
59 # Need to actually get the interface elements to implement the right interfaces
57 _wire()
60 _wire()
58 del _wire
61 del _wire
59
62
60 from zope.interface.declarations import Declaration
63 from .declarations import Declaration
61 from zope.interface.declarations import alsoProvides
64 from .declarations import alsoProvides
62 from zope.interface.declarations import classImplements
65 from .declarations import classImplements
63 from zope.interface.declarations import classImplementsOnly
66 from .declarations import classImplementsOnly
64 from zope.interface.declarations import classProvides
67 from .declarations import classProvides
65 from zope.interface.declarations import directlyProvidedBy
68 from .declarations import directlyProvidedBy
66 from zope.interface.declarations import directlyProvides
69 from .declarations import directlyProvides
67 from zope.interface.declarations import implementedBy
70 from .declarations import implementedBy
68 from zope.interface.declarations import implementer
71 from .declarations import implementer
69 from zope.interface.declarations import implementer_only
72 from .declarations import implementer_only
70 from zope.interface.declarations import implements
73 from .declarations import implements
71 from zope.interface.declarations import implementsOnly
74 from .declarations import implementsOnly
72 from zope.interface.declarations import moduleProvides
75 from .declarations import moduleProvides
73 from zope.interface.declarations import named
76 from .declarations import named
74 from zope.interface.declarations import noLongerProvides
77 from .declarations import noLongerProvides
75 from zope.interface.declarations import providedBy
78 from .declarations import providedBy
76 from zope.interface.declarations import provider
79 from .declarations import provider
77 from zope.interface.exceptions import Invalid
80 from .exceptions import Invalid
78 from zope.interface.interface import Attribute
81 from .interface import Attribute
79 from zope.interface.interface import invariant
82 from .interface import invariant
80 from zope.interface.interface import taggedValue
83 from .interface import taggedValue
81
84
82 # The following are to make spec pickles cleaner
85 # The following are to make spec pickles cleaner
83 from zope.interface.declarations import Provides
86 from .declarations import Provides
84
87
85
88
86 from zope.interface.interfaces import IInterfaceDeclaration
89 from .interfaces import IInterfaceDeclaration
87
90
88 moduleProvides(IInterfaceDeclaration)
91 moduleProvides(IInterfaceDeclaration)
89
92
@@ -13,6 +13,8 b''
13 ##############################################################################
13 ##############################################################################
14 """Basic components support
14 """Basic components support
15 """
15 """
16 from __future__ import absolute_import
17
16 import sys
18 import sys
17 import types
19 import types
18
20
@@ -15,7 +15,10 b''
15
15
16 See Adapter class.
16 See Adapter class.
17 """
17 """
18 from zope.interface import Declaration
18
19 from __future__ import absolute_import
20
21 from .interface import Declaration
19
22
20 def _flatten(implements, include_None=0):
23 def _flatten(implements, include_None=0):
21
24
@@ -47,7 +47,8 b' import_declarations(void)'
47 {
47 {
48 PyObject *declarations, *i;
48 PyObject *declarations, *i;
49
49
50 declarations = PyImport_ImportModule("zope.interface.declarations");
50 declarations = PyImport_ImportModule(
51 "mercurial.thirdparty.zope.interface.declarations");
51 if (declarations == NULL)
52 if (declarations == NULL)
52 return -1;
53 return -1;
53
54
@@ -13,16 +13,18 b''
13 ##############################################################################
13 ##############################################################################
14 """Adapter management
14 """Adapter management
15 """
15 """
16 from __future__ import absolute_import
17
16 import weakref
18 import weakref
17
19
18 from zope.interface import implementer
20 from . import implementer
19 from zope.interface import providedBy
21 from . import providedBy
20 from zope.interface import Interface
22 from . import Interface
21 from zope.interface import ro
23 from . import ro
22 from zope.interface.interfaces import IAdapterRegistry
24 from .interfaces import IAdapterRegistry
23
25
24 from zope.interface._compat import _normalize_name
26 from ._compat import _normalize_name
25 from zope.interface._compat import STRING_TYPES
27 from ._compat import STRING_TYPES
26
28
27 _BLANK = u''
29 _BLANK = u''
28
30
@@ -409,7 +411,7 b' class LookupBaseFallback(object):'
409 LookupBasePy = LookupBaseFallback # BBB
411 LookupBasePy = LookupBaseFallback # BBB
410
412
411 try:
413 try:
412 from zope.interface._zope_interface_coptimizations import LookupBase
414 from ._zope_interface_coptimizations import LookupBase
413 except ImportError:
415 except ImportError:
414 LookupBase = LookupBaseFallback
416 LookupBase = LookupBaseFallback
415
417
@@ -445,7 +447,7 b' class VerifyingBaseFallback(LookupBaseFa'
445 VerifyingBasePy = VerifyingBaseFallback #BBB
447 VerifyingBasePy = VerifyingBaseFallback #BBB
446
448
447 try:
449 try:
448 from zope.interface._zope_interface_coptimizations import VerifyingBase
450 from ._zope_interface_coptimizations import VerifyingBase
449 except ImportError:
451 except ImportError:
450 VerifyingBase = VerifyingBaseFallback
452 VerifyingBase = VerifyingBaseFallback
451
453
@@ -25,6 +25,8 b' models, object-relational persistence, a'
25 Visit the PEAK home page at http://peak.telecommunity.com for more information.
25 Visit the PEAK home page at http://peak.telecommunity.com for more information.
26 """
26 """
27
27
28 from __future__ import absolute_import
29
28 from types import FunctionType
30 from types import FunctionType
29 try:
31 try:
30 from types import ClassType
32 from types import ClassType
@@ -15,8 +15,10 b' This module is called idatetime because '
15 of the real datetime would fail.
15 of the real datetime would fail.
16 """
16 """
17
17
18 from zope.interface import Interface, Attribute
18 from __future__ import absolute_import
19 from zope.interface import classImplements
19
20 from .. import Interface, Attribute
21 from .. import classImplements
20
22
21 from datetime import timedelta, date, datetime, time, tzinfo
23 from datetime import timedelta, date, datetime, time, tzinfo
22
24
@@ -13,8 +13,11 b''
13 ##############################################################################
13 ##############################################################################
14 """Interfaces for standard python exceptions
14 """Interfaces for standard python exceptions
15 """
15 """
16 from zope.interface import Interface
16
17 from zope.interface import classImplements
17 from __future__ import absolute_import
18
19 from .. import Interface
20 from .. import classImplements
18
21
19 class IException(Interface): pass
22 class IException(Interface): pass
20 class IStandardError(IException): pass
23 class IStandardError(IException): pass
@@ -13,7 +13,10 b''
13 ##############################################################################
13 ##############################################################################
14 """Mapping Interfaces
14 """Mapping Interfaces
15 """
15 """
16 from zope.interface import Interface
16
17 from __future__ import absolute_import
18
19 from .. import Interface
17
20
18 class IItemMapping(Interface):
21 class IItemMapping(Interface):
19 """Simplest readable mapping object
22 """Simplest readable mapping object
@@ -13,8 +13,11 b''
13 ##############################################################################
13 ##############################################################################
14 """Sequence Interfaces
14 """Sequence Interfaces
15 """
15 """
16
17 from __future__ import absolute_import
18
16 __docformat__ = 'restructuredtext'
19 __docformat__ = 'restructuredtext'
17 from zope.interface import Interface
20 from .. import Interface
18
21
19 class IMinimalSequence(Interface):
22 class IMinimalSequence(Interface):
20 """Most basic sequence interface.
23 """Most basic sequence interface.
@@ -24,6 +24,8 b' There are three flavors of declarations:'
24 provided by objects.
24 provided by objects.
25
25
26 """
26 """
27 from __future__ import absolute_import
28
27 __docformat__ = 'restructuredtext'
29 __docformat__ = 'restructuredtext'
28
30
29 import sys
31 import sys
@@ -32,12 +34,12 b' from types import MethodType'
32 from types import ModuleType
34 from types import ModuleType
33 import weakref
35 import weakref
34
36
35 from zope.interface.advice import addClassAdvisor
37 from .advice import addClassAdvisor
36 from zope.interface.interface import InterfaceClass
38 from .interface import InterfaceClass
37 from zope.interface.interface import SpecificationBase
39 from .interface import SpecificationBase
38 from zope.interface.interface import Specification
40 from .interface import Specification
39 from zope.interface._compat import CLASS_TYPES as DescriptorAwareMetaClasses
41 from ._compat import CLASS_TYPES as DescriptorAwareMetaClasses
40 from zope.interface._compat import PYTHON3
42 from ._compat import PYTHON3
41
43
42 # Registry of class-implementation specifications
44 # Registry of class-implementation specifications
43 BuiltinImplementationSpecifications = {}
45 BuiltinImplementationSpecifications = {}
@@ -638,11 +640,11 b' ClassProvidesBase = ClassProvidesBaseFal'
638
640
639 # Try to get C base:
641 # Try to get C base:
640 try:
642 try:
641 import zope.interface._zope_interface_coptimizations
643 from . import _zope_interface_coptimizations
642 except ImportError:
644 except ImportError:
643 pass
645 pass
644 else:
646 else:
645 from zope.interface._zope_interface_coptimizations import ClassProvidesBase
647 from ._zope_interface_coptimizations import ClassProvidesBase
646
648
647
649
648 class ClassProvides(Declaration, ClassProvidesBase):
650 class ClassProvides(Declaration, ClassProvidesBase):
@@ -915,15 +917,15 b' def _normalizeargs(sequence, output = No'
915 _empty = Declaration()
917 _empty = Declaration()
916
918
917 try:
919 try:
918 import zope.interface._zope_interface_coptimizations
920 from . import _zope_interface_coptimizations
919 except ImportError:
921 except ImportError:
920 pass
922 pass
921 else:
923 else:
922 from zope.interface._zope_interface_coptimizations import implementedBy
924 from ._zope_interface_coptimizations import implementedBy
923 from zope.interface._zope_interface_coptimizations import providedBy
925 from ._zope_interface_coptimizations import providedBy
924 from zope.interface._zope_interface_coptimizations import (
926 from ._zope_interface_coptimizations import (
925 getObjectSpecification)
927 getObjectSpecification)
926 from zope.interface._zope_interface_coptimizations import (
928 from ._zope_interface_coptimizations import (
927 ObjectSpecificationDescriptor)
929 ObjectSpecificationDescriptor)
928
930
929 objectSpecificationDescriptor = ObjectSpecificationDescriptor()
931 objectSpecificationDescriptor = ObjectSpecificationDescriptor()
@@ -16,8 +16,10 b''
16 This module provides a function, asStructuredText, for rendering an
16 This module provides a function, asStructuredText, for rendering an
17 interface as structured text.
17 interface as structured text.
18 """
18 """
19 import zope.interface
20
19
20 from __future__ import absolute_import
21
22 from . import Interface
21
23
22 def asStructuredText(I, munge=0, rst=False):
24 def asStructuredText(I, munge=0, rst=False):
23 """ Output structured text format. Note, this will whack any existing
25 """ Output structured text format. Note, this will whack any existing
@@ -41,7 +43,7 b' def asStructuredText(I, munge=0, rst=Fal'
41
43
42 bases = [base
44 bases = [base
43 for base in I.__bases__
45 for base in I.__bases__
44 if base is not zope.interface.Interface
46 if base is not Interface
45 ]
47 ]
46 if bases:
48 if bases:
47 outp(_justify_and_indent("This interface extends:", level, munge))
49 outp(_justify_and_indent("This interface extends:", level, munge))
@@ -14,6 +14,8 b''
14 """Interface-specific exceptions
14 """Interface-specific exceptions
15 """
15 """
16
16
17 from __future__ import absolute_import
18
17 class Invalid(Exception):
19 class Invalid(Exception):
18 """A specification is violated
20 """A specification is violated
19 """
21 """
@@ -13,7 +13,7 b''
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
@@ -21,8 +21,8 b' 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
@@ -114,7 +114,7 b' class SpecificationBasePy(object):'
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
@@ -155,14 +155,14 b' class InterfaceBasePy(object):'
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
@@ -665,22 +665,22 b' def fromMethod(meth, interface=None, nam'
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
@@ -13,11 +13,14 b''
13 ##############################################################################
13 ##############################################################################
14 """Interface Package Interfaces
14 """Interface Package Interfaces
15 """
15 """
16
17 from __future__ import absolute_import
18
16 __docformat__ = 'restructuredtext'
19 __docformat__ = 'restructuredtext'
17
20
18 from zope.interface.interface import Attribute
21 from .interface import Attribute
19 from zope.interface.interface import Interface
22 from .interface import Interface
20 from zope.interface.declarations import implementer
23 from .declarations import implementer
21
24
22
25
23 _BLANK = u''
26 _BLANK = u''
@@ -13,31 +13,34 b''
13 ##############################################################################
13 ##############################################################################
14 """Basic components support
14 """Basic components support
15 """
15 """
16
17 from __future__ import absolute_import
18
16 from collections import defaultdict
19 from collections import defaultdict
17
20
18 try:
21 try:
19 from zope.event import notify
22 from ..event import notify
20 except ImportError: # pragma: no cover
23 except ImportError: # pragma: no cover
21 def notify(*arg, **kw): pass
24 def notify(*arg, **kw): pass
22
25
23 from zope.interface.interfaces import ISpecification
26 from .interfaces import ISpecification
24 from zope.interface.interfaces import ComponentLookupError
27 from .interfaces import ComponentLookupError
25 from zope.interface.interfaces import IAdapterRegistration
28 from .interfaces import IAdapterRegistration
26 from zope.interface.interfaces import IComponents
29 from .interfaces import IComponents
27 from zope.interface.interfaces import IHandlerRegistration
30 from .interfaces import IHandlerRegistration
28 from zope.interface.interfaces import ISubscriptionAdapterRegistration
31 from .interfaces import ISubscriptionAdapterRegistration
29 from zope.interface.interfaces import IUtilityRegistration
32 from .interfaces import IUtilityRegistration
30 from zope.interface.interfaces import Registered
33 from .interfaces import Registered
31 from zope.interface.interfaces import Unregistered
34 from .interfaces import Unregistered
32
35
33 from zope.interface.interface import Interface
36 from .interface import Interface
34 from zope.interface.declarations import implementedBy
37 from .declarations import implementedBy
35 from zope.interface.declarations import implementer
38 from .declarations import implementer
36 from zope.interface.declarations import implementer_only
39 from .declarations import implementer_only
37 from zope.interface.declarations import providedBy
40 from .declarations import providedBy
38 from zope.interface.adapter import AdapterRegistry
41 from .adapter import AdapterRegistry
39 from zope.interface._compat import CLASS_TYPES
42 from ._compat import CLASS_TYPES
40 from zope.interface._compat import STRING_TYPES
43 from ._compat import STRING_TYPES
41
44
42
45
43 class _UnhashableComponentCounter(object):
46 class _UnhashableComponentCounter(object):
@@ -13,6 +13,9 b''
13 ##############################################################################
13 ##############################################################################
14 """Compute a resolution order for an object and its bases
14 """Compute a resolution order for an object and its bases
15 """
15 """
16
17 from __future__ import absolute_import
18
16 __docformat__ = 'restructuredtext'
19 __docformat__ = 'restructuredtext'
17
20
18 def _mergeOrderings(orderings):
21 def _mergeOrderings(orderings):
@@ -13,10 +13,12 b''
13 ##############################################################################
13 ##############################################################################
14 """Verify interface implementations
14 """Verify interface implementations
15 """
15 """
16 from zope.interface.exceptions import BrokenImplementation, DoesNotImplement
16 from __future__ import absolute_import
17 from zope.interface.exceptions import BrokenMethodImplementation
17
18 from .exceptions import BrokenImplementation, DoesNotImplement
19 from .exceptions import BrokenMethodImplementation
18 from types import FunctionType, MethodType
20 from types import FunctionType, MethodType
19 from zope.interface.interface import fromMethod, fromFunction, Method
21 from .interface import fromMethod, fromFunction, Method
20 import sys
22 import sys
21
23
22 # This will be monkey-patched when running under Zope 2, so leave this
24 # This will be monkey-patched when running under Zope 2, so leave this
General Comments 0
You need to be logged in to leave comments. Login now