Coverage for /home/martinb/.local/share/virtualenvs/camcops/lib/python3.6/site-packages/vine/abstract.py : 0%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""Abstract classes."""
2from __future__ import absolute_import, unicode_literals
4import abc
6from .five import with_metaclass, Callable
8__all__ = ['Thenable']
11@with_metaclass(abc.ABCMeta)
12class Thenable(Callable): # pragma: no cover
13 """Object that supports ``.then()``."""
15 __slots__ = ()
17 @abc.abstractmethod
18 def then(self, on_success, on_error=None):
19 raise NotImplementedError()
21 @abc.abstractmethod
22 def throw(self, exc=None, tb=None, propagate=True):
23 raise NotImplementedError()
25 @abc.abstractmethod
26 def cancel(self):
27 raise NotImplementedError()
29 @classmethod
30 def __subclasshook__(cls, C):
31 if cls is Thenable:
32 if any('then' in B.__dict__ for B in C.__mro__):
33 return True
34 return NotImplemented
36 @classmethod
37 def register(cls, other):
38 # overide to return other so `register` can be used as a decorator
39 type(cls).register(cls, other)
40 return other
43@Thenable.register
44class ThenableProxy(object):
45 """Proxy to object that supports ``.then()``."""
47 def _set_promise_target(self, p):
48 self._p = p
50 def then(self, on_success, on_error=None):
51 return self._p.then(on_success, on_error)
53 def cancel(self):
54 return self._p.cancel()
56 def throw1(self, exc=None):
57 return self._p.throw1(exc)
59 def throw(self, exc=None, tb=None, propagate=True):
60 return self._p.throw(exc, tb=tb, propagate=propagate)
62 @property
63 def cancelled(self):
64 return self._p.cancelled
66 @property
67 def ready(self):
68 return self._p.ready
70 @property
71 def failed(self):
72 return self._p.failed