aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/python/grpcio/grpc/beta
diff options
context:
space:
mode:
authorGravatar Nathaniel Manista <nathaniel@google.com>2015-09-02 20:04:23 +0000
committerGravatar Nathaniel Manista <nathaniel@google.com>2015-09-02 21:10:48 +0000
commit1d750d6ca2d878385e4a13a933663bbfe87e5358 (patch)
tree2b37f13be2dc8c264cd3bdda58d8eb9ff8b97efc /src/python/grpcio/grpc/beta
parent69210e598be64274def39c7da70129cffffe8c2a (diff)
UNIMPLEMENTED status for methods not found
Diffstat (limited to 'src/python/grpcio/grpc/beta')
-rw-r--r--src/python/grpcio/grpc/beta/_server.py24
-rw-r--r--src/python/grpcio/grpc/beta/interfaces.py54
2 files changed, 76 insertions, 2 deletions
diff --git a/src/python/grpcio/grpc/beta/_server.py b/src/python/grpcio/grpc/beta/_server.py
index 4e46ffd17f..ebf91d80ab 100644
--- a/src/python/grpcio/grpc/beta/_server.py
+++ b/src/python/grpcio/grpc/beta/_server.py
@@ -32,9 +32,11 @@
import threading
from grpc._links import service
+from grpc.beta import interfaces
from grpc.framework.core import implementations as _core_implementations
from grpc.framework.crust import implementations as _crust_implementations
from grpc.framework.foundation import logging_pool
+from grpc.framework.interfaces.base import base
from grpc.framework.interfaces.links import utilities
_DEFAULT_POOL_SIZE = 8
@@ -42,6 +44,23 @@ _DEFAULT_TIMEOUT = 300
_MAXIMUM_TIMEOUT = 24 * 60 * 60
+class _GRPCServicer(base.Servicer):
+
+ def __init__(self, delegate):
+ self._delegate = delegate
+
+ def service(self, group, method, context, output_operator):
+ try:
+ return self._delegate.service(group, method, context, output_operator)
+ except base.NoSuchMethodError as e:
+ if e.code is None and e.details is None:
+ raise base.NoSuchMethodError(
+ interfaces.StatusCode.UNIMPLEMENTED,
+ b'Method "%s" of service "%s" not implemented!' % (method, group))
+ else:
+ raise
+
+
def _disassemble(grpc_link, end_link, pool, event, grace):
grpc_link.begin_stop()
end_link.stop(grace).wait()
@@ -99,8 +118,9 @@ def server(
service_thread_pool = thread_pool
assembly_thread_pool = None
- servicer = _crust_implementations.servicer(
- implementations, multi_implementation, service_thread_pool)
+ servicer = _GRPCServicer(
+ _crust_implementations.servicer(
+ implementations, multi_implementation, service_thread_pool))
grpc_link = service.service_link(request_deserializers, response_serializers)
diff --git a/src/python/grpcio/grpc/beta/interfaces.py b/src/python/grpcio/grpc/beta/interfaces.py
new file mode 100644
index 0000000000..25e6a9c66b
--- /dev/null
+++ b/src/python/grpcio/grpc/beta/interfaces.py
@@ -0,0 +1,54 @@
+# Copyright 2015, Google Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following disclaimer
+# in the documentation and/or other materials provided with the
+# distribution.
+# * Neither the name of Google Inc. nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+"""Constants and interfaces of the Beta API of gRPC Python."""
+
+import enum
+
+
+@enum.unique
+class StatusCode(enum.Enum):
+ """Mirrors grpc_status_code in the C core."""
+ OK = 0
+ CANCELLED = 1
+ UNKNOWN = 2
+ INVALID_ARGUMENT = 3
+ DEADLINE_EXCEEDED = 4
+ NOT_FOUND = 5
+ ALREADY_EXISTS = 6
+ PERMISSION_DENIED = 7
+ RESOURCE_EXHAUSTED = 8
+ FAILED_PRECONDITION = 9
+ ABORTED = 10
+ OUT_OF_RANGE = 11
+ UNIMPLEMENTED = 12
+ INTERNAL = 13
+ UNAVAILABLE = 14
+ DATA_LOSS = 15
+ UNAUTHENTICATED = 16