|
2 | 2 | Call loop machinery
|
3 | 3 | """
|
4 | 4 | import sys
|
5 |
| -import warnings |
6 | 5 |
|
7 |
| -_py3 = sys.version_info > (3, 0) |
8 |
| - |
9 |
| - |
10 |
| -if not _py3: |
11 |
| - exec( |
12 |
| - """ |
13 |
| -def _reraise(cls, val, tb): |
14 |
| - raise cls, val, tb |
15 |
| -""" |
16 |
| - ) |
17 |
| - |
18 |
| - |
19 |
| -def _raise_wrapfail(wrap_controller, msg): |
20 |
| - co = wrap_controller.gi_code |
21 |
| - raise RuntimeError( |
22 |
| - "wrap_controller at %r %s:%d %s" |
23 |
| - % (co.co_name, co.co_filename, co.co_firstlineno, msg) |
24 |
| - ) |
25 |
| - |
26 |
| - |
27 |
| -class HookCallError(Exception): |
28 |
| - """ Hook was called wrongly. """ |
29 |
| - |
30 |
| - |
31 |
| -class _Result(object): |
32 |
| - def __init__(self, result, excinfo): |
33 |
| - self._result = result |
34 |
| - self._excinfo = excinfo |
35 |
| - |
36 |
| - @property |
37 |
| - def excinfo(self): |
38 |
| - return self._excinfo |
39 |
| - |
40 |
| - @property |
41 |
| - def result(self): |
42 |
| - """Get the result(s) for this hook call (DEPRECATED in favor of ``get_result()``).""" |
43 |
| - msg = "Use get_result() which forces correct exception handling" |
44 |
| - warnings.warn(DeprecationWarning(msg), stacklevel=2) |
45 |
| - return self._result |
46 |
| - |
47 |
| - @classmethod |
48 |
| - def from_call(cls, func): |
49 |
| - __tracebackhide__ = True |
50 |
| - result = excinfo = None |
51 |
| - try: |
52 |
| - result = func() |
53 |
| - except BaseException: |
54 |
| - excinfo = sys.exc_info() |
55 |
| - |
56 |
| - return cls(result, excinfo) |
57 |
| - |
58 |
| - def force_result(self, result): |
59 |
| - """Force the result(s) to ``result``. |
60 |
| -
|
61 |
| - If the hook was marked as a ``firstresult`` a single value should |
62 |
| - be set otherwise set a (modified) list of results. Any exceptions |
63 |
| - found during invocation will be deleted. |
64 |
| - """ |
65 |
| - self._result = result |
66 |
| - self._excinfo = None |
67 |
| - |
68 |
| - def get_result(self): |
69 |
| - """Get the result(s) for this hook call. |
70 |
| -
|
71 |
| - If the hook was marked as a ``firstresult`` only a single value |
72 |
| - will be returned otherwise a list of results. |
73 |
| - """ |
74 |
| - __tracebackhide__ = True |
75 |
| - if self._excinfo is None: |
76 |
| - return self._result |
77 |
| - else: |
78 |
| - ex = self._excinfo |
79 |
| - if _py3: |
80 |
| - raise ex[1].with_traceback(ex[2]) |
81 |
| - _reraise(*ex) # noqa |
| 6 | +from ._result import HookCallError, _Result, _raise_wrapfail |
82 | 7 |
|
83 | 8 |
|
84 | 9 | def _multicall(hook_impls, caller_kwargs, firstresult=False):
|
|
0 commit comments