comparison mercurial/thirdparty/zope/interface/exceptions.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) 2002 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 """Interface-specific exceptions
15 """
16
17 class Invalid(Exception):
18 """A specification is violated
19 """
20
21 class DoesNotImplement(Invalid):
22 """ This object does not implement """
23 def __init__(self, interface):
24 self.interface = interface
25
26 def __str__(self):
27 return """An object does not implement interface %(interface)s
28
29 """ % self.__dict__
30
31 class BrokenImplementation(Invalid):
32 """An attribute is not completely implemented.
33 """
34
35 def __init__(self, interface, name):
36 self.interface=interface
37 self.name=name
38
39 def __str__(self):
40 return """An object has failed to implement interface %(interface)s
41
42 The %(name)s attribute was not provided.
43 """ % self.__dict__
44
45 class BrokenMethodImplementation(Invalid):
46 """An method is not completely implemented.
47 """
48
49 def __init__(self, method, mess):
50 self.method=method
51 self.mess=mess
52
53 def __str__(self):
54 return """The implementation of %(method)s violates its contract
55 because %(mess)s.
56 """ % self.__dict__
57
58 class InvalidInterface(Exception):
59 """The interface has invalid contents
60 """
61
62 class BadImplements(TypeError):
63 """An implementation assertion is invalid
64
65 because it doesn't contain an interface or a sequence of valid
66 implementation assertions.
67 """