| 1 |
# Copyright 2017 gRPC authors. |
| 2 |
# |
| 3 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
# you may not use this file except in compliance with the License. |
| 5 |
# You may obtain a copy of the License at |
| 6 |
# |
| 7 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
# |
| 9 |
# Unless required by applicable law or agreed to in writing, software |
| 10 |
# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
# See the License for the specific language governing permissions and |
| 13 |
# limitations under the License. |
| 14 |
|
| 15 |
import grpc_testing |
| 16 |
|
| 17 |
|
| 18 |
class _UnaryUnary(grpc_testing.UnaryUnaryChannelRpc): |
| 19 |
|
| 20 |
def __init__(self, rpc_state): |
| 21 |
self._rpc_state = rpc_state |
| 22 |
|
| 23 |
def send_initial_metadata(self, initial_metadata): |
| 24 |
self._rpc_state.send_initial_metadata(initial_metadata) |
| 25 |
|
| 26 |
def cancelled(self): |
| 27 |
self._rpc_state.cancelled() |
| 28 |
|
| 29 |
def terminate(self, response, trailing_metadata, code, details): |
| 30 |
self._rpc_state.terminate_with_response(response, trailing_metadata, |
| 31 |
code, details) |
| 32 |
|
| 33 |
|
| 34 |
class _UnaryStream(grpc_testing.UnaryStreamChannelRpc): |
| 35 |
|
| 36 |
def __init__(self, rpc_state): |
| 37 |
self._rpc_state = rpc_state |
| 38 |
|
| 39 |
def send_initial_metadata(self, initial_metadata): |
| 40 |
self._rpc_state.send_initial_metadata(initial_metadata) |
| 41 |
|
| 42 |
def send_response(self, response): |
| 43 |
self._rpc_state.send_response(response) |
| 44 |
|
| 45 |
def cancelled(self): |
| 46 |
self._rpc_state.cancelled() |
| 47 |
|
| 48 |
def terminate(self, trailing_metadata, code, details): |
| 49 |
self._rpc_state.terminate(trailing_metadata, code, details) |
| 50 |
|
| 51 |
|
| 52 |
class _StreamUnary(grpc_testing.StreamUnaryChannelRpc): |
| 53 |
|
| 54 |
def __init__(self, rpc_state): |
| 55 |
self._rpc_state = rpc_state |
| 56 |
|
| 57 |
def send_initial_metadata(self, initial_metadata): |
| 58 |
self._rpc_state.send_initial_metadata(initial_metadata) |
| 59 |
|
| 60 |
def take_request(self): |
| 61 |
return self._rpc_state.take_request() |
| 62 |
|
| 63 |
def requests_closed(self): |
| 64 |
return self._rpc_state.requests_closed() |
| 65 |
|
| 66 |
def cancelled(self): |
| 67 |
self._rpc_state.cancelled() |
| 68 |
|
| 69 |
def terminate(self, response, trailing_metadata, code, details): |
| 70 |
self._rpc_state.terminate_with_response(response, trailing_metadata, |
| 71 |
code, details) |
| 72 |
|
| 73 |
|
| 74 |
class _StreamStream(grpc_testing.StreamStreamChannelRpc): |
| 75 |
|
| 76 |
def __init__(self, rpc_state): |
| 77 |
self._rpc_state = rpc_state |
| 78 |
|
| 79 |
def send_initial_metadata(self, initial_metadata): |
| 80 |
self._rpc_state.send_initial_metadata(initial_metadata) |
| 81 |
|
| 82 |
def take_request(self): |
| 83 |
return self._rpc_state.take_request() |
| 84 |
|
| 85 |
def send_response(self, response): |
| 86 |
self._rpc_state.send_response(response) |
| 87 |
|
| 88 |
def requests_closed(self): |
| 89 |
return self._rpc_state.requests_closed() |
| 90 |
|
| 91 |
def cancelled(self): |
| 92 |
self._rpc_state.cancelled() |
| 93 |
|
| 94 |
def terminate(self, trailing_metadata, code, details): |
| 95 |
self._rpc_state.terminate(trailing_metadata, code, details) |
| 96 |
|
| 97 |
|
| 98 |
def unary_unary(channel_state, method_descriptor): |
| 99 |
rpc_state = channel_state.take_rpc_state(method_descriptor) |
| 100 |
invocation_metadata, request = ( |
| 101 |
rpc_state.take_invocation_metadata_and_request()) |
| 102 |
return invocation_metadata, request, _UnaryUnary(rpc_state) |
| 103 |
|
| 104 |
|
| 105 |
def unary_stream(channel_state, method_descriptor): |
| 106 |
rpc_state = channel_state.take_rpc_state(method_descriptor) |
| 107 |
invocation_metadata, request = ( |
| 108 |
rpc_state.take_invocation_metadata_and_request()) |
| 109 |
return invocation_metadata, request, _UnaryStream(rpc_state) |
| 110 |
|
| 111 |
|
| 112 |
def stream_unary(channel_state, method_descriptor): |
| 113 |
rpc_state = channel_state.take_rpc_state(method_descriptor) |
| 114 |
return rpc_state.take_invocation_metadata(), _StreamUnary(rpc_state) |
| 115 |
|
| 116 |
|
| 117 |
def stream_stream(channel_state, method_descriptor): |
| 118 |
rpc_state = channel_state.take_rpc_state(method_descriptor) |
| 119 |
return rpc_state.take_invocation_metadata(), _StreamStream(rpc_state) |