|
22 | 22 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
23 | 23 | # SOFTWARE.
|
24 | 24 |
|
| 25 | +import core |
| 26 | +from .events import WrappedEvents |
25 | 27 |
|
26 | 28 |
|
27 | 29 | class ReqRep():
|
@@ -68,4 +70,48 @@ def iterator(event):
|
68 | 70 | bufchan.channel.channel.close()
|
69 | 71 | return iterator(event)
|
70 | 72 |
|
71 |
| -patterns_list = [ReqStream(), ReqRep()] |
| 73 | + |
| 74 | +class ReqContext(): |
| 75 | + |
| 76 | + def process_call(self, context, bufchan, event, functor): |
| 77 | + context_gen =context.middleware_call_procedure(functor, *event.args) |
| 78 | + methods = context_gen.next() |
| 79 | + wchannel = WrappedEvents(bufchan) |
| 80 | + server = core.ServerBase(wchannel, methods, heartbeat=None) |
| 81 | + bufchan.emit('CTX', (None,)) |
| 82 | + try: |
| 83 | + server.run() |
| 84 | + except Exception as e: |
| 85 | + try: |
| 86 | + context_gen.throw(e) |
| 87 | + except StopIteration: |
| 88 | + pass |
| 89 | + else: |
| 90 | + try: |
| 91 | + context_gen.next() |
| 92 | + except StopIteration: |
| 93 | + pass |
| 94 | + finally: |
| 95 | + server.close() |
| 96 | + wchannel.close() |
| 97 | + |
| 98 | + def accept_answer(self, event): |
| 99 | + return event.name == 'CTX' |
| 100 | + |
| 101 | + def process_answer(self, context, bufchan, event, method, |
| 102 | + raise_remote_error): |
| 103 | + if event.name == 'ERR': |
| 104 | + raise_remote_error(event) |
| 105 | + wchannel = WrappedEvents(bufchan) |
| 106 | + |
| 107 | + class ContextClient(core.ClientBase): |
| 108 | + def close(self): |
| 109 | + self._channel.emit('CTX_CLOSE', (None,)) |
| 110 | + super(ContextClient, self).close() |
| 111 | + bufchan.close() |
| 112 | + bufchan.channel.close() |
| 113 | + bufchan.channel.channel.close() |
| 114 | + |
| 115 | + return ContextClient(wchannel, heartbeat=None) |
| 116 | + |
| 117 | +patterns_list = [ReqContext(), ReqStream(), ReqRep()] |
0 commit comments