Mercurial > hg
changeset 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
line wrap: on
line diff
--- a/mercurial/thirdparty/zope/interface/__init__.py Wed Mar 21 19:49:07 2018 -0700 +++ b/mercurial/thirdparty/zope/interface/__init__.py Wed Mar 21 19:52:30 2018 -0700 @@ -48,42 +48,45 @@ See the module doc strings for more information. """ + +from __future__ import absolute_import + __docformat__ = 'restructuredtext' -from zope.interface.interface import Interface -from zope.interface.interface import _wire +from .interface import Interface +from .interface import _wire # Need to actually get the interface elements to implement the right interfaces _wire() del _wire -from zope.interface.declarations import Declaration -from zope.interface.declarations import alsoProvides -from zope.interface.declarations import classImplements -from zope.interface.declarations import classImplementsOnly -from zope.interface.declarations import classProvides -from zope.interface.declarations import directlyProvidedBy -from zope.interface.declarations import directlyProvides -from zope.interface.declarations import implementedBy -from zope.interface.declarations import implementer -from zope.interface.declarations import implementer_only -from zope.interface.declarations import implements -from zope.interface.declarations import implementsOnly -from zope.interface.declarations import moduleProvides -from zope.interface.declarations import named -from zope.interface.declarations import noLongerProvides -from zope.interface.declarations import providedBy -from zope.interface.declarations import provider -from zope.interface.exceptions import Invalid -from zope.interface.interface import Attribute -from zope.interface.interface import invariant -from zope.interface.interface import taggedValue +from .declarations import Declaration +from .declarations import alsoProvides +from .declarations import classImplements +from .declarations import classImplementsOnly +from .declarations import classProvides +from .declarations import directlyProvidedBy +from .declarations import directlyProvides +from .declarations import implementedBy +from .declarations import implementer +from .declarations import implementer_only +from .declarations import implements +from .declarations import implementsOnly +from .declarations import moduleProvides +from .declarations import named +from .declarations import noLongerProvides +from .declarations import providedBy +from .declarations import provider +from .exceptions import Invalid +from .interface import Attribute +from .interface import invariant +from .interface import taggedValue # The following are to make spec pickles cleaner -from zope.interface.declarations import Provides +from .declarations import Provides -from zope.interface.interfaces import IInterfaceDeclaration +from .interfaces import IInterfaceDeclaration moduleProvides(IInterfaceDeclaration)
--- a/mercurial/thirdparty/zope/interface/_compat.py Wed Mar 21 19:49:07 2018 -0700 +++ b/mercurial/thirdparty/zope/interface/_compat.py Wed Mar 21 19:52:30 2018 -0700 @@ -13,6 +13,8 @@ ############################################################################## """Basic components support """ +from __future__ import absolute_import + import sys import types
--- a/mercurial/thirdparty/zope/interface/_flatten.py Wed Mar 21 19:49:07 2018 -0700 +++ b/mercurial/thirdparty/zope/interface/_flatten.py Wed Mar 21 19:52:30 2018 -0700 @@ -15,7 +15,10 @@ See Adapter class. """ -from zope.interface import Declaration + +from __future__ import absolute_import + +from .interface import Declaration def _flatten(implements, include_None=0):
--- a/mercurial/thirdparty/zope/interface/_zope_interface_coptimizations.c Wed Mar 21 19:49:07 2018 -0700 +++ b/mercurial/thirdparty/zope/interface/_zope_interface_coptimizations.c Wed Mar 21 19:52:30 2018 -0700 @@ -47,7 +47,8 @@ { PyObject *declarations, *i; - declarations = PyImport_ImportModule("zope.interface.declarations"); + declarations = PyImport_ImportModule( + "mercurial.thirdparty.zope.interface.declarations"); if (declarations == NULL) return -1; @@ -1336,7 +1337,7 @@ static void verifying_dealloc(verify *self) { - PyObject_GC_UnTrack((PyObject *)self); + PyObject_GC_UnTrack((PyObject *)self); verifying_clear(self); Py_TYPE(self)->tp_free((PyObject*)self); }
--- a/mercurial/thirdparty/zope/interface/adapter.py Wed Mar 21 19:49:07 2018 -0700 +++ b/mercurial/thirdparty/zope/interface/adapter.py Wed Mar 21 19:52:30 2018 -0700 @@ -13,16 +13,18 @@ ############################################################################## """Adapter management """ +from __future__ import absolute_import + import weakref -from zope.interface import implementer -from zope.interface import providedBy -from zope.interface import Interface -from zope.interface import ro -from zope.interface.interfaces import IAdapterRegistry +from . import implementer +from . import providedBy +from . import Interface +from . import ro +from .interfaces import IAdapterRegistry -from zope.interface._compat import _normalize_name -from zope.interface._compat import STRING_TYPES +from ._compat import _normalize_name +from ._compat import STRING_TYPES _BLANK = u'' @@ -409,7 +411,7 @@ LookupBasePy = LookupBaseFallback # BBB try: - from zope.interface._zope_interface_coptimizations import LookupBase + from ._zope_interface_coptimizations import LookupBase except ImportError: LookupBase = LookupBaseFallback @@ -445,7 +447,7 @@ VerifyingBasePy = VerifyingBaseFallback #BBB try: - from zope.interface._zope_interface_coptimizations import VerifyingBase + from ._zope_interface_coptimizations import VerifyingBase except ImportError: VerifyingBase = VerifyingBaseFallback
--- a/mercurial/thirdparty/zope/interface/advice.py Wed Mar 21 19:49:07 2018 -0700 +++ b/mercurial/thirdparty/zope/interface/advice.py Wed Mar 21 19:52:30 2018 -0700 @@ -25,6 +25,8 @@ Visit the PEAK home page at http://peak.telecommunity.com for more information. """ +from __future__ import absolute_import + from types import FunctionType try: from types import ClassType
--- a/mercurial/thirdparty/zope/interface/common/idatetime.py Wed Mar 21 19:49:07 2018 -0700 +++ b/mercurial/thirdparty/zope/interface/common/idatetime.py Wed Mar 21 19:52:30 2018 -0700 @@ -1,7 +1,7 @@ ############################################################################## # Copyright (c) 2002 Zope Foundation and Contributors. # All Rights Reserved. -# +# # This software is subject to the provisions of the Zope Public License, # Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED @@ -15,8 +15,10 @@ of the real datetime would fail. """ -from zope.interface import Interface, Attribute -from zope.interface import classImplements +from __future__ import absolute_import + +from .. import Interface, Attribute +from .. import classImplements from datetime import timedelta, date, datetime, time, tzinfo @@ -112,7 +114,7 @@ Except for those members given new values by whichever keyword arguments are specified. For example, if d == date(2002, 12, 31), then - d.replace(day=26) == date(2000, 12, 26). + d.replace(day=26) == date(2000, 12, 26). """ def timetuple(): @@ -232,7 +234,7 @@ """Return the current UTC date and time, with tzinfo None. This is like now(), but returns the current UTC date and time, as a - naive datetime object. + naive datetime object. See also now(). """ @@ -357,7 +359,7 @@ If you merely want to attach a time zone object tz to a datetime dt without adjustment of date and time members, use dt.replace(tzinfo=tz). If you merely want to remove the time zone object from an aware - datetime dt without conversion of date and time members, use + datetime dt without conversion of date and time members, use dt.replace(tzinfo=None). Note that the default tzinfo.fromutc() method can be overridden in a
--- a/mercurial/thirdparty/zope/interface/common/interfaces.py Wed Mar 21 19:49:07 2018 -0700 +++ b/mercurial/thirdparty/zope/interface/common/interfaces.py Wed Mar 21 19:52:30 2018 -0700 @@ -13,8 +13,11 @@ ############################################################################## """Interfaces for standard python exceptions """ -from zope.interface import Interface -from zope.interface import classImplements + +from __future__ import absolute_import + +from .. import Interface +from .. import classImplements class IException(Interface): pass class IStandardError(IException): pass
--- a/mercurial/thirdparty/zope/interface/common/mapping.py Wed Mar 21 19:49:07 2018 -0700 +++ b/mercurial/thirdparty/zope/interface/common/mapping.py Wed Mar 21 19:52:30 2018 -0700 @@ -13,7 +13,10 @@ ############################################################################## """Mapping Interfaces """ -from zope.interface import Interface + +from __future__ import absolute_import + +from .. import Interface class IItemMapping(Interface): """Simplest readable mapping object @@ -42,13 +45,13 @@ class IWriteMapping(Interface): """Mapping methods for changing data""" - + def __delitem__(key): """Delete a value from the mapping using the key.""" def __setitem__(key, value): """Set a new item in the mapping.""" - + class IEnumerableMapping(IReadMapping): """Mapping objects whose items can be enumerated. @@ -89,32 +92,32 @@ "iterate over items" class IClonableMapping(Interface): - + def copy(): "return copy of dict" class IExtendedReadMapping(IIterableMapping): - + def has_key(key): """Tell if a key exists in the mapping; equivalent to __contains__""" class IExtendedWriteMapping(IWriteMapping): - + def clear(): "delete all items" - + def update(d): " Update D from E: for k in E.keys(): D[k] = E[k]" - + def setdefault(key, default=None): "D.setdefault(k[,d]) -> D.get(k,d), also set D[k]=d if k not in D" - + def pop(k, *args): """remove specified key and return the corresponding value *args may contain a single default value, or may not be supplied. - If key is not found, default is returned if given, otherwise + If key is not found, default is returned if given, otherwise KeyError is raised""" - + def popitem(): """remove and return some (key, value) pair as a 2-tuple; but raise KeyError if mapping is empty"""
--- a/mercurial/thirdparty/zope/interface/common/sequence.py Wed Mar 21 19:49:07 2018 -0700 +++ b/mercurial/thirdparty/zope/interface/common/sequence.py Wed Mar 21 19:52:30 2018 -0700 @@ -13,8 +13,11 @@ ############################################################################## """Sequence Interfaces """ + +from __future__ import absolute_import + __docformat__ = 'restructuredtext' -from zope.interface import Interface +from .. import Interface class IMinimalSequence(Interface): """Most basic sequence interface.
--- a/mercurial/thirdparty/zope/interface/declarations.py Wed Mar 21 19:49:07 2018 -0700 +++ b/mercurial/thirdparty/zope/interface/declarations.py Wed Mar 21 19:52:30 2018 -0700 @@ -24,6 +24,8 @@ provided by objects. """ +from __future__ import absolute_import + __docformat__ = 'restructuredtext' import sys @@ -32,12 +34,12 @@ from types import ModuleType import weakref -from zope.interface.advice import addClassAdvisor -from zope.interface.interface import InterfaceClass -from zope.interface.interface import SpecificationBase -from zope.interface.interface import Specification -from zope.interface._compat import CLASS_TYPES as DescriptorAwareMetaClasses -from zope.interface._compat import PYTHON3 +from .advice import addClassAdvisor +from .interface import InterfaceClass +from .interface import SpecificationBase +from .interface import Specification +from ._compat import CLASS_TYPES as DescriptorAwareMetaClasses +from ._compat import PYTHON3 # Registry of class-implementation specifications BuiltinImplementationSpecifications = {} @@ -638,11 +640,11 @@ # Try to get C base: try: - import zope.interface._zope_interface_coptimizations + from . import _zope_interface_coptimizations except ImportError: pass else: - from zope.interface._zope_interface_coptimizations import ClassProvidesBase + from ._zope_interface_coptimizations import ClassProvidesBase class ClassProvides(Declaration, ClassProvidesBase): @@ -915,15 +917,15 @@ _empty = Declaration() try: - import zope.interface._zope_interface_coptimizations + from . import _zope_interface_coptimizations except ImportError: pass else: - from zope.interface._zope_interface_coptimizations import implementedBy - from zope.interface._zope_interface_coptimizations import providedBy - from zope.interface._zope_interface_coptimizations import ( + from ._zope_interface_coptimizations import implementedBy + from ._zope_interface_coptimizations import providedBy + from ._zope_interface_coptimizations import ( getObjectSpecification) - from zope.interface._zope_interface_coptimizations import ( + from ._zope_interface_coptimizations import ( ObjectSpecificationDescriptor) objectSpecificationDescriptor = ObjectSpecificationDescriptor()
--- a/mercurial/thirdparty/zope/interface/document.py Wed Mar 21 19:49:07 2018 -0700 +++ b/mercurial/thirdparty/zope/interface/document.py Wed Mar 21 19:52:30 2018 -0700 @@ -16,8 +16,10 @@ This module provides a function, asStructuredText, for rendering an interface as structured text. """ -import zope.interface +from __future__ import absolute_import + +from . import Interface def asStructuredText(I, munge=0, rst=False): """ Output structured text format. Note, this will whack any existing @@ -41,7 +43,7 @@ bases = [base for base in I.__bases__ - if base is not zope.interface.Interface + if base is not Interface ] if bases: outp(_justify_and_indent("This interface extends:", level, munge))
--- a/mercurial/thirdparty/zope/interface/exceptions.py Wed Mar 21 19:49:07 2018 -0700 +++ b/mercurial/thirdparty/zope/interface/exceptions.py Wed Mar 21 19:52:30 2018 -0700 @@ -14,6 +14,8 @@ """Interface-specific exceptions """ +from __future__ import absolute_import + class Invalid(Exception): """A specification is violated """
--- a/mercurial/thirdparty/zope/interface/interface.py Wed Mar 21 19:49:07 2018 -0700 +++ b/mercurial/thirdparty/zope/interface/interface.py Wed Mar 21 19:52:30 2018 -0700 @@ -13,7 +13,7 @@ ############################################################################## """Interface object implementation """ -from __future__ import generators +from __future__ import absolute_import, generators import sys from types import MethodType @@ -21,8 +21,8 @@ import warnings import weakref -from zope.interface.exceptions import Invalid -from zope.interface.ro import ro +from .exceptions import Invalid +from .ro import ro CO_VARARGS = 4 @@ -114,7 +114,7 @@ SpecificationBase = SpecificationBasePy try: - from zope.interface._zope_interface_coptimizations import SpecificationBase + from ._zope_interface_coptimizations import SpecificationBase except ImportError: pass @@ -155,14 +155,14 @@ InterfaceBase = InterfaceBasePy try: - from zope.interface._zope_interface_coptimizations import InterfaceBase + from ._zope_interface_coptimizations import InterfaceBase except ImportError: pass adapter_hooks = [] try: - from zope.interface._zope_interface_coptimizations import adapter_hooks + from ._zope_interface_coptimizations import adapter_hooks except ImportError: pass @@ -665,22 +665,22 @@ # Now we can create the interesting interfaces and wire them up: def _wire(): - from zope.interface.declarations import classImplements + from .declarations import classImplements - from zope.interface.interfaces import IAttribute + from .interfaces import IAttribute classImplements(Attribute, IAttribute) - from zope.interface.interfaces import IMethod + from .interfaces import IMethod classImplements(Method, IMethod) - from zope.interface.interfaces import IInterface + from .interfaces import IInterface classImplements(InterfaceClass, IInterface) - from zope.interface.interfaces import ISpecification + from .interfaces import ISpecification classImplements(Specification, ISpecification) # We import this here to deal with module dependencies. -from zope.interface.declarations import implementedBy -from zope.interface.declarations import providedBy -from zope.interface.exceptions import InvalidInterface -from zope.interface.exceptions import BrokenImplementation +from .declarations import implementedBy +from .declarations import providedBy +from .exceptions import InvalidInterface +from .exceptions import BrokenImplementation
--- a/mercurial/thirdparty/zope/interface/interfaces.py Wed Mar 21 19:49:07 2018 -0700 +++ b/mercurial/thirdparty/zope/interface/interfaces.py Wed Mar 21 19:52:30 2018 -0700 @@ -13,11 +13,14 @@ ############################################################################## """Interface Package Interfaces """ + +from __future__ import absolute_import + __docformat__ = 'restructuredtext' -from zope.interface.interface import Attribute -from zope.interface.interface import Interface -from zope.interface.declarations import implementer +from .interface import Attribute +from .interface import Interface +from .declarations import implementer _BLANK = u'' @@ -447,10 +450,10 @@ Instances of ``C`` provide only ``I1``, ``I2``, and regardless of whatever interfaces instances of ``A`` and ``B`` implement. """ - + def implementer_only(*interfaces): - """Create a decorator for declaring the only interfaces implemented - + """Create a decorator for declaring the only interfaces implemented + A callable is returned that makes an implements declaration on objects passed to it. """
--- a/mercurial/thirdparty/zope/interface/registry.py Wed Mar 21 19:49:07 2018 -0700 +++ b/mercurial/thirdparty/zope/interface/registry.py Wed Mar 21 19:52:30 2018 -0700 @@ -13,31 +13,34 @@ ############################################################################## """Basic components support """ + +from __future__ import absolute_import + from collections import defaultdict try: - from zope.event import notify + from ..event import notify except ImportError: # pragma: no cover def notify(*arg, **kw): pass -from zope.interface.interfaces import ISpecification -from zope.interface.interfaces import ComponentLookupError -from zope.interface.interfaces import IAdapterRegistration -from zope.interface.interfaces import IComponents -from zope.interface.interfaces import IHandlerRegistration -from zope.interface.interfaces import ISubscriptionAdapterRegistration -from zope.interface.interfaces import IUtilityRegistration -from zope.interface.interfaces import Registered -from zope.interface.interfaces import Unregistered +from .interfaces import ISpecification +from .interfaces import ComponentLookupError +from .interfaces import IAdapterRegistration +from .interfaces import IComponents +from .interfaces import IHandlerRegistration +from .interfaces import ISubscriptionAdapterRegistration +from .interfaces import IUtilityRegistration +from .interfaces import Registered +from .interfaces import Unregistered -from zope.interface.interface import Interface -from zope.interface.declarations import implementedBy -from zope.interface.declarations import implementer -from zope.interface.declarations import implementer_only -from zope.interface.declarations import providedBy -from zope.interface.adapter import AdapterRegistry -from zope.interface._compat import CLASS_TYPES -from zope.interface._compat import STRING_TYPES +from .interface import Interface +from .declarations import implementedBy +from .declarations import implementer +from .declarations import implementer_only +from .declarations import providedBy +from .adapter import AdapterRegistry +from ._compat import CLASS_TYPES +from ._compat import STRING_TYPES class _UnhashableComponentCounter(object):
--- a/mercurial/thirdparty/zope/interface/ro.py Wed Mar 21 19:49:07 2018 -0700 +++ b/mercurial/thirdparty/zope/interface/ro.py Wed Mar 21 19:52:30 2018 -0700 @@ -13,6 +13,9 @@ ############################################################################## """Compute a resolution order for an object and its bases """ + +from __future__ import absolute_import + __docformat__ = 'restructuredtext' def _mergeOrderings(orderings):
--- a/mercurial/thirdparty/zope/interface/verify.py Wed Mar 21 19:49:07 2018 -0700 +++ b/mercurial/thirdparty/zope/interface/verify.py Wed Mar 21 19:52:30 2018 -0700 @@ -13,10 +13,12 @@ ############################################################################## """Verify interface implementations """ -from zope.interface.exceptions import BrokenImplementation, DoesNotImplement -from zope.interface.exceptions import BrokenMethodImplementation +from __future__ import absolute_import + +from .exceptions import BrokenImplementation, DoesNotImplement +from .exceptions import BrokenMethodImplementation from types import FunctionType, MethodType -from zope.interface.interface import fromMethod, fromFunction, Method +from .interface import fromMethod, fromFunction, Method import sys # This will be monkey-patched when running under Zope 2, so leave this