ยปCore Development>Code coverage>Lib/asyncio/base_futures.py

Python code coverage for Lib/asyncio/base_futures.py

#countcontent
1n/a__all__ = []
2n/a
3n/aimport concurrent.futures._base
4n/aimport reprlib
5n/a
6n/afrom . import events
7n/a
8n/aError = concurrent.futures._base.Error
9n/aCancelledError = concurrent.futures.CancelledError
10n/aTimeoutError = concurrent.futures.TimeoutError
11n/a
12n/a
13n/aclass InvalidStateError(Error):
14n/a """The operation is not allowed in this state."""
15n/a
16n/a
17n/a# States for Future.
18n/a_PENDING = 'PENDING'
19n/a_CANCELLED = 'CANCELLED'
20n/a_FINISHED = 'FINISHED'
21n/a
22n/a
23n/adef isfuture(obj):
24n/a """Check for a Future.
25n/a
26n/a This returns True when obj is a Future instance or is advertising
27n/a itself as duck-type compatible by setting _asyncio_future_blocking.
28n/a See comment in Future for more details.
29n/a """
30n/a return (hasattr(obj.__class__, '_asyncio_future_blocking') and
31n/a obj._asyncio_future_blocking is not None)
32n/a
33n/a
34n/adef _format_callbacks(cb):
35n/a """helper function for Future.__repr__"""
36n/a size = len(cb)
37n/a if not size:
38n/a cb = ''
39n/a
40n/a def format_cb(callback):
41n/a return events._format_callback_source(callback, ())
42n/a
43n/a if size == 1:
44n/a cb = format_cb(cb[0])
45n/a elif size == 2:
46n/a cb = '{}, {}'.format(format_cb(cb[0]), format_cb(cb[1]))
47n/a elif size > 2:
48n/a cb = '{}, <{} more>, {}'.format(format_cb(cb[0]),
49n/a size - 2,
50n/a format_cb(cb[-1]))
51n/a return 'cb=[%s]' % cb
52n/a
53n/a
54n/adef _future_repr_info(future):
55n/a # (Future) -> str
56n/a """helper function for Future.__repr__"""
57n/a info = [future._state.lower()]
58n/a if future._state == _FINISHED:
59n/a if future._exception is not None:
60n/a info.append('exception={!r}'.format(future._exception))
61n/a else:
62n/a # use reprlib to limit the length of the output, especially
63n/a # for very long strings
64n/a result = reprlib.repr(future._result)
65n/a info.append('result={}'.format(result))
66n/a if future._callbacks:
67n/a info.append(_format_callbacks(future._callbacks))
68n/a if future._source_traceback:
69n/a frame = future._source_traceback[-1]
70n/a info.append('created at %s:%s' % (frame[0], frame[1]))
71n/a return info