Total Complexity | 9 |
Total Lines | 25 |
Duplicated Lines | 0 % |
Coverage | 100% |
1 | # -*- coding: utf-8 -*- |
||
40 | 1 | class InjectionContext(object): |
|
41 | |||
42 | 1 | def __init__(self, injector, inherit=False): |
|
43 | 1 | if _stack.is_empty: |
|
44 | 1 | if callable(injector): |
|
45 | 1 | injector = injector() |
|
46 | |||
47 | 1 | self._push(injector) |
|
48 | 1 | elif inherit: |
|
49 | 1 | if callable(injector): |
|
50 | 1 | injector = injector() |
|
51 | |||
52 | 1 | injector = merge_injectors(_stack.top.injector, injector) |
|
53 | 1 | self._push(injector) |
|
54 | |||
55 | 1 | def _push(self, injector): |
|
56 | 1 | item = StackItem(injector, self) |
|
57 | 1 | _stack.push(item) |
|
58 | |||
59 | 1 | def __enter__(self): |
|
60 | 1 | return _stack.top.injector |
|
61 | |||
62 | 1 | def __exit__(self, type, value, traceback): |
|
63 | 1 | if _stack.top.parent is self: |
|
64 | _stack.pop() |
||
65 |