comparison mercurial/thirdparty/zope/interface/common/interfaces.py @ 37176:943d77fc07a3

thirdparty: vendor zope.interface 4.4.3 I've been trying to formalize interfaces for various components of Mercurial. So far, we've been using the "abc" package. This package is "good enough" for a lot of tasks. But it quickly falls over. For example, if you declare an @abc.abstractproperty, you must implement that attribute with a @property or the class compile time checking performed by abc will complain. This often forces you to implement dumb @property wrappers to return a _ prefixed attribute of the sane name. That's ugly. I've also wanted to implement automated checking that classes conform to various interfaces and don't expose other "public" attributes. After doing a bit of research and asking around, the general consensus seems to be that zope.interface is the best package for doing interface-based programming in Python. It has built-in support for verifying classes and objects conform to interfaces. It allows an interface's properties to be defined during __init__. There's even an "adapter registry" that allow you to register interfaces and look up which classes implement them. That could potentially be useful for places where our custom registry.py modules currently facilitates central registrations, but at a type level. Imagine extensions providing alternate implementations of things like the local repository interface to allow opening repositories with custom requirements. Anyway, this commit vendors zope.interface 4.4.3. The contents of the source tarball have been copied into mercurial/thirdparty/zope/ without modifications. Test modules have been removed because they are not interesting to us. The LICENSE.txt file has been copied so it lives next to the source. The Python modules don't use relative imports. zope/__init__.py defines a namespace package. So we'll need to modify the source code before this package is usable inside Mercurial. This will be done in subsequent commits. # no-check-commit for various style failures Differential Revision: https://phab.mercurial-scm.org/D2928
author Gregory Szorc <gregory.szorc@gmail.com>
date Wed, 21 Mar 2018 19:48:50 -0700
parents
children 68ee61822182
comparison
equal deleted inserted replaced
37175:fbe34945220d 37176:943d77fc07a3
1 ##############################################################################
2 #
3 # Copyright (c) 2003 Zope Foundation and Contributors.
4 # All Rights Reserved.
5 #
6 # This software is subject to the provisions of the Zope Public License,
7 # Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
8 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
9 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
10 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
11 # FOR A PARTICULAR PURPOSE.
12 #
13 ##############################################################################
14 """Interfaces for standard python exceptions
15 """
16 from zope.interface import Interface
17 from zope.interface import classImplements
18
19 class IException(Interface): pass
20 class IStandardError(IException): pass
21 class IWarning(IException): pass
22 class ISyntaxError(IStandardError): pass
23 class ILookupError(IStandardError): pass
24 class IValueError(IStandardError): pass
25 class IRuntimeError(IStandardError): pass
26 class IArithmeticError(IStandardError): pass
27 class IAssertionError(IStandardError): pass
28 class IAttributeError(IStandardError): pass
29 class IDeprecationWarning(IWarning): pass
30 class IEOFError(IStandardError): pass
31 class IEnvironmentError(IStandardError): pass
32 class IFloatingPointError(IArithmeticError): pass
33 class IIOError(IEnvironmentError): pass
34 class IImportError(IStandardError): pass
35 class IIndentationError(ISyntaxError): pass
36 class IIndexError(ILookupError): pass
37 class IKeyError(ILookupError): pass
38 class IKeyboardInterrupt(IStandardError): pass
39 class IMemoryError(IStandardError): pass
40 class INameError(IStandardError): pass
41 class INotImplementedError(IRuntimeError): pass
42 class IOSError(IEnvironmentError): pass
43 class IOverflowError(IArithmeticError): pass
44 class IOverflowWarning(IWarning): pass
45 class IReferenceError(IStandardError): pass
46 class IRuntimeWarning(IWarning): pass
47 class IStopIteration(IException): pass
48 class ISyntaxWarning(IWarning): pass
49 class ISystemError(IStandardError): pass
50 class ISystemExit(IException): pass
51 class ITabError(IIndentationError): pass
52 class ITypeError(IStandardError): pass
53 class IUnboundLocalError(INameError): pass
54 class IUnicodeError(IValueError): pass
55 class IUserWarning(IWarning): pass
56 class IZeroDivisionError(IArithmeticError): pass
57
58 classImplements(ArithmeticError, IArithmeticError)
59 classImplements(AssertionError, IAssertionError)
60 classImplements(AttributeError, IAttributeError)
61 classImplements(DeprecationWarning, IDeprecationWarning)
62 classImplements(EnvironmentError, IEnvironmentError)
63 classImplements(EOFError, IEOFError)
64 classImplements(Exception, IException)
65 classImplements(FloatingPointError, IFloatingPointError)
66 classImplements(ImportError, IImportError)
67 classImplements(IndentationError, IIndentationError)
68 classImplements(IndexError, IIndexError)
69 classImplements(IOError, IIOError)
70 classImplements(KeyboardInterrupt, IKeyboardInterrupt)
71 classImplements(KeyError, IKeyError)
72 classImplements(LookupError, ILookupError)
73 classImplements(MemoryError, IMemoryError)
74 classImplements(NameError, INameError)
75 classImplements(NotImplementedError, INotImplementedError)
76 classImplements(OSError, IOSError)
77 classImplements(OverflowError, IOverflowError)
78 try:
79 classImplements(OverflowWarning, IOverflowWarning)
80 except NameError: #pragma NO COVER
81 pass # OverflowWarning was removed in Python 2.5
82 classImplements(ReferenceError, IReferenceError)
83 classImplements(RuntimeError, IRuntimeError)
84 classImplements(RuntimeWarning, IRuntimeWarning)
85 try:
86 classImplements(StandardError, IStandardError)
87 except NameError: #pragma NO COVER
88 pass # StandardError does not exist in Python 3
89 classImplements(StopIteration, IStopIteration)
90 classImplements(SyntaxError, ISyntaxError)
91 classImplements(SyntaxWarning, ISyntaxWarning)
92 classImplements(SystemError, ISystemError)
93 classImplements(SystemExit, ISystemExit)
94 classImplements(TabError, ITabError)
95 classImplements(TypeError, ITypeError)
96 classImplements(UnboundLocalError, IUnboundLocalError)
97 classImplements(UnicodeError, IUnicodeError)
98 classImplements(UserWarning, IUserWarning)
99 classImplements(ValueError, IValueError)
100 classImplements(Warning, IWarning)
101 classImplements(ZeroDivisionError, IZeroDivisionError)
102