File: __init__.py

package info (click to toggle)
golang-github-grpc-ecosystem-grpc-opentracing 0.0~git20180507.8e809c8-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bookworm-proposed-updates, bullseye
  • size: 576 kB
  • sloc: python: 2,021; java: 1,077; makefile: 2
file content (185 lines) | stat: -rw-r--r-- 6,352 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
import abc

import six


class UnaryClientInfo(six.with_metaclass(abc.ABCMeta)):
    """Consists of various information about a unary RPC on the invocation-side.

  Attributes:
    full_method: A string of the full RPC method, i.e., /package.service/method.
    timeout: The length of time in seconds to wait for the computation to
      terminate or be cancelled, or None if this method should block until
      the computation is terminated or is cancelled no matter how long that
      takes.
  """


class StreamClientInfo(six.with_metaclass(abc.ABCMeta)):
    """Consists of various information about a stream RPC on the invocation-side.

  Attributes:
    full_method: A string of the full RPC method, i.e., /package.service/method.
    is_client_stream: Indicates whether the RPC is client-streaming.
    is_server_stream: Indicates whether the RPC is server-streaming.
    timeout: The length of time in seconds to wait for the computation to
      terminate or be cancelled, or None if this method should block until
      the computation is terminated or is cancelled no matter how long that
      takes.
  """


class UnaryClientInterceptor(six.with_metaclass(abc.ABCMeta)):
    """Affords intercepting unary-unary RPCs on the invocation-side."""

    @abc.abstractmethod
    def intercept_unary(self, request, metadata, client_info, invoker):
        """Intercepts unary-unary RPCs on the invocation-side.

    Args:
      request: The request value for the RPC.
      metadata: Optional :term:`metadata` to be transmitted to the
        service-side of the RPC.
      client_info: A UnaryClientInfo containing various information about
        the RPC.
      invoker: The handler to complete the RPC on the client. It is the
        interceptor's responsibility to call it.

    Returns:
      The result from calling invoker(request, metadata).
    """
        raise NotImplementedError()


class StreamClientInterceptor(six.with_metaclass(abc.ABCMeta)):
    """Affords intercepting stream RPCs on the invocation-side."""

    @abc.abstractmethod
    def intercept_stream(self, request_or_iterator, metadata, client_info,
                         invoker):
        """Intercepts stream RPCs on the invocation-side.

    Args:
      request_or_iterator: The request value for the RPC if
        `client_info.is_client_stream` is `false`; otherwise, an iterator of
        request values.
      metadata: Optional :term:`metadata` to be transmitted to the service-side
        of the RPC.
      client_info: A StreamClientInfo containing various information about
        the RPC.
      invoker:  The handler to complete the RPC on the client. It is the
        interceptor's responsibility to call it.

      Returns:
        The result from calling invoker(metadata).
    """
        raise NotImplementedError()


def intercept_channel(channel, *interceptors):
    """Creates an intercepted channel.

  Args:
    channel: A Channel.
    interceptors: Zero or more UnaryClientInterceptors or
      StreamClientInterceptors

  Returns:
    A Channel.

  Raises:
    TypeError: If an interceptor derives from neither UnaryClientInterceptor
      nor StreamClientInterceptor.
  """
    from grpc_opentracing.grpcext import _interceptor
    return _interceptor.intercept_channel(channel, *interceptors)


class UnaryServerInfo(six.with_metaclass(abc.ABCMeta)):
    """Consists of various information about a unary RPC on the service-side.

  Attributes:
    full_method: A string of the full RPC method, i.e., /package.service/method.
  """


class StreamServerInfo(six.with_metaclass(abc.ABCMeta)):
    """Consists of various information about a stream RPC on the service-side.

  Attributes:
    full_method: A string of the full RPC method, i.e., /package.service/method.
    is_client_stream: Indicates whether the RPC is client-streaming.
    is_server_stream: Indicates whether the RPC is server-streaming.
  """


class UnaryServerInterceptor(six.with_metaclass(abc.ABCMeta)):
    """Affords intercepting unary-unary RPCs on the service-side."""

    @abc.abstractmethod
    def intercept_unary(self, request, servicer_context, server_info, handler):
        """Intercepts unary-unary RPCs on the service-side.

    Args:
      request: The request value for the RPC.
      servicer_context: A ServicerContext.
      server_info: A UnaryServerInfo containing various information about
        the RPC.
      handler:  The handler to complete the RPC on the server. It is the
        interceptor's responsibility to call it.

    Returns:
      The result from calling handler(request, servicer_context).
    """
        raise NotImplementedError()


class StreamServerInterceptor(six.with_metaclass(abc.ABCMeta)):
    """Affords intercepting stream RPCs on the service-side."""

    @abc.abstractmethod
    def intercept_stream(self, request_or_iterator, servicer_context,
                         server_info, handler):
        """Intercepts stream RPCs on the service-side.

    Args:
      request_or_iterator: The request value for the RPC if
        `server_info.is_client_stream` is `False`; otherwise, an iterator of
        request values.
      servicer_context: A ServicerContext.
      server_info: A StreamServerInfo containing various information about
        the RPC.
      handler:  The handler to complete the RPC on the server. It is the
        interceptor's responsibility to call it.

      Returns:
        The result from calling handler(servicer_context).
    """
        raise NotImplementedError()


def intercept_server(server, *interceptors):
    """Creates an intercepted server.

  Args:
    server: A Server.
    interceptors: Zero or more UnaryServerInterceptors or
      StreamServerInterceptors

  Returns:
    A Server.

  Raises:
    TypeError: If an interceptor derives from neither UnaryServerInterceptor
      nor StreamServerInterceptor.
  """
    from grpc_opentracing.grpcext import _interceptor
    return _interceptor.intercept_server(server, *interceptors)


###################################  __all__  #################################

__all__ = ('UnaryClientInterceptor', 'StreamClientInfo',
           'StreamClientInterceptor', 'UnaryServerInfo', 'StreamServerInfo',
           'UnaryServerInterceptor', 'StreamServerInterceptor',
           'intercept_channel', 'intercept_server',)