##// 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 49 See the module doc strings for more information.
50 50 """
51
52 from __future__ import absolute_import
53
51 54 __docformat__ = 'restructuredtext'
52 55
53 from zope.interface.interface import Interface
54 from zope.interface.interface import _wire
56 from .interface import Interface
57 from .interface import _wire
55 58
56 59 # Need to actually get the interface elements to implement the right interfaces
57 60 _wire()
58 61 del _wire
59 62
60 from zope.interface.declarations import Declaration
61 from zope.interface.declarations import alsoProvides
62 from zope.interface.declarations import classImplements
63 from zope.interface.declarations import classImplementsOnly
64 from zope.interface.declarations import classProvides
65 from zope.interface.declarations import directlyProvidedBy
66 from zope.interface.declarations import directlyProvides
67 from zope.interface.declarations import implementedBy
68 from zope.interface.declarations import implementer
69 from zope.interface.declarations import implementer_only
70 from zope.interface.declarations import implements
71 from zope.interface.declarations import implementsOnly
72 from zope.interface.declarations import moduleProvides
73 from zope.interface.declarations import named
74 from zope.interface.declarations import noLongerProvides
75 from zope.interface.declarations import providedBy
76 from zope.interface.declarations import provider
77 from zope.interface.exceptions import Invalid
78 from zope.interface.interface import Attribute
79 from zope.interface.interface import invariant
80 from zope.interface.interface import taggedValue
63 from .declarations import Declaration
64 from .declarations import alsoProvides
65 from .declarations import classImplements
66 from .declarations import classImplementsOnly
67 from .declarations import classProvides
68 from .declarations import directlyProvidedBy
69 from .declarations import directlyProvides
70 from .declarations import implementedBy
71 from .declarations import implementer
72 from .declarations import implementer_only
73 from .declarations import implements
74 from .declarations import implementsOnly
75 from .declarations import moduleProvides
76 from .declarations import named
77 from .declarations import noLongerProvides
78 from .declarations import providedBy
79 from .declarations import provider
80 from .exceptions import Invalid
81 from .interface import Attribute
82 from .interface import invariant
83 from .interface import taggedValue
81 84
82 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 91 moduleProvides(IInterfaceDeclaration)
89 92
@@ -13,6 +13,8 b''
13 13 ##############################################################################
14 14 """Basic components support
15 15 """
16 from __future__ import absolute_import
17
16 18 import sys
17 19 import types
18 20
@@ -15,7 +15,10 b''
15 15
16 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 23 def _flatten(implements, include_None=0):
21 24
@@ -47,7 +47,8 b' import_declarations(void)'
47 47 {
48 48 PyObject *declarations, *i;
49 49
50 declarations = PyImport_ImportModule("zope.interface.declarations");
50 declarations = PyImport_ImportModule(
51 "mercurial.thirdparty.zope.interface.declarations");
51 52 if (declarations == NULL)
52 53 return -1;
53 54
@@ -1336,7 +1337,7 b' verifying_clear(verify *self)'
1336 1337 static void
1337 1338 verifying_dealloc(verify *self)
1338 1339 {
1339 PyObject_GC_UnTrack((PyObject *)self);
1340 PyObject_GC_UnTrack((PyObject *)self);
1340 1341 verifying_clear(self);
1341 1342 Py_TYPE(self)->tp_free((PyObject*)self);
1342 1343 }
@@ -13,16 +13,18 b''
13 13 ##############################################################################
14 14 """Adapter management
15 15 """
16 from __future__ import absolute_import
17
16 18 import weakref
17 19
18 from zope.interface import implementer
19 from zope.interface import providedBy
20 from zope.interface import Interface
21 from zope.interface import ro
22 from zope.interface.interfaces import IAdapterRegistry
20 from . import implementer
21 from . import providedBy
22 from . import Interface
23 from . import ro
24 from .interfaces import IAdapterRegistry
23 25
24 from zope.interface._compat import _normalize_name
25 from zope.interface._compat import STRING_TYPES
26 from ._compat import _normalize_name
27 from ._compat import STRING_TYPES
26 28
27 29 _BLANK = u''
28 30
@@ -409,7 +411,7 b' class LookupBaseFallback(object):'
409 411 LookupBasePy = LookupBaseFallback # BBB
410 412
411 413 try:
412 from zope.interface._zope_interface_coptimizations import LookupBase
414 from ._zope_interface_coptimizations import LookupBase
413 415 except ImportError:
414 416 LookupBase = LookupBaseFallback
415 417
@@ -445,7 +447,7 b' class VerifyingBaseFallback(LookupBaseFa'
445 447 VerifyingBasePy = VerifyingBaseFallback #BBB
446 448
447 449 try:
448 from zope.interface._zope_interface_coptimizations import VerifyingBase
450 from ._zope_interface_coptimizations import VerifyingBase
449 451 except ImportError:
450 452 VerifyingBase = VerifyingBaseFallback
451 453
@@ -25,6 +25,8 b' models, object-relational persistence, a'
25 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 30 from types import FunctionType
29 31 try:
30 32 from types import ClassType
@@ -1,7 +1,7 b''
1 1 ##############################################################################
2 2 # Copyright (c) 2002 Zope Foundation and Contributors.
3 3 # All Rights Reserved.
4 #
4 #
5 5 # This software is subject to the provisions of the Zope Public License,
6 6 # Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
7 7 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
@@ -15,8 +15,10 b' This module is called idatetime because '
15 15 of the real datetime would fail.
16 16 """
17 17
18 from zope.interface import Interface, Attribute
19 from zope.interface import classImplements
18 from __future__ import absolute_import
19
20 from .. import Interface, Attribute
21 from .. import classImplements
20 22
21 23 from datetime import timedelta, date, datetime, time, tzinfo
22 24
@@ -112,7 +114,7 b' class IDate(IDateClass):'
112 114
113 115 Except for those members given new values by whichever keyword
114 116 arguments are specified. For example, if d == date(2002, 12, 31), then
115 d.replace(day=26) == date(2000, 12, 26).
117 d.replace(day=26) == date(2000, 12, 26).
116 118 """
117 119
118 120 def timetuple():
@@ -232,7 +234,7 b' class IDateTimeClass(Interface):'
232 234 """Return the current UTC date and time, with tzinfo None.
233 235
234 236 This is like now(), but returns the current UTC date and time, as a
235 naive datetime object.
237 naive datetime object.
236 238
237 239 See also now().
238 240 """
@@ -357,7 +359,7 b' class IDateTime(IDate, IDateTimeClass):'
357 359 If you merely want to attach a time zone object tz to a datetime dt
358 360 without adjustment of date and time members, use dt.replace(tzinfo=tz).
359 361 If you merely want to remove the time zone object from an aware
360 datetime dt without conversion of date and time members, use
362 datetime dt without conversion of date and time members, use
361 363 dt.replace(tzinfo=None).
362 364
363 365 Note that the default tzinfo.fromutc() method can be overridden in a
@@ -13,8 +13,11 b''
13 13 ##############################################################################
14 14 """Interfaces for standard python exceptions
15 15 """
16 from zope.interface import Interface
17 from zope.interface import classImplements
16
17 from __future__ import absolute_import
18
19 from .. import Interface
20 from .. import classImplements
18 21
19 22 class IException(Interface): pass
20 23 class IStandardError(IException): pass
@@ -13,7 +13,10 b''
13 13 ##############################################################################
14 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 21 class IItemMapping(Interface):
19 22 """Simplest readable mapping object
@@ -42,13 +45,13 b' class IReadMapping(IItemMapping):'
42 45
43 46 class IWriteMapping(Interface):
44 47 """Mapping methods for changing data"""
45
48
46 49 def __delitem__(key):
47 50 """Delete a value from the mapping using the key."""
48 51
49 52 def __setitem__(key, value):
50 53 """Set a new item in the mapping."""
51
54
52 55
53 56 class IEnumerableMapping(IReadMapping):
54 57 """Mapping objects whose items can be enumerated.
@@ -89,32 +92,32 b' class IIterableMapping(IEnumerableMappin'
89 92 "iterate over items"
90 93
91 94 class IClonableMapping(Interface):
92
95
93 96 def copy():
94 97 "return copy of dict"
95 98
96 99 class IExtendedReadMapping(IIterableMapping):
97
100
98 101 def has_key(key):
99 102 """Tell if a key exists in the mapping; equivalent to __contains__"""
100 103
101 104 class IExtendedWriteMapping(IWriteMapping):
102
105
103 106 def clear():
104 107 "delete all items"
105
108
106 109 def update(d):
107 110 " Update D from E: for k in E.keys(): D[k] = E[k]"
108
111
109 112 def setdefault(key, default=None):
110 113 "D.setdefault(k[,d]) -> D.get(k,d), also set D[k]=d if k not in D"
111
114
112 115 def pop(k, *args):
113 116 """remove specified key and return the corresponding value
114 117 *args may contain a single default value, or may not be supplied.
115 If key is not found, default is returned if given, otherwise
118 If key is not found, default is returned if given, otherwise
116 119 KeyError is raised"""
117
120
118 121 def popitem():
119 122 """remove and return some (key, value) pair as a
120 123 2-tuple; but raise KeyError if mapping is empty"""
@@ -13,8 +13,11 b''
13 13 ##############################################################################
14 14 """Sequence Interfaces
15 15 """
16
17 from __future__ import absolute_import
18
16 19 __docformat__ = 'restructuredtext'
17 from zope.interface import Interface
20 from .. import Interface
18 21
19 22 class IMinimalSequence(Interface):
20 23 """Most basic sequence interface.
@@ -24,6 +24,8 b' There are three flavors of declarations:'
24 24 provided by objects.
25 25
26 26 """
27 from __future__ import absolute_import
28
27 29 __docformat__ = 'restructuredtext'
28 30
29 31 import sys
@@ -32,12 +34,12 b' from types import MethodType'
32 34 from types import ModuleType
33 35 import weakref
34 36
35 from zope.interface.advice import addClassAdvisor
36 from zope.interface.interface import InterfaceClass
37 from zope.interface.interface import SpecificationBase
38 from zope.interface.interface import Specification
39 from zope.interface._compat import CLASS_TYPES as DescriptorAwareMetaClasses
40 from zope.interface._compat import PYTHON3
37 from .advice import addClassAdvisor
38 from .interface import InterfaceClass
39 from .interface import SpecificationBase
40 from .interface import Specification
41 from ._compat import CLASS_TYPES as DescriptorAwareMetaClasses
42 from ._compat import PYTHON3
41 43
42 44 # Registry of class-implementation specifications
43 45 BuiltinImplementationSpecifications = {}
@@ -638,11 +640,11 b' ClassProvidesBase = ClassProvidesBaseFal'
638 640
639 641 # Try to get C base:
640 642 try:
641 import zope.interface._zope_interface_coptimizations
643 from . import _zope_interface_coptimizations
642 644 except ImportError:
643 645 pass
644 646 else:
645 from zope.interface._zope_interface_coptimizations import ClassProvidesBase
647 from ._zope_interface_coptimizations import ClassProvidesBase
646 648
647 649
648 650 class ClassProvides(Declaration, ClassProvidesBase):
@@ -915,15 +917,15 b' def _normalizeargs(sequence, output = No'
915 917 _empty = Declaration()
916 918
917 919 try:
918 import zope.interface._zope_interface_coptimizations
920 from . import _zope_interface_coptimizations
919 921 except ImportError:
920 922 pass
921 923 else:
922 from zope.interface._zope_interface_coptimizations import implementedBy
923 from zope.interface._zope_interface_coptimizations import providedBy
924 from zope.interface._zope_interface_coptimizations import (
924 from ._zope_interface_coptimizations import implementedBy
925 from ._zope_interface_coptimizations import providedBy
926 from ._zope_interface_coptimizations import (
925 927 getObjectSpecification)
926 from zope.interface._zope_interface_coptimizations import (
928 from ._zope_interface_coptimizations import (
927 929 ObjectSpecificationDescriptor)
928 930
929 931 objectSpecificationDescriptor = ObjectSpecificationDescriptor()
@@ -16,8 +16,10 b''
16 16 This module provides a function, asStructuredText, for rendering an
17 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 24 def asStructuredText(I, munge=0, rst=False):
23 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 44 bases = [base
43 45 for base in I.__bases__
44 if base is not zope.interface.Interface
46 if base is not Interface
45 47 ]
46 48 if bases:
47 49 outp(_justify_and_indent("This interface extends:", level, munge))
@@ -14,6 +14,8 b''
14 14 """Interface-specific exceptions
15 15 """
16 16
17 from __future__ import absolute_import
18
17 19 class Invalid(Exception):
18 20 """A specification is violated
19 21 """
@@ -13,7 +13,7 b''
13 13 ##############################################################################
14 14 """Interface object implementation
15 15 """
16 from __future__ import generators
16 from __future__ import absolute_import, generators
17 17
18 18 import sys
19 19 from types import MethodType
@@ -21,8 +21,8 b' from types import FunctionType'
21 21 import warnings
22 22 import weakref
23 23
24 from zope.interface.exceptions import Invalid
25 from zope.interface.ro import ro
24 from .exceptions import Invalid
25 from .ro import ro
26 26
27 27
28 28 CO_VARARGS = 4
@@ -114,7 +114,7 b' class SpecificationBasePy(object):'
114 114
115 115 SpecificationBase = SpecificationBasePy
116 116 try:
117 from zope.interface._zope_interface_coptimizations import SpecificationBase
117 from ._zope_interface_coptimizations import SpecificationBase
118 118 except ImportError:
119 119 pass
120 120
@@ -155,14 +155,14 b' class InterfaceBasePy(object):'
155 155
156 156 InterfaceBase = InterfaceBasePy
157 157 try:
158 from zope.interface._zope_interface_coptimizations import InterfaceBase
158 from ._zope_interface_coptimizations import InterfaceBase
159 159 except ImportError:
160 160 pass
161 161
162 162
163 163 adapter_hooks = []
164 164 try:
165 from zope.interface._zope_interface_coptimizations import adapter_hooks
165 from ._zope_interface_coptimizations import adapter_hooks
166 166 except ImportError:
167 167 pass
168 168
@@ -665,22 +665,22 b' def fromMethod(meth, interface=None, nam'
665 665
666 666 # Now we can create the interesting interfaces and wire them up:
667 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 671 classImplements(Attribute, IAttribute)
672 672
673 from zope.interface.interfaces import IMethod
673 from .interfaces import IMethod
674 674 classImplements(Method, IMethod)
675 675
676 from zope.interface.interfaces import IInterface
676 from .interfaces import IInterface
677 677 classImplements(InterfaceClass, IInterface)
678 678
679 from zope.interface.interfaces import ISpecification
679 from .interfaces import ISpecification
680 680 classImplements(Specification, ISpecification)
681 681
682 682 # We import this here to deal with module dependencies.
683 from zope.interface.declarations import implementedBy
684 from zope.interface.declarations import providedBy
685 from zope.interface.exceptions import InvalidInterface
686 from zope.interface.exceptions import BrokenImplementation
683 from .declarations import implementedBy
684 from .declarations import providedBy
685 from .exceptions import InvalidInterface
686 from .exceptions import BrokenImplementation
@@ -13,11 +13,14 b''
13 13 ##############################################################################
14 14 """Interface Package Interfaces
15 15 """
16
17 from __future__ import absolute_import
18
16 19 __docformat__ = 'restructuredtext'
17 20
18 from zope.interface.interface import Attribute
19 from zope.interface.interface import Interface
20 from zope.interface.declarations import implementer
21 from .interface import Attribute
22 from .interface import Interface
23 from .declarations import implementer
21 24
22 25
23 26 _BLANK = u''
@@ -447,10 +450,10 b' class IInterfaceDeclaration(Interface):'
447 450 Instances of ``C`` provide only ``I1``, ``I2``, and regardless of
448 451 whatever interfaces instances of ``A`` and ``B`` implement.
449 452 """
450
453
451 454 def implementer_only(*interfaces):
452 """Create a decorator for declaring the only interfaces implemented
453
455 """Create a decorator for declaring the only interfaces implemented
456
454 457 A callable is returned that makes an implements declaration on
455 458 objects passed to it.
456 459 """
@@ -13,31 +13,34 b''
13 13 ##############################################################################
14 14 """Basic components support
15 15 """
16
17 from __future__ import absolute_import
18
16 19 from collections import defaultdict
17 20
18 21 try:
19 from zope.event import notify
22 from ..event import notify
20 23 except ImportError: # pragma: no cover
21 24 def notify(*arg, **kw): pass
22 25
23 from zope.interface.interfaces import ISpecification
24 from zope.interface.interfaces import ComponentLookupError
25 from zope.interface.interfaces import IAdapterRegistration
26 from zope.interface.interfaces import IComponents
27 from zope.interface.interfaces import IHandlerRegistration
28 from zope.interface.interfaces import ISubscriptionAdapterRegistration
29 from zope.interface.interfaces import IUtilityRegistration
30 from zope.interface.interfaces import Registered
31 from zope.interface.interfaces import Unregistered
26 from .interfaces import ISpecification
27 from .interfaces import ComponentLookupError
28 from .interfaces import IAdapterRegistration
29 from .interfaces import IComponents
30 from .interfaces import IHandlerRegistration
31 from .interfaces import ISubscriptionAdapterRegistration
32 from .interfaces import IUtilityRegistration
33 from .interfaces import Registered
34 from .interfaces import Unregistered
32 35
33 from zope.interface.interface import Interface
34 from zope.interface.declarations import implementedBy
35 from zope.interface.declarations import implementer
36 from zope.interface.declarations import implementer_only
37 from zope.interface.declarations import providedBy
38 from zope.interface.adapter import AdapterRegistry
39 from zope.interface._compat import CLASS_TYPES
40 from zope.interface._compat import STRING_TYPES
36 from .interface import Interface
37 from .declarations import implementedBy
38 from .declarations import implementer
39 from .declarations import implementer_only
40 from .declarations import providedBy
41 from .adapter import AdapterRegistry
42 from ._compat import CLASS_TYPES
43 from ._compat import STRING_TYPES
41 44
42 45
43 46 class _UnhashableComponentCounter(object):
@@ -13,6 +13,9 b''
13 13 ##############################################################################
14 14 """Compute a resolution order for an object and its bases
15 15 """
16
17 from __future__ import absolute_import
18
16 19 __docformat__ = 'restructuredtext'
17 20
18 21 def _mergeOrderings(orderings):
@@ -13,10 +13,12 b''
13 13 ##############################################################################
14 14 """Verify interface implementations
15 15 """
16 from zope.interface.exceptions import BrokenImplementation, DoesNotImplement
17 from zope.interface.exceptions import BrokenMethodImplementation
16 from __future__ import absolute_import
17
18 from .exceptions import BrokenImplementation, DoesNotImplement
19 from .exceptions import BrokenMethodImplementation
18 20 from types import FunctionType, MethodType
19 from zope.interface.interface import fromMethod, fromFunction, Method
21 from .interface import fromMethod, fromFunction, Method
20 22 import sys
21 23
22 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