framework/interfaces/face/utilities.py
Go to the documentation of this file.
1 # Copyright 2015 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 """Utilities for RPC Framework's Face interface."""
15 
16 import collections
17 
18 # stream is referenced from specification in this module.
19 from grpc.framework.common import cardinality
20 from grpc.framework.common import style
21 from grpc.framework.foundation import stream # pylint: disable=unused-import
22 from grpc.framework.interfaces.face import face
23 
24 
26  collections.namedtuple('_MethodImplementation', [
27  'cardinality',
28  'style',
29  'unary_unary_inline',
30  'unary_stream_inline',
31  'stream_unary_inline',
32  'stream_stream_inline',
33  'unary_unary_event',
34  'unary_stream_event',
35  'stream_unary_event',
36  'stream_stream_event',
37  ])):
38  pass
39 
40 
41 def unary_unary_inline(behavior):
42  """Creates an face.MethodImplementation for the given behavior.
43 
44  Args:
45  behavior: The implementation of a unary-unary RPC method as a callable value
46  that takes a request value and an face.ServicerContext object and
47  returns a response value.
48 
49  Returns:
50  An face.MethodImplementation derived from the given behavior.
51  """
52  return _MethodImplementation(cardinality.Cardinality.UNARY_UNARY,
53  style.Service.INLINE, behavior, None, None,
54  None, None, None, None, None)
55 
56 
57 def unary_stream_inline(behavior):
58  """Creates an face.MethodImplementation for the given behavior.
59 
60  Args:
61  behavior: The implementation of a unary-stream RPC method as a callable
62  value that takes a request value and an face.ServicerContext object and
63  returns an iterator of response values.
64 
65  Returns:
66  An face.MethodImplementation derived from the given behavior.
67  """
68  return _MethodImplementation(cardinality.Cardinality.UNARY_STREAM,
69  style.Service.INLINE, None, behavior, None,
70  None, None, None, None, None)
71 
72 
73 def stream_unary_inline(behavior):
74  """Creates an face.MethodImplementation for the given behavior.
75 
76  Args:
77  behavior: The implementation of a stream-unary RPC method as a callable
78  value that takes an iterator of request values and an
79  face.ServicerContext object and returns a response value.
80 
81  Returns:
82  An face.MethodImplementation derived from the given behavior.
83  """
84  return _MethodImplementation(cardinality.Cardinality.STREAM_UNARY,
85  style.Service.INLINE, None, None, behavior,
86  None, None, None, None, None)
87 
88 
89 def stream_stream_inline(behavior):
90  """Creates an face.MethodImplementation for the given behavior.
91 
92  Args:
93  behavior: The implementation of a stream-stream RPC method as a callable
94  value that takes an iterator of request values and an
95  face.ServicerContext object and returns an iterator of response values.
96 
97  Returns:
98  An face.MethodImplementation derived from the given behavior.
99  """
100  return _MethodImplementation(cardinality.Cardinality.STREAM_STREAM,
101  style.Service.INLINE, None, None, None,
102  behavior, None, None, None, None)
103 
104 
105 def unary_unary_event(behavior):
106  """Creates an face.MethodImplementation for the given behavior.
107 
108  Args:
109  behavior: The implementation of a unary-unary RPC method as a callable
110  value that takes a request value, a response callback to which to pass
111  the response value of the RPC, and an face.ServicerContext.
112 
113  Returns:
114  An face.MethodImplementation derived from the given behavior.
115  """
116  return _MethodImplementation(cardinality.Cardinality.UNARY_UNARY,
117  style.Service.EVENT, None, None, None, None,
118  behavior, None, None, None)
119 
120 
121 def unary_stream_event(behavior):
122  """Creates an face.MethodImplementation for the given behavior.
123 
124  Args:
125  behavior: The implementation of a unary-stream RPC method as a callable
126  value that takes a request value, a stream.Consumer to which to pass the
127  the response values of the RPC, and an face.ServicerContext.
128 
129  Returns:
130  An face.MethodImplementation derived from the given behavior.
131  """
132  return _MethodImplementation(cardinality.Cardinality.UNARY_STREAM,
133  style.Service.EVENT, None, None, None, None,
134  None, behavior, None, None)
135 
136 
137 def stream_unary_event(behavior):
138  """Creates an face.MethodImplementation for the given behavior.
139 
140  Args:
141  behavior: The implementation of a stream-unary RPC method as a callable
142  value that takes a response callback to which to pass the response value
143  of the RPC and an face.ServicerContext and returns a stream.Consumer to
144  which the request values of the RPC should be passed.
145 
146  Returns:
147  An face.MethodImplementation derived from the given behavior.
148  """
149  return _MethodImplementation(cardinality.Cardinality.STREAM_UNARY,
150  style.Service.EVENT, None, None, None, None,
151  None, None, behavior, None)
152 
153 
154 def stream_stream_event(behavior):
155  """Creates an face.MethodImplementation for the given behavior.
156 
157  Args:
158  behavior: The implementation of a stream-stream RPC method as a callable
159  value that takes a stream.Consumer to which to pass the response values
160  of the RPC and an face.ServicerContext and returns a stream.Consumer to
161  which the request values of the RPC should be passed.
162 
163  Returns:
164  An face.MethodImplementation derived from the given behavior.
165  """
166  return _MethodImplementation(cardinality.Cardinality.STREAM_STREAM,
167  style.Service.EVENT, None, None, None, None,
168  None, None, None, behavior)
grpc.framework.interfaces.face.utilities.unary_unary_event
def unary_unary_event(behavior)
Definition: framework/interfaces/face/utilities.py:105
grpc.framework.interfaces.face.utilities.unary_stream_inline
def unary_stream_inline(behavior)
Definition: framework/interfaces/face/utilities.py:57
grpc.framework.foundation
Definition: src/python/grpcio/grpc/framework/foundation/__init__.py:1
grpc.framework.interfaces.face
Definition: src/python/grpcio/grpc/framework/interfaces/face/__init__.py:1
grpc.framework.interfaces.face.face.MethodImplementation
Definition: face.py:613
grpc.framework.interfaces.face.utilities.stream_stream_event
def stream_stream_event(behavior)
Definition: framework/interfaces/face/utilities.py:154
grpc.framework.interfaces.face.utilities.stream_unary_inline
def stream_unary_inline(behavior)
Definition: framework/interfaces/face/utilities.py:73
grpc.framework.interfaces.face.utilities.stream_unary_event
def stream_unary_event(behavior)
Definition: framework/interfaces/face/utilities.py:137
grpc.framework.common
Definition: src/python/grpcio/grpc/framework/common/__init__.py:1
grpc.framework.interfaces.face.utilities.stream_stream_inline
def stream_stream_inline(behavior)
Definition: framework/interfaces/face/utilities.py:89
grpc.framework.interfaces.face.utilities._MethodImplementation
Definition: framework/interfaces/face/utilities.py:37
grpc.framework.interfaces.face.utilities.unary_unary_inline
def unary_unary_inline(behavior)
Definition: framework/interfaces/face/utilities.py:41
grpc.framework.interfaces.face.utilities.unary_stream_event
def unary_stream_event(behavior)
Definition: framework/interfaces/face/utilities.py:121


grpc
Author(s):
autogenerated on Fri May 16 2025 03:00:49