aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/python/grpcio/grpc/_channel.py
diff options
context:
space:
mode:
authorGravatar Ken Payson <kpayson@google.com>2016-06-27 14:12:08 -0700
committerGravatar Ken Payson <kpayson@google.com>2016-06-29 17:49:19 -0700
commit6a654dd400cc204a1ceb059785821c8ea15acde9 (patch)
tree7cbdef066db3e8c442b00c61b62d81c2b11b0ac9 /src/python/grpcio/grpc/_channel.py
parentb4028f6675a3c3d24fdbb3bed4e4a3939ccbb434 (diff)
Changed default string type to be str
This impacts the following APIs: Metadata: Key is always a str, Value is bytes for binary metadata, str otherwise Call Details: str type gRPC method: str type hostname/target: str type
Diffstat (limited to 'src/python/grpcio/grpc/_channel.py')
-rw-r--r--src/python/grpcio/grpc/_channel.py46
1 files changed, 26 insertions, 20 deletions
diff --git a/src/python/grpcio/grpc/_channel.py b/src/python/grpcio/grpc/_channel.py
index cf6175d031..a89b501303 100644
--- a/src/python/grpcio/grpc/_channel.py
+++ b/src/python/grpcio/grpc/_channel.py
@@ -364,13 +364,13 @@ class _Rendezvous(grpc.RpcError, grpc.Future, grpc.Call):
with self._state.condition:
while self._state.initial_metadata is None:
self._state.condition.wait()
- return self._state.initial_metadata
+ return _common.application_metadata(self._state.initial_metadata)
def trailing_metadata(self):
with self._state.condition:
while self._state.trailing_metadata is None:
self._state.condition.wait()
- return self._state.trailing_metadata
+ return _common.application_metadata(self._state.trailing_metadata)
def code(self):
with self._state.condition:
@@ -382,7 +382,7 @@ class _Rendezvous(grpc.RpcError, grpc.Future, grpc.Call):
with self._state.condition:
while self._state.details is None:
self._state.condition.wait()
- return self._state.details
+ return _common.decode(self._state.details)
def _repr(self):
with self._state.condition:
@@ -390,7 +390,7 @@ class _Rendezvous(grpc.RpcError, grpc.Future, grpc.Call):
return '<_Rendezvous object of in-flight RPC>'
else:
return '<_Rendezvous of RPC that terminated with ({}, {})>'.format(
- self._state.code, self._state.details)
+ self._state.code, _common.decode(self._state.details))
def __repr__(self):
return self._repr()
@@ -451,7 +451,7 @@ class _UnaryUnaryMultiCallable(grpc.UnaryUnaryMultiCallable):
state = _RPCState(_UNARY_UNARY_INITIAL_DUE, None, None, None, None)
operations = (
cygrpc.operation_send_initial_metadata(
- _common.metadata(metadata), _EMPTY_FLAGS),
+ _common.cygrpc_metadata(metadata), _EMPTY_FLAGS),
cygrpc.operation_send_message(serialized_request, _EMPTY_FLAGS),
cygrpc.operation_send_close_from_client(_EMPTY_FLAGS),
cygrpc.operation_receive_initial_metadata(_EMPTY_FLAGS),
@@ -529,7 +529,7 @@ class _UnaryStreamMultiCallable(grpc.UnaryStreamMultiCallable):
event_handler)
operations = (
cygrpc.operation_send_initial_metadata(
- _common.metadata(metadata), _EMPTY_FLAGS),
+ _common.cygrpc_metadata(metadata), _EMPTY_FLAGS),
cygrpc.operation_send_message(serialized_request, _EMPTY_FLAGS),
cygrpc.operation_send_close_from_client(_EMPTY_FLAGS),
cygrpc.operation_receive_status_on_client(_EMPTY_FLAGS),
@@ -564,7 +564,7 @@ class _StreamUnaryMultiCallable(grpc.StreamUnaryMultiCallable):
None)
operations = (
cygrpc.operation_send_initial_metadata(
- _common.metadata(metadata), _EMPTY_FLAGS),
+ _common.cygrpc_metadata(metadata), _EMPTY_FLAGS),
cygrpc.operation_receive_message(_EMPTY_FLAGS),
cygrpc.operation_receive_status_on_client(_EMPTY_FLAGS),
)
@@ -608,7 +608,7 @@ class _StreamUnaryMultiCallable(grpc.StreamUnaryMultiCallable):
event_handler)
operations = (
cygrpc.operation_send_initial_metadata(
- _common.metadata(metadata), _EMPTY_FLAGS),
+ _common.cygrpc_metadata(metadata), _EMPTY_FLAGS),
cygrpc.operation_receive_message(_EMPTY_FLAGS),
cygrpc.operation_receive_status_on_client(_EMPTY_FLAGS),
)
@@ -645,7 +645,7 @@ class _StreamStreamMultiCallable(grpc.StreamStreamMultiCallable):
event_handler)
operations = (
cygrpc.operation_send_initial_metadata(
- _common.metadata(metadata), _EMPTY_FLAGS),
+ _common.cygrpc_metadata(metadata), _EMPTY_FLAGS),
cygrpc.operation_receive_status_on_client(_EMPTY_FLAGS),
)
call.start_batch(cygrpc.Operations(operations), event_handler)
@@ -846,8 +846,13 @@ def _options(options):
else:
pairs = list(options) + [
(cygrpc.ChannelArgKey.primary_user_agent_string, _USER_AGENT)]
- return cygrpc.ChannelArgs(
- cygrpc.ChannelArg(arg_name, arg_value) for arg_name, arg_value in pairs)
+ encoded_pairs = [
+ (_common.encode(arg_name), arg_value) if isinstance(arg_value, int)
+ else (_common.encode(arg_name), _common.encode(arg_value))
+ for arg_name, arg_value in pairs]
+ return cygrpc.ChannelArgs([
+ cygrpc.ChannelArg(arg_name, arg_value)
+ for arg_name, arg_value in encoded_pairs])
class Channel(grpc.Channel):
@@ -860,7 +865,8 @@ class Channel(grpc.Channel):
options: Configuration options for the channel.
credentials: A cygrpc.ChannelCredentials or None.
"""
- self._channel = cygrpc.Channel(target, _options(options), credentials)
+ self._channel = cygrpc.Channel(
+ _common.encode(target), _options(options), credentials)
self._call_state = _ChannelCallState(self._channel)
self._connectivity_state = _ChannelConnectivityState(self._channel)
@@ -873,26 +879,26 @@ class Channel(grpc.Channel):
def unary_unary(
self, method, request_serializer=None, response_deserializer=None):
return _UnaryUnaryMultiCallable(
- self._channel, _create_channel_managed_call(self._call_state), method,
- request_serializer, response_deserializer)
+ self._channel, _create_channel_managed_call(self._call_state),
+ _common.encode(method), request_serializer, response_deserializer)
def unary_stream(
self, method, request_serializer=None, response_deserializer=None):
return _UnaryStreamMultiCallable(
- self._channel, _create_channel_managed_call(self._call_state), method,
- request_serializer, response_deserializer)
+ self._channel, _create_channel_managed_call(self._call_state),
+ _common.encode(method), request_serializer, response_deserializer)
def stream_unary(
self, method, request_serializer=None, response_deserializer=None):
return _StreamUnaryMultiCallable(
- self._channel, _create_channel_managed_call(self._call_state), method,
- request_serializer, response_deserializer)
+ self._channel, _create_channel_managed_call(self._call_state),
+ _common.encode(method), request_serializer, response_deserializer)
def stream_stream(
self, method, request_serializer=None, response_deserializer=None):
return _StreamStreamMultiCallable(
- self._channel, _create_channel_managed_call(self._call_state), method,
- request_serializer, response_deserializer)
+ self._channel, _create_channel_managed_call(self._call_state),
+ _common.encode(method), request_serializer, response_deserializer)
def __del__(self):
_moot(self._connectivity_state)