Merge pull request #8742 from kpayson64/service_names_hint

Allow handlers to hint at the services they export
pull/9019/head
kpayson64 8 years ago committed by GitHub
commit 5431135ce5
  1. 20
      src/python/grpcio/grpc/__init__.py
  2. 6
      src/python/grpcio/grpc/_utilities.py

@ -849,6 +849,26 @@ class GenericRpcHandler(six.with_metaclass(abc.ABCMeta)):
raise NotImplementedError()
class ServiceRpcHandler(six.with_metaclass(abc.ABCMeta, GenericRpcHandler)):
"""An implementation of RPC methods belonging to a service.
A service handles RPC methods with structured names of the form
'/Service.Name/Service.MethodX', where 'Service.Name' is the value
returned by service_name(), and 'Service.MethodX' is the service method
name. A service can have multiple service methods names, but only a single
service name.
"""
@abc.abstractmethod
def service_name(self):
"""Returns this services name.
Returns:
The service name.
"""
raise NotImplementedError()
############################# Server Interface ###############################

@ -53,13 +53,17 @@ class RpcMethodHandler(
pass
class DictionaryGenericHandler(grpc.GenericRpcHandler):
class DictionaryGenericHandler(grpc.ServiceRpcHandler):
def __init__(self, service, method_handlers):
self._name = service
self._method_handlers = {
_common.fully_qualified_method(service, method): method_handler
for method, method_handler in six.iteritems(method_handlers)}
def service_name(self):
return self._name
def service(self, handler_call_details):
return self._method_handlers.get(handler_call_details.method)

Loading…
Cancel
Save