aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/python/grpcio/grpc/beta
diff options
context:
space:
mode:
authorGravatar Ken Payson <kpayson@google.com>2016-06-08 13:06:44 -0700
committerGravatar Ken Payson <kpayson@google.com>2016-06-10 11:48:24 -0700
commit1efb6017ec1edb26706895dfe71f4d72ea387cf4 (patch)
treeeaede04a7db3e55c9c0954185192dc84231c2637 /src/python/grpcio/grpc/beta
parent698d3e91ff42db3fe640cc369e8edf85abc5343d (diff)
Initial Python3 support
Notable Changes: -Convert all str types to byte types at cython layer (ascii encoding) -Use six for packages that have different names in Python2/Python3 -By default, unit tests are compiled/run in Python2.7 and Python3.4 -Ensure MACOSX_BUILD_TARGET is at least 10.7
Diffstat (limited to 'src/python/grpcio/grpc/beta')
-rw-r--r--src/python/grpcio/grpc/beta/_client_adaptations.py17
-rw-r--r--src/python/grpcio/grpc/beta/_server_adaptations.py46
2 files changed, 34 insertions, 29 deletions
diff --git a/src/python/grpcio/grpc/beta/_client_adaptations.py b/src/python/grpcio/grpc/beta/_client_adaptations.py
index 621fcf2174..024808c540 100644
--- a/src/python/grpcio/grpc/beta/_client_adaptations.py
+++ b/src/python/grpcio/grpc/beta/_client_adaptations.py
@@ -30,6 +30,7 @@
"""Translates gRPC's client-side API into gRPC's client-side Beta API."""
import grpc
+from grpc import _common
from grpc._cython import cygrpc
from grpc.beta import interfaces
from grpc.framework.common import cardinality
@@ -48,10 +49,6 @@ _STATUS_CODE_TO_ABORTION_KIND_AND_ABORTION_ERROR_CLASS = {
}
-def _fully_qualified_method(group, method):
- return b'/{}/{}'.format(group, method)
-
-
def _effective_metadata(metadata, metadata_transformer):
non_none_metadata = () if metadata is None else metadata
if metadata_transformer is None:
@@ -184,7 +181,7 @@ def _blocking_unary_unary(
metadata_transformer, request, request_serializer, response_deserializer):
try:
multi_callable = channel.unary_unary(
- _fully_qualified_method(group, method),
+ _common.fully_qualified_method(group, method),
request_serializer=request_serializer,
response_deserializer=response_deserializer)
effective_metadata = _effective_metadata(metadata, metadata_transformer)
@@ -205,7 +202,7 @@ def _future_unary_unary(
channel, group, method, timeout, protocol_options, metadata,
metadata_transformer, request, request_serializer, response_deserializer):
multi_callable = channel.unary_unary(
- _fully_qualified_method(group, method),
+ _common.fully_qualified_method(group, method),
request_serializer=request_serializer,
response_deserializer=response_deserializer)
effective_metadata = _effective_metadata(metadata, metadata_transformer)
@@ -219,7 +216,7 @@ def _unary_stream(
channel, group, method, timeout, protocol_options, metadata,
metadata_transformer, request, request_serializer, response_deserializer):
multi_callable = channel.unary_stream(
- _fully_qualified_method(group, method),
+ _common.fully_qualified_method(group, method),
request_serializer=request_serializer,
response_deserializer=response_deserializer)
effective_metadata = _effective_metadata(metadata, metadata_transformer)
@@ -235,7 +232,7 @@ def _blocking_stream_unary(
response_deserializer):
try:
multi_callable = channel.stream_unary(
- _fully_qualified_method(group, method),
+ _common.fully_qualified_method(group, method),
request_serializer=request_serializer,
response_deserializer=response_deserializer)
effective_metadata = _effective_metadata(metadata, metadata_transformer)
@@ -257,7 +254,7 @@ def _future_stream_unary(
metadata_transformer, request_iterator, request_serializer,
response_deserializer):
multi_callable = channel.stream_unary(
- _fully_qualified_method(group, method),
+ _common.fully_qualified_method(group, method),
request_serializer=request_serializer,
response_deserializer=response_deserializer)
effective_metadata = _effective_metadata(metadata, metadata_transformer)
@@ -272,7 +269,7 @@ def _stream_stream(
metadata_transformer, request_iterator, request_serializer,
response_deserializer):
multi_callable = channel.stream_stream(
- _fully_qualified_method(group, method),
+ _common.fully_qualified_method(group, method),
request_serializer=request_serializer,
response_deserializer=response_deserializer)
effective_metadata = _effective_metadata(metadata, metadata_transformer)
diff --git a/src/python/grpcio/grpc/beta/_server_adaptations.py b/src/python/grpcio/grpc/beta/_server_adaptations.py
index 52eadf2315..79e6ca87eb 100644
--- a/src/python/grpcio/grpc/beta/_server_adaptations.py
+++ b/src/python/grpcio/grpc/beta/_server_adaptations.py
@@ -33,6 +33,7 @@ import collections
import threading
import grpc
+from grpc import _common
from grpc.beta import interfaces
from grpc.framework.common import cardinality
from grpc.framework.common import style
@@ -287,36 +288,43 @@ def _simple_method_handler(
None, _adapt_stream_stream_event(implementation.stream_stream_event))
+def _flatten_method_pair_map(method_pair_map):
+ method_pair_map = method_pair_map or {}
+ flat_map = {}
+ for method_pair in method_pair_map:
+ method = _common.fully_qualified_method(method_pair[0], method_pair[1])
+ flat_map[method] = method_pair_map[method_pair]
+ return flat_map
+
+
class _GenericRpcHandler(grpc.GenericRpcHandler):
def __init__(
self, method_implementations, multi_method_implementation,
request_deserializers, response_serializers):
- self._method_implementations = method_implementations
+ self._method_implementations = _flatten_method_pair_map(
+ method_implementations)
+ self._request_deserializers = _flatten_method_pair_map(
+ request_deserializers)
+ self._response_serializers = _flatten_method_pair_map(
+ response_serializers)
self._multi_method_implementation = multi_method_implementation
- self._request_deserializers = request_deserializers or {}
- self._response_serializers = response_serializers or {}
def service(self, handler_call_details):
- try:
- group_name, method_name = handler_call_details.method.split(b'/')[1:3]
- except ValueError:
+ method_implementation = self._method_implementations.get(
+ handler_call_details.method)
+ if method_implementation is not None:
+ return _simple_method_handler(
+ method_implementation,
+ self._request_deserializers.get(handler_call_details.method),
+ self._response_serializers.get(handler_call_details.method))
+ elif self._multi_method_implementation is None:
return None
else:
- method_implementation = self._method_implementations.get(
- (group_name, method_name,))
- if method_implementation is not None:
- return _simple_method_handler(
- method_implementation,
- self._request_deserializers.get((group_name, method_name,)),
- self._response_serializers.get((group_name, method_name,)))
- elif self._multi_method_implementation is None:
+ try:
+ return None #TODO(nathaniel): call the multimethod.
+ except face.NoSuchMethodError:
return None
- else:
- try:
- return None #TODO(nathaniel): call the multimethod.
- except face.NoSuchMethodError:
- return None
class _Server(interfaces.Server):