diff options
author | dvshkurko <dvshkurko@yandex-team.ru> | 2022-02-10 16:45:51 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:51 +0300 |
commit | 321ee9bce31ec6e238be26dbcbe539cffa2c3309 (patch) | |
tree | 14407a2757cbf29eb97e266b7f07e851f971000c /contrib/libs/grpc/src/python/grpcio | |
parent | 2f6ca198245aeffd5e2d82b65927c2465b68b4f5 (diff) | |
download | ydb-321ee9bce31ec6e238be26dbcbe539cffa2c3309.tar.gz |
Restoring authorship annotation for <dvshkurko@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'contrib/libs/grpc/src/python/grpcio')
53 files changed, 3052 insertions, 3052 deletions
diff --git a/contrib/libs/grpc/src/python/grpcio/README.rst b/contrib/libs/grpc/src/python/grpcio/README.rst index fe34ad5adf..9bfec34f6d 100644 --- a/contrib/libs/grpc/src/python/grpcio/README.rst +++ b/contrib/libs/grpc/src/python/grpcio/README.rst @@ -1,24 +1,24 @@ gRPC Python =========== -|compat_check_pypi| - +|compat_check_pypi| + Package for gRPC Python. -.. |compat_check_pypi| image:: https://python-compatibility-tools.appspot.com/one_badge_image?package=grpcio - :target: https://python-compatibility-tools.appspot.com/one_badge_target?package=grpcio - -Supported Python Versions -------------------------- -Python >= 3.5 - +.. |compat_check_pypi| image:: https://python-compatibility-tools.appspot.com/one_badge_image?package=grpcio + :target: https://python-compatibility-tools.appspot.com/one_badge_target?package=grpcio + +Supported Python Versions +------------------------- +Python >= 3.5 + Installation ------------ gRPC Python is available for Linux, macOS, and Windows. -Installing From PyPI -~~~~~~~~~~~~~~~~~~~~ +Installing From PyPI +~~~~~~~~~~~~~~~~~~~~ If you are installing locally... @@ -46,8 +46,8 @@ n.b. On Windows and on Mac OS X one *must* have a recent release of :code:`pip` to retrieve the proper wheel from PyPI. Be sure to upgrade to the latest version! -Installing From Source -~~~~~~~~~~~~~~~~~~~~~~ +Installing From Source +~~~~~~~~~~~~~~~~~~~~~~ Building from source requires that you have the Python headers (usually a package named :code:`python-dev`). diff --git a/contrib/libs/grpc/src/python/grpcio/commands.py b/contrib/libs/grpc/src/python/grpcio/commands.py index 8240beb295..dcb2ce5a53 100644 --- a/contrib/libs/grpc/src/python/grpcio/commands.py +++ b/contrib/libs/grpc/src/python/grpcio/commands.py @@ -212,43 +212,43 @@ class BuildExt(build_ext.build_ext): LINK_OPTIONS = {} def build_extensions(self): - - def compiler_ok_with_extra_std(): - """Test if default compiler is okay with specifying c++ version - when invoked in C mode. GCC is okay with this, while clang is not. - """ + + def compiler_ok_with_extra_std(): + """Test if default compiler is okay with specifying c++ version + when invoked in C mode. GCC is okay with this, while clang is not. + """ if platform.system() != 'Windows': return False - # TODO(lidiz) Remove the generated a.out for success tests. + # TODO(lidiz) Remove the generated a.out for success tests. cc_test = subprocess.Popen(['cc', '-x', 'c', '-std=c++11', '-'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - _, cc_err = cc_test.communicate(input=b'int main(){return 0;}') - return not 'invalid argument' in str(cc_err) - + _, cc_err = cc_test.communicate(input=b'int main(){return 0;}') + return not 'invalid argument' in str(cc_err) + # This special conditioning is here due to difference of compiler # behavior in gcc and clang. The clang doesn't take --stdc++11 # flags but gcc does. Since the setuptools of Python only support # all C or all C++ compilation, the mix of C and C++ will crash. - # *By default*, macOS and FreBSD use clang and Linux use gcc - # - # If we are not using a permissive compiler that's OK with being - # passed wrong std flags, swap out compile function by adding a filter - # for it. - if not compiler_ok_with_extra_std(): - old_compile = self.compiler._compile - - def new_compile(obj, src, ext, cc_args, extra_postargs, pp_opts): - if src[-2:] == '.c': - extra_postargs = [ - arg for arg in extra_postargs if not '-std=c++' in arg - ] - return old_compile(obj, src, ext, cc_args, extra_postargs, - pp_opts) - - self.compiler._compile = new_compile - + # *By default*, macOS and FreBSD use clang and Linux use gcc + # + # If we are not using a permissive compiler that's OK with being + # passed wrong std flags, swap out compile function by adding a filter + # for it. + if not compiler_ok_with_extra_std(): + old_compile = self.compiler._compile + + def new_compile(obj, src, ext, cc_args, extra_postargs, pp_opts): + if src[-2:] == '.c': + extra_postargs = [ + arg for arg in extra_postargs if not '-std=c++' in arg + ] + return old_compile(obj, src, ext, cc_args, extra_postargs, + pp_opts) + + self.compiler._compile = new_compile + compiler = self.compiler.compiler_type if compiler in BuildExt.C_OPTIONS: for extension in self.extensions: diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/__init__.py b/contrib/libs/grpc/src/python/grpcio/grpc/__init__.py index abe87458c4..62205cd0ad 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/__init__.py +++ b/contrib/libs/grpc/src/python/grpcio/grpc/__init__.py @@ -14,14 +14,14 @@ """gRPC's Python API.""" import abc -import contextlib +import contextlib import enum import logging import sys import six from grpc._cython import cygrpc as _cygrpc -from grpc import _compression +from grpc import _compression logging.getLogger(__name__).addHandler(logging.NullHandler()) @@ -192,9 +192,9 @@ class Future(six.with_metaclass(abc.ABCMeta)): If the computation has already completed, the callback will be called immediately. - Exceptions raised in the callback will be logged at ERROR level, but - will not terminate any threads of execution. - + Exceptions raised in the callback will be logged at ERROR level, but + will not terminate any threads of execution. + Args: fn: A callable taking this Future object as its single parameter. """ @@ -286,7 +286,7 @@ class Status(six.with_metaclass(abc.ABCMeta)): Attributes: code: A StatusCode object to be sent to the client. - details: A UTF-8-encodable string to be sent to the client upon + details: A UTF-8-encodable string to be sent to the client upon termination of the RPC. trailing_metadata: The trailing :term:`metadata` in the RPC. """ @@ -342,7 +342,7 @@ class RpcContext(six.with_metaclass(abc.ABCMeta)): callback: A no-parameter callable to be called on RPC termination. Returns: - True if the callback was added and will be called later; False if + True if the callback was added and will be called later; False if the callback was not added and will not be called (because the RPC already terminated or some other reason). """ @@ -416,8 +416,8 @@ class ClientCallDetails(six.with_metaclass(abc.ABCMeta)): credentials: An optional CallCredentials for the RPC. wait_for_ready: This is an EXPERIMENTAL argument. An optional flag to enable :term:`wait_for_ready` mechanism. - compression: An element of grpc.compression, e.g. - grpc.compression.Gzip. This is an EXPERIMENTAL option. + compression: An element of grpc.compression, e.g. + grpc.compression.Gzip. This is an EXPERIMENTAL option. """ @@ -586,9 +586,9 @@ class ChannelCredentials(object): class CallCredentials(object): """An encapsulation of the data required to assert an identity over a call. - A CallCredentials has to be used with secure Channel, otherwise the - metadata will not be transmitted to the server. - + A CallCredentials has to be used with secure Channel, otherwise the + metadata will not be transmitted to the server. + A CallCredentials may be composed with ChannelCredentials to always assert identity for every call over that Channel. @@ -677,8 +677,8 @@ class UnaryUnaryMultiCallable(six.with_metaclass(abc.ABCMeta)): timeout=None, metadata=None, credentials=None, - wait_for_ready=None, - compression=None): + wait_for_ready=None, + compression=None): """Synchronously invokes the underlying RPC. Args: @@ -687,12 +687,12 @@ class UnaryUnaryMultiCallable(six.with_metaclass(abc.ABCMeta)): for the RPC. metadata: Optional :term:`metadata` to be transmitted to the service-side of the RPC. - credentials: An optional CallCredentials for the RPC. Only valid for - secure Channel. + credentials: An optional CallCredentials for the RPC. Only valid for + secure Channel. wait_for_ready: This is an EXPERIMENTAL argument. An optional flag to enable :term:`wait_for_ready` mechanism. - compression: An element of grpc.compression, e.g. - grpc.compression.Gzip. This is an EXPERIMENTAL option. + compression: An element of grpc.compression, e.g. + grpc.compression.Gzip. This is an EXPERIMENTAL option. Returns: The response value for the RPC. @@ -710,8 +710,8 @@ class UnaryUnaryMultiCallable(six.with_metaclass(abc.ABCMeta)): timeout=None, metadata=None, credentials=None, - wait_for_ready=None, - compression=None): + wait_for_ready=None, + compression=None): """Synchronously invokes the underlying RPC. Args: @@ -720,12 +720,12 @@ class UnaryUnaryMultiCallable(six.with_metaclass(abc.ABCMeta)): the RPC. metadata: Optional :term:`metadata` to be transmitted to the service-side of the RPC. - credentials: An optional CallCredentials for the RPC. Only valid for - secure Channel. + credentials: An optional CallCredentials for the RPC. Only valid for + secure Channel. wait_for_ready: This is an EXPERIMENTAL argument. An optional flag to enable :term:`wait_for_ready` mechanism. - compression: An element of grpc.compression, e.g. - grpc.compression.Gzip. This is an EXPERIMENTAL option. + compression: An element of grpc.compression, e.g. + grpc.compression.Gzip. This is an EXPERIMENTAL option. Returns: The response value for the RPC and a Call value for the RPC. @@ -743,8 +743,8 @@ class UnaryUnaryMultiCallable(six.with_metaclass(abc.ABCMeta)): timeout=None, metadata=None, credentials=None, - wait_for_ready=None, - compression=None): + wait_for_ready=None, + compression=None): """Asynchronously invokes the underlying RPC. Args: @@ -753,12 +753,12 @@ class UnaryUnaryMultiCallable(six.with_metaclass(abc.ABCMeta)): the RPC. metadata: Optional :term:`metadata` to be transmitted to the service-side of the RPC. - credentials: An optional CallCredentials for the RPC. Only valid for - secure Channel. + credentials: An optional CallCredentials for the RPC. Only valid for + secure Channel. wait_for_ready: This is an EXPERIMENTAL argument. An optional flag to enable :term:`wait_for_ready` mechanism. - compression: An element of grpc.compression, e.g. - grpc.compression.Gzip. This is an EXPERIMENTAL option. + compression: An element of grpc.compression, e.g. + grpc.compression.Gzip. This is an EXPERIMENTAL option. Returns: An object that is both a Call for the RPC and a Future. @@ -779,8 +779,8 @@ class UnaryStreamMultiCallable(six.with_metaclass(abc.ABCMeta)): timeout=None, metadata=None, credentials=None, - wait_for_ready=None, - compression=None): + wait_for_ready=None, + compression=None): """Invokes the underlying RPC. Args: @@ -789,12 +789,12 @@ class UnaryStreamMultiCallable(six.with_metaclass(abc.ABCMeta)): the RPC. If None, the timeout is considered infinite. metadata: An optional :term:`metadata` to be transmitted to the service-side of the RPC. - credentials: An optional CallCredentials for the RPC. Only valid for - secure Channel. + credentials: An optional CallCredentials for the RPC. Only valid for + secure Channel. wait_for_ready: This is an EXPERIMENTAL argument. An optional flag to enable :term:`wait_for_ready` mechanism. - compression: An element of grpc.compression, e.g. - grpc.compression.Gzip. This is an EXPERIMENTAL option. + compression: An element of grpc.compression, e.g. + grpc.compression.Gzip. This is an EXPERIMENTAL option. Returns: An object that is both a Call for the RPC and an iterator of @@ -814,8 +814,8 @@ class StreamUnaryMultiCallable(six.with_metaclass(abc.ABCMeta)): timeout=None, metadata=None, credentials=None, - wait_for_ready=None, - compression=None): + wait_for_ready=None, + compression=None): """Synchronously invokes the underlying RPC. Args: @@ -825,12 +825,12 @@ class StreamUnaryMultiCallable(six.with_metaclass(abc.ABCMeta)): the RPC. If None, the timeout is considered infinite. metadata: Optional :term:`metadata` to be transmitted to the service-side of the RPC. - credentials: An optional CallCredentials for the RPC. Only valid for - secure Channel. + credentials: An optional CallCredentials for the RPC. Only valid for + secure Channel. wait_for_ready: This is an EXPERIMENTAL argument. An optional flag to enable :term:`wait_for_ready` mechanism. - compression: An element of grpc.compression, e.g. - grpc.compression.Gzip. This is an EXPERIMENTAL option. + compression: An element of grpc.compression, e.g. + grpc.compression.Gzip. This is an EXPERIMENTAL option. Returns: The response value for the RPC. @@ -848,8 +848,8 @@ class StreamUnaryMultiCallable(six.with_metaclass(abc.ABCMeta)): timeout=None, metadata=None, credentials=None, - wait_for_ready=None, - compression=None): + wait_for_ready=None, + compression=None): """Synchronously invokes the underlying RPC on the client. Args: @@ -859,12 +859,12 @@ class StreamUnaryMultiCallable(six.with_metaclass(abc.ABCMeta)): the RPC. If None, the timeout is considered infinite. metadata: Optional :term:`metadata` to be transmitted to the service-side of the RPC. - credentials: An optional CallCredentials for the RPC. Only valid for - secure Channel. + credentials: An optional CallCredentials for the RPC. Only valid for + secure Channel. wait_for_ready: This is an EXPERIMENTAL argument. An optional flag to enable :term:`wait_for_ready` mechanism. - compression: An element of grpc.compression, e.g. - grpc.compression.Gzip. This is an EXPERIMENTAL option. + compression: An element of grpc.compression, e.g. + grpc.compression.Gzip. This is an EXPERIMENTAL option. Returns: The response value for the RPC and a Call object for the RPC. @@ -882,8 +882,8 @@ class StreamUnaryMultiCallable(six.with_metaclass(abc.ABCMeta)): timeout=None, metadata=None, credentials=None, - wait_for_ready=None, - compression=None): + wait_for_ready=None, + compression=None): """Asynchronously invokes the underlying RPC on the client. Args: @@ -892,12 +892,12 @@ class StreamUnaryMultiCallable(six.with_metaclass(abc.ABCMeta)): the RPC. If None, the timeout is considered infinite. metadata: Optional :term:`metadata` to be transmitted to the service-side of the RPC. - credentials: An optional CallCredentials for the RPC. Only valid for - secure Channel. + credentials: An optional CallCredentials for the RPC. Only valid for + secure Channel. wait_for_ready: This is an EXPERIMENTAL argument. An optional flag to enable :term:`wait_for_ready` mechanism. - compression: An element of grpc.compression, e.g. - grpc.compression.Gzip. This is an EXPERIMENTAL option. + compression: An element of grpc.compression, e.g. + grpc.compression.Gzip. This is an EXPERIMENTAL option. Returns: An object that is both a Call for the RPC and a Future. @@ -918,8 +918,8 @@ class StreamStreamMultiCallable(six.with_metaclass(abc.ABCMeta)): timeout=None, metadata=None, credentials=None, - wait_for_ready=None, - compression=None): + wait_for_ready=None, + compression=None): """Invokes the underlying RPC on the client. Args: @@ -928,12 +928,12 @@ class StreamStreamMultiCallable(six.with_metaclass(abc.ABCMeta)): the RPC. If not specified, the timeout is considered infinite. metadata: Optional :term:`metadata` to be transmitted to the service-side of the RPC. - credentials: An optional CallCredentials for the RPC. Only valid for - secure Channel. + credentials: An optional CallCredentials for the RPC. Only valid for + secure Channel. wait_for_ready: This is an EXPERIMENTAL argument. An optional flag to enable :term:`wait_for_ready` mechanism. - compression: An element of grpc.compression, e.g. - grpc.compression.Gzip. This is an EXPERIMENTAL option. + compression: An element of grpc.compression, e.g. + grpc.compression.Gzip. This is an EXPERIMENTAL option. Returns: An object that is both a Call for the RPC and an iterator of @@ -1145,17 +1145,17 @@ class ServicerContext(six.with_metaclass(abc.ABCMeta, RpcContext)): """ raise NotImplementedError() - def set_compression(self, compression): - """Set the compression algorithm to be used for the entire call. - - This is an EXPERIMENTAL method. - - Args: - compression: An element of grpc.compression, e.g. - grpc.compression.Gzip. - """ - raise NotImplementedError() - + def set_compression(self, compression): + """Set the compression algorithm to be used for the entire call. + + This is an EXPERIMENTAL method. + + Args: + compression: An element of grpc.compression, e.g. + grpc.compression.Gzip. + """ + raise NotImplementedError() + @abc.abstractmethod def send_initial_metadata(self, initial_metadata): """Sends the initial metadata value to the client. @@ -1196,7 +1196,7 @@ class ServicerContext(six.with_metaclass(abc.ABCMeta, RpcContext)): Args: code: A StatusCode object to be sent to the client. It must not be StatusCode.OK. - details: A UTF-8-encodable string to be sent to the client upon + details: A UTF-8-encodable string to be sent to the client upon termination of the RPC. Raises: @@ -1244,22 +1244,22 @@ class ServicerContext(six.with_metaclass(abc.ABCMeta, RpcContext)): no details to transmit. Args: - details: A UTF-8-encodable string to be sent to the client upon + details: A UTF-8-encodable string to be sent to the client upon termination of the RPC. """ raise NotImplementedError() - def disable_next_message_compression(self): - """Disables compression for the next response message. - - This is an EXPERIMENTAL method. - - This method will override any compression configuration set during - server creation or set on the call. - """ - raise NotImplementedError() - - + def disable_next_message_compression(self): + """Disables compression for the next response message. + + This is an EXPERIMENTAL method. + + This method will override any compression configuration set during + server creation or set on the call. + """ + raise NotImplementedError() + + ##################### Service-Side Handler Interfaces ######################## @@ -1301,7 +1301,7 @@ class RpcMethodHandler(six.with_metaclass(abc.ABCMeta)): class HandlerCallDetails(six.with_metaclass(abc.ABCMeta)): """Describes an RPC that has just arrived for service. - + Attributes: method: The method name of the RPC. invocation_metadata: The :term:`metadata` sent by the client. @@ -1398,8 +1398,8 @@ class Server(six.with_metaclass(abc.ABCMeta)): This method may only be called before starting the server. Args: - address: The address for which to open a port. If the port is 0, - or not specified in the address, then gRPC runtime will choose a port. + address: The address for which to open a port. If the port is 0, + or not specified in the address, then gRPC runtime will choose a port. Returns: An integer port on which server will accept RPC requests. @@ -1461,30 +1461,30 @@ class Server(six.with_metaclass(abc.ABCMeta)): """ raise NotImplementedError() - def wait_for_termination(self, timeout=None): - """Block current thread until the server stops. - - This is an EXPERIMENTAL API. - - The wait will not consume computational resources during blocking, and - it will block until one of the two following conditions are met: - - 1) The server is stopped or terminated; - 2) A timeout occurs if timeout is not `None`. - - The timeout argument works in the same way as `threading.Event.wait()`. + def wait_for_termination(self, timeout=None): + """Block current thread until the server stops. + + This is an EXPERIMENTAL API. + + The wait will not consume computational resources during blocking, and + it will block until one of the two following conditions are met: + + 1) The server is stopped or terminated; + 2) A timeout occurs if timeout is not `None`. + + The timeout argument works in the same way as `threading.Event.wait()`. https://docs.python.org/3/library/threading.html#threading.Event.wait - - Args: - timeout: A floating point number specifying a timeout for the - operation in seconds. - - Returns: - A bool indicates if the operation times out. - """ - raise NotImplementedError() - - + + Args: + timeout: A floating point number specifying a timeout for the + operation in seconds. + + Returns: + A bool indicates if the operation times out. + """ + raise NotImplementedError() + + ################################# Functions ################################ @@ -1761,78 +1761,78 @@ def dynamic_ssl_server_credentials(initial_certificate_configuration, certificate_configuration_fetcher, require_client_authentication)) -@enum.unique -class LocalConnectionType(enum.Enum): - """Types of local connection for local credential creation. - - Attributes: - UDS: Unix domain socket connections - LOCAL_TCP: Local TCP connections. - """ - UDS = _cygrpc.LocalConnectionType.uds - LOCAL_TCP = _cygrpc.LocalConnectionType.local_tcp - - -def local_channel_credentials(local_connect_type=LocalConnectionType.LOCAL_TCP): - """Creates a local ChannelCredentials used for local connections. - - This is an EXPERIMENTAL API. - - Local credentials are used by local TCP endpoints (e.g. localhost:10000) - also UDS connections. - - The connections created by local channel credentials are not - encrypted, but will be checked if they are local or not. - The UDS connections are considered secure by providing peer authentication - and data confidentiality while TCP connections are considered insecure. - - It is allowed to transmit call credentials over connections created by - local channel credentials. - - Local channel credentials are useful for 1) eliminating insecure_channel usage; - 2) enable unit testing for call credentials without setting up secrets. - - Args: - local_connect_type: Local connection type (either - grpc.LocalConnectionType.UDS or grpc.LocalConnectionType.LOCAL_TCP) - - Returns: - A ChannelCredentials for use with a local Channel - """ - return ChannelCredentials( - _cygrpc.channel_credentials_local(local_connect_type.value)) - - -def local_server_credentials(local_connect_type=LocalConnectionType.LOCAL_TCP): - """Creates a local ServerCredentials used for local connections. - - This is an EXPERIMENTAL API. - - Local credentials are used by local TCP endpoints (e.g. localhost:10000) - also UDS connections. - - The connections created by local server credentials are not - encrypted, but will be checked if they are local or not. - The UDS connections are considered secure by providing peer authentication - and data confidentiality while TCP connections are considered insecure. - - It is allowed to transmit call credentials over connections created by local - server credentials. - - Local server credentials are useful for 1) eliminating insecure_channel usage; - 2) enable unit testing for call credentials without setting up secrets. - - Args: - local_connect_type: Local connection type (either - grpc.LocalConnectionType.UDS or grpc.LocalConnectionType.LOCAL_TCP) - - Returns: - A ServerCredentials for use with a local Server - """ - return ServerCredentials( - _cygrpc.server_credentials_local(local_connect_type.value)) - - +@enum.unique +class LocalConnectionType(enum.Enum): + """Types of local connection for local credential creation. + + Attributes: + UDS: Unix domain socket connections + LOCAL_TCP: Local TCP connections. + """ + UDS = _cygrpc.LocalConnectionType.uds + LOCAL_TCP = _cygrpc.LocalConnectionType.local_tcp + + +def local_channel_credentials(local_connect_type=LocalConnectionType.LOCAL_TCP): + """Creates a local ChannelCredentials used for local connections. + + This is an EXPERIMENTAL API. + + Local credentials are used by local TCP endpoints (e.g. localhost:10000) + also UDS connections. + + The connections created by local channel credentials are not + encrypted, but will be checked if they are local or not. + The UDS connections are considered secure by providing peer authentication + and data confidentiality while TCP connections are considered insecure. + + It is allowed to transmit call credentials over connections created by + local channel credentials. + + Local channel credentials are useful for 1) eliminating insecure_channel usage; + 2) enable unit testing for call credentials without setting up secrets. + + Args: + local_connect_type: Local connection type (either + grpc.LocalConnectionType.UDS or grpc.LocalConnectionType.LOCAL_TCP) + + Returns: + A ChannelCredentials for use with a local Channel + """ + return ChannelCredentials( + _cygrpc.channel_credentials_local(local_connect_type.value)) + + +def local_server_credentials(local_connect_type=LocalConnectionType.LOCAL_TCP): + """Creates a local ServerCredentials used for local connections. + + This is an EXPERIMENTAL API. + + Local credentials are used by local TCP endpoints (e.g. localhost:10000) + also UDS connections. + + The connections created by local server credentials are not + encrypted, but will be checked if they are local or not. + The UDS connections are considered secure by providing peer authentication + and data confidentiality while TCP connections are considered insecure. + + It is allowed to transmit call credentials over connections created by local + server credentials. + + Local server credentials are useful for 1) eliminating insecure_channel usage; + 2) enable unit testing for call credentials without setting up secrets. + + Args: + local_connect_type: Local connection type (either + grpc.LocalConnectionType.UDS or grpc.LocalConnectionType.LOCAL_TCP) + + Returns: + A ServerCredentials for use with a local Server + """ + return ServerCredentials( + _cygrpc.server_credentials_local(local_connect_type.value)) + + def alts_channel_credentials(service_accounts=None): """Creates a ChannelCredentials for use with an ALTS-enabled Channel. @@ -1902,7 +1902,7 @@ def channel_ready_future(channel): return _utilities.channel_ready_future(channel) -def insecure_channel(target, options=None, compression=None): +def insecure_channel(target, options=None, compression=None): """Creates an insecure Channel to a server. The returned Channel is thread-safe. @@ -1911,8 +1911,8 @@ def insecure_channel(target, options=None, compression=None): target: The server address options: An optional list of key-value pairs (:term:`channel_arguments` in gRPC Core runtime) to configure the channel. - compression: An optional value indicating the compression method to be - used over the lifetime of the channel. This is an EXPERIMENTAL option. + compression: An optional value indicating the compression method to be + used over the lifetime of the channel. This is an EXPERIMENTAL option. Returns: A Channel. @@ -1922,7 +1922,7 @@ def insecure_channel(target, options=None, compression=None): compression) -def secure_channel(target, credentials, options=None, compression=None): +def secure_channel(target, credentials, options=None, compression=None): """Creates a secure Channel to a server. The returned Channel is thread-safe. @@ -1932,8 +1932,8 @@ def secure_channel(target, credentials, options=None, compression=None): credentials: A ChannelCredentials instance. options: An optional list of key-value pairs (:term:`channel_arguments` in gRPC Core runtime) to configure the channel. - compression: An optional value indicating the compression method to be - used over the lifetime of the channel. This is an EXPERIMENTAL option. + compression: An optional value indicating the compression method to be + used over the lifetime of the channel. This is an EXPERIMENTAL option. Returns: A Channel. @@ -1945,7 +1945,7 @@ def secure_channel(target, credentials, options=None, compression=None): "secure_channel cannot be called with insecure credentials." + " Call insecure_channel instead.") return _channel.Channel(target, () if options is None else options, - credentials._credentials, compression) + credentials._credentials, compression) def intercept_channel(channel, *interceptors): @@ -1980,8 +1980,8 @@ def server(thread_pool, handlers=None, interceptors=None, options=None, - maximum_concurrent_rpcs=None, - compression=None): + maximum_concurrent_rpcs=None, + compression=None): """Creates a Server with which RPCs can be serviced. Args: @@ -1999,9 +1999,9 @@ def server(thread_pool, maximum_concurrent_rpcs: The maximum number of concurrent RPCs this server will service before returning RESOURCE_EXHAUSTED status, or None to indicate no limit. - compression: An element of grpc.compression, e.g. - grpc.compression.Gzip. This compression algorithm will be used for the - lifetime of the server unless overridden. This is an EXPERIMENTAL option. + compression: An element of grpc.compression, e.g. + grpc.compression.Gzip. This compression algorithm will be used for the + lifetime of the server unless overridden. This is an EXPERIMENTAL option. Returns: A Server object. @@ -2011,33 +2011,33 @@ def server(thread_pool, () if handlers is None else handlers, () if interceptors is None else interceptors, () if options is None else options, - maximum_concurrent_rpcs, compression) - - -@contextlib.contextmanager -def _create_servicer_context(rpc_event, state, request_deserializer): - from grpc import _server # pylint: disable=cyclic-import - context = _server._Context(rpc_event, state, request_deserializer) - yield context - context._finalize_state() # pylint: disable=protected-access - - -@enum.unique -class Compression(enum.IntEnum): - """Indicates the compression method to be used for an RPC. - - This enumeration is part of an EXPERIMENTAL API. - - Attributes: - NoCompression: Do not use compression algorithm. - Deflate: Use "Deflate" compression algorithm. - Gzip: Use "Gzip" compression algorithm. - """ - NoCompression = _compression.NoCompression - Deflate = _compression.Deflate - Gzip = _compression.Gzip - - + maximum_concurrent_rpcs, compression) + + +@contextlib.contextmanager +def _create_servicer_context(rpc_event, state, request_deserializer): + from grpc import _server # pylint: disable=cyclic-import + context = _server._Context(rpc_event, state, request_deserializer) + yield context + context._finalize_state() # pylint: disable=protected-access + + +@enum.unique +class Compression(enum.IntEnum): + """Indicates the compression method to be used for an RPC. + + This enumeration is part of an EXPERIMENTAL API. + + Attributes: + NoCompression: Do not use compression algorithm. + Deflate: Use "Deflate" compression algorithm. + Gzip: Use "Gzip" compression algorithm. + """ + NoCompression = _compression.NoCompression + Deflate = _compression.Deflate + Gzip = _compression.Gzip + + from grpc._runtime_protos import protos, services, protos_and_services # pylint: disable=wrong-import-position ################################### __all__ ################################# @@ -2057,11 +2057,11 @@ __all__ = ( 'AuthMetadataContext', 'AuthMetadataPluginCallback', 'AuthMetadataPlugin', - 'Compression', + 'Compression', 'ClientCallDetails', 'ServerCertificateConfiguration', 'ServerCredentials', - 'LocalConnectionType', + 'LocalConnectionType', 'UnaryUnaryMultiCallable', 'UnaryStreamMultiCallable', 'StreamUnaryMultiCallable', @@ -2088,8 +2088,8 @@ __all__ = ( 'access_token_call_credentials', 'composite_call_credentials', 'composite_channel_credentials', - 'local_channel_credentials', - 'local_server_credentials', + 'local_channel_credentials', + 'local_server_credentials', 'alts_channel_credentials', 'alts_server_credentials', 'ssl_server_credentials', diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/_channel.py b/contrib/libs/grpc/src/python/grpcio/grpc/_channel.py index 11921d7883..f8ffb7eb2a 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/_channel.py +++ b/contrib/libs/grpc/src/python/grpcio/grpc/_channel.py @@ -13,17 +13,17 @@ # limitations under the License. """Invocation-side implementation of gRPC Python.""" -import copy -import functools +import copy +import functools import logging -import os +import os import sys import threading import time import grpc -import grpc.experimental -from grpc import _compression +import grpc.experimental +from grpc import _compression from grpc import _common from grpc import _grpcio_metadata from grpc._cython import cygrpc @@ -34,11 +34,11 @@ _USER_AGENT = 'grpc-python/{}'.format(_grpcio_metadata.__version__) _EMPTY_FLAGS = 0 -# NOTE(rbellevi): No guarantees are given about the maintenance of this -# environment variable. -_DEFAULT_SINGLE_THREADED_UNARY_STREAM = os.getenv( - "GRPC_SINGLE_THREADED_UNARY_STREAM") is not None - +# NOTE(rbellevi): No guarantees are given about the maintenance of this +# environment variable. +_DEFAULT_SINGLE_THREADED_UNARY_STREAM = os.getenv( + "GRPC_SINGLE_THREADED_UNARY_STREAM") is not None + _UNARY_UNARY_INITIAL_DUE = ( cygrpc.OperationType.send_initial_metadata, cygrpc.OperationType.send_message, @@ -69,12 +69,12 @@ _STREAM_STREAM_INITIAL_DUE = ( _CHANNEL_SUBSCRIPTION_CALLBACK_ERROR_LOG_MESSAGE = ( 'Exception calling channel subscription callback!') -_OK_RENDEZVOUS_REPR_FORMAT = ('<{} of RPC that terminated with:\n' +_OK_RENDEZVOUS_REPR_FORMAT = ('<{} of RPC that terminated with:\n' '\tstatus = {}\n' '\tdetails = "{}"\n' '>') -_NON_OK_RENDEZVOUS_REPR_FORMAT = ('<{} of RPC that terminated with:\n' +_NON_OK_RENDEZVOUS_REPR_FORMAT = ('<{} of RPC that terminated with:\n' '\tstatus = {}\n' '\tdetails = "{}"\n' '\tdebug_error_string = "{}"\n' @@ -167,11 +167,11 @@ def _event_handler(state, response_deserializer): state.condition.notify_all() done = not state.due for callback in callbacks: - try: - callback() - except Exception as e: # pylint: disable=broad-except - # NOTE(rbellevi): We suppress but log errors here so as not to - # kill the channel spin thread. + try: + callback() + except Exception as e: # pylint: disable=broad-except + # NOTE(rbellevi): We suppress but log errors here so as not to + # kill the channel spin thread. logging.error('Exception in callback %s: %s', repr(callback.func), repr(e)) return done and state.fork_epoch >= cygrpc.get_fork_epoch() @@ -182,11 +182,11 @@ def _event_handler(state, response_deserializer): #pylint: disable=too-many-statements def _consume_request_iterator(request_iterator, state, call, request_serializer, event_handler): - """Consume a request iterator supplied by the user.""" + """Consume a request iterator supplied by the user.""" def consume_request_iterator(): # pylint: disable=too-many-branches - # Iterate over the request iterator until it is exhausted or an error - # condition is encountered. + # Iterate over the request iterator until it is exhausted or an error + # condition is encountered. while True: return_from_user_request_generator_invoked = False try: @@ -227,19 +227,19 @@ def _consume_request_iterator(request_iterator, state, call, request_serializer, state.due.add(cygrpc.OperationType.send_message) else: return - - def _done(): - return (state.code is not None or - cygrpc.OperationType.send_message not in - state.due) - + + def _done(): + return (state.code is not None or + cygrpc.OperationType.send_message not in + state.due) + _common.wait(state.condition.wait, _done, spin_cb=functools.partial( cygrpc.block_if_fork_in_progress, state)) - if state.code is not None: - return + if state.code is not None: + return else: return with state.condition: @@ -256,112 +256,112 @@ def _consume_request_iterator(request_iterator, state, call, request_serializer, consumption_thread.start() -def _rpc_state_string(class_name, rpc_state): - """Calculates error string for RPC.""" - with rpc_state.condition: - if rpc_state.code is None: - return '<{} object>'.format(class_name) - elif rpc_state.code is grpc.StatusCode.OK: - return _OK_RENDEZVOUS_REPR_FORMAT.format(class_name, rpc_state.code, - rpc_state.details) - else: - return _NON_OK_RENDEZVOUS_REPR_FORMAT.format( - class_name, rpc_state.code, rpc_state.details, - rpc_state.debug_error_string) - - -class _InactiveRpcError(grpc.RpcError, grpc.Call, grpc.Future): - """An RPC error not tied to the execution of a particular RPC. - - The RPC represented by the state object must not be in-progress or - cancelled. - - Attributes: - _state: An instance of _RPCState. - """ - - def __init__(self, state): - with state.condition: - self._state = _RPCState((), copy.deepcopy(state.initial_metadata), - copy.deepcopy(state.trailing_metadata), - state.code, copy.deepcopy(state.details)) - self._state.response = copy.copy(state.response) - self._state.debug_error_string = copy.copy(state.debug_error_string) - - def initial_metadata(self): - return self._state.initial_metadata - - def trailing_metadata(self): - return self._state.trailing_metadata - - def code(self): - return self._state.code - - def details(self): - return _common.decode(self._state.details) - - def debug_error_string(self): - return _common.decode(self._state.debug_error_string) - - def _repr(self): - return _rpc_state_string(self.__class__.__name__, self._state) - - def __repr__(self): - return self._repr() - - def __str__(self): - return self._repr() - - def cancel(self): - """See grpc.Future.cancel.""" - return False - - def cancelled(self): - """See grpc.Future.cancelled.""" - return False - - def running(self): - """See grpc.Future.running.""" - return False - - def done(self): - """See grpc.Future.done.""" - return True - - def result(self, timeout=None): # pylint: disable=unused-argument - """See grpc.Future.result.""" - raise self - - def exception(self, timeout=None): # pylint: disable=unused-argument - """See grpc.Future.exception.""" - return self - - def traceback(self, timeout=None): # pylint: disable=unused-argument - """See grpc.Future.traceback.""" - try: - raise self - except grpc.RpcError: - return sys.exc_info()[2] - - def add_done_callback(self, fn, timeout=None): # pylint: disable=unused-argument - """See grpc.Future.add_done_callback.""" - fn(self) - - -class _Rendezvous(grpc.RpcError, grpc.RpcContext): - """An RPC iterator. - - Attributes: - _state: An instance of _RPCState. - _call: An instance of SegregatedCall or IntegratedCall. - In either case, the _call object is expected to have operate, cancel, - and next_event methods. - _response_deserializer: A callable taking bytes and return a Python - object. - _deadline: A float representing the deadline of the RPC in seconds. Or - possibly None, to represent an RPC with no deadline at all. - """ - +def _rpc_state_string(class_name, rpc_state): + """Calculates error string for RPC.""" + with rpc_state.condition: + if rpc_state.code is None: + return '<{} object>'.format(class_name) + elif rpc_state.code is grpc.StatusCode.OK: + return _OK_RENDEZVOUS_REPR_FORMAT.format(class_name, rpc_state.code, + rpc_state.details) + else: + return _NON_OK_RENDEZVOUS_REPR_FORMAT.format( + class_name, rpc_state.code, rpc_state.details, + rpc_state.debug_error_string) + + +class _InactiveRpcError(grpc.RpcError, grpc.Call, grpc.Future): + """An RPC error not tied to the execution of a particular RPC. + + The RPC represented by the state object must not be in-progress or + cancelled. + + Attributes: + _state: An instance of _RPCState. + """ + + def __init__(self, state): + with state.condition: + self._state = _RPCState((), copy.deepcopy(state.initial_metadata), + copy.deepcopy(state.trailing_metadata), + state.code, copy.deepcopy(state.details)) + self._state.response = copy.copy(state.response) + self._state.debug_error_string = copy.copy(state.debug_error_string) + + def initial_metadata(self): + return self._state.initial_metadata + + def trailing_metadata(self): + return self._state.trailing_metadata + + def code(self): + return self._state.code + + def details(self): + return _common.decode(self._state.details) + + def debug_error_string(self): + return _common.decode(self._state.debug_error_string) + + def _repr(self): + return _rpc_state_string(self.__class__.__name__, self._state) + + def __repr__(self): + return self._repr() + + def __str__(self): + return self._repr() + + def cancel(self): + """See grpc.Future.cancel.""" + return False + + def cancelled(self): + """See grpc.Future.cancelled.""" + return False + + def running(self): + """See grpc.Future.running.""" + return False + + def done(self): + """See grpc.Future.done.""" + return True + + def result(self, timeout=None): # pylint: disable=unused-argument + """See grpc.Future.result.""" + raise self + + def exception(self, timeout=None): # pylint: disable=unused-argument + """See grpc.Future.exception.""" + return self + + def traceback(self, timeout=None): # pylint: disable=unused-argument + """See grpc.Future.traceback.""" + try: + raise self + except grpc.RpcError: + return sys.exc_info()[2] + + def add_done_callback(self, fn, timeout=None): # pylint: disable=unused-argument + """See grpc.Future.add_done_callback.""" + fn(self) + + +class _Rendezvous(grpc.RpcError, grpc.RpcContext): + """An RPC iterator. + + Attributes: + _state: An instance of _RPCState. + _call: An instance of SegregatedCall or IntegratedCall. + In either case, the _call object is expected to have operate, cancel, + and next_event methods. + _response_deserializer: A callable taking bytes and return a Python + object. + _deadline: A float representing the deadline of the RPC in seconds. Or + possibly None, to represent an RPC with no deadline at all. + """ + def __init__(self, state, call, response_deserializer, deadline): super(_Rendezvous, self).__init__() self._state = state @@ -369,21 +369,21 @@ class _Rendezvous(grpc.RpcError, grpc.RpcContext): self._response_deserializer = response_deserializer self._deadline = deadline - def is_active(self): - """See grpc.RpcContext.is_active""" - with self._state.condition: - return self._state.code is None - - def time_remaining(self): - """See grpc.RpcContext.time_remaining""" - with self._state.condition: - if self._deadline is None: - return None - else: - return max(self._deadline - time.time(), 0) - + def is_active(self): + """See grpc.RpcContext.is_active""" + with self._state.condition: + return self._state.code is None + + def time_remaining(self): + """See grpc.RpcContext.time_remaining""" + with self._state.condition: + if self._deadline is None: + return None + else: + return max(self._deadline - time.time(), 0) + def cancel(self): - """See grpc.RpcContext.cancel""" + """See grpc.RpcContext.cancel""" with self._state.condition: if self._state.code is None: code = grpc.StatusCode.CANCELLED @@ -393,69 +393,69 @@ class _Rendezvous(grpc.RpcError, grpc.RpcContext): self._state.cancelled = True _abort(self._state, code, details) self._state.condition.notify_all() - return True - else: - return False - - def add_callback(self, callback): - """See grpc.RpcContext.add_callback""" - with self._state.condition: - if self._state.callbacks is None: - return False - else: - self._state.callbacks.append(callback) - return True - - def __iter__(self): - return self - - def next(self): - return self._next() - - def __next__(self): - return self._next() - - def _next(self): - raise NotImplementedError() - - def debug_error_string(self): - raise NotImplementedError() - - def _repr(self): - return _rpc_state_string(self.__class__.__name__, self._state) - - def __repr__(self): - return self._repr() - - def __str__(self): - return self._repr() - - def __del__(self): - with self._state.condition: - if self._state.code is None: - self._state.code = grpc.StatusCode.CANCELLED - self._state.details = 'Cancelled upon garbage collection!' - self._state.cancelled = True - self._call.cancel( - _common.STATUS_CODE_TO_CYGRPC_STATUS_CODE[self._state.code], - self._state.details) - self._state.condition.notify_all() - - + return True + else: + return False + + def add_callback(self, callback): + """See grpc.RpcContext.add_callback""" + with self._state.condition: + if self._state.callbacks is None: + return False + else: + self._state.callbacks.append(callback) + return True + + def __iter__(self): + return self + + def next(self): + return self._next() + + def __next__(self): + return self._next() + + def _next(self): + raise NotImplementedError() + + def debug_error_string(self): + raise NotImplementedError() + + def _repr(self): + return _rpc_state_string(self.__class__.__name__, self._state) + + def __repr__(self): + return self._repr() + + def __str__(self): + return self._repr() + + def __del__(self): + with self._state.condition: + if self._state.code is None: + self._state.code = grpc.StatusCode.CANCELLED + self._state.details = 'Cancelled upon garbage collection!' + self._state.cancelled = True + self._call.cancel( + _common.STATUS_CODE_TO_CYGRPC_STATUS_CODE[self._state.code], + self._state.details) + self._state.condition.notify_all() + + class _SingleThreadedRendezvous(_Rendezvous, grpc.Call, grpc.Future): # pylint: disable=too-many-ancestors - """An RPC iterator operating entirely on a single thread. - - The __next__ method of _SingleThreadedRendezvous does not depend on the - existence of any other thread, including the "channel spin thread". - However, this means that its interface is entirely synchronous. So this + """An RPC iterator operating entirely on a single thread. + + The __next__ method of _SingleThreadedRendezvous does not depend on the + existence of any other thread, including the "channel spin thread". + However, this means that its interface is entirely synchronous. So this class cannot completely fulfill the grpc.Future interface. The result, exception, and traceback methods will never block and will instead raise an exception if calling the method would result in blocking. This means that these methods are safe to call from add_done_callback handlers. - """ - + """ + def _is_complete(self): return self._state.code is not None @@ -548,145 +548,145 @@ class _SingleThreadedRendezvous(_Rendezvous, grpc.Call, grpc.Future): # pylint: fn(self) - def initial_metadata(self): - """See grpc.Call.initial_metadata""" - with self._state.condition: - # NOTE(gnossen): Based on our initial call batch, we are guaranteed - # to receive initial metadata before any messages. - while self._state.initial_metadata is None: - self._consume_next_event() - return self._state.initial_metadata - - def trailing_metadata(self): - """See grpc.Call.trailing_metadata""" - with self._state.condition: - if self._state.trailing_metadata is None: - raise grpc.experimental.UsageError( - "Cannot get trailing metadata until RPC is completed.") - return self._state.trailing_metadata - - def code(self): - """See grpc.Call.code""" - with self._state.condition: - if self._state.code is None: - raise grpc.experimental.UsageError( - "Cannot get code until RPC is completed.") - return self._state.code - - def details(self): - """See grpc.Call.details""" - with self._state.condition: - if self._state.details is None: - raise grpc.experimental.UsageError( - "Cannot get details until RPC is completed.") - return _common.decode(self._state.details) - - def _consume_next_event(self): - event = self._call.next_event() - with self._state.condition: - callbacks = _handle_event(event, self._state, - self._response_deserializer) - for callback in callbacks: - # NOTE(gnossen): We intentionally allow exceptions to bubble up - # to the user when running on a single thread. - callback() - return event - - def _next_response(self): - while True: - self._consume_next_event() - with self._state.condition: - if self._state.response is not None: - response = self._state.response - self._state.response = None - return response - elif cygrpc.OperationType.receive_message not in self._state.due: - if self._state.code is grpc.StatusCode.OK: - raise StopIteration() - elif self._state.code is not None: - raise self - - def _next(self): - with self._state.condition: - if self._state.code is None: - operating = self._call.operate( - (cygrpc.ReceiveMessageOperation(_EMPTY_FLAGS),), None) - if operating: - self._state.due.add(cygrpc.OperationType.receive_message) - elif self._state.code is grpc.StatusCode.OK: - raise StopIteration() - else: - raise self - return self._next_response() - - def debug_error_string(self): - with self._state.condition: - if self._state.debug_error_string is None: - raise grpc.experimental.UsageError( - "Cannot get debug error string until RPC is completed.") - return _common.decode(self._state.debug_error_string) - - -class _MultiThreadedRendezvous(_Rendezvous, grpc.Call, grpc.Future): # pylint: disable=too-many-ancestors - """An RPC iterator that depends on a channel spin thread. - - This iterator relies upon a per-channel thread running in the background, - dequeueing events from the completion queue, and notifying threads waiting - on the threading.Condition object in the _RPCState object. - - This extra thread allows _MultiThreadedRendezvous to fulfill the grpc.Future interface - and to mediate a bidirection streaming RPC. - """ - - def initial_metadata(self): - """See grpc.Call.initial_metadata""" - with self._state.condition: - - def _done(): - return self._state.initial_metadata is not None - - _common.wait(self._state.condition.wait, _done) - return self._state.initial_metadata - - def trailing_metadata(self): - """See grpc.Call.trailing_metadata""" - with self._state.condition: - - def _done(): - return self._state.trailing_metadata is not None - - _common.wait(self._state.condition.wait, _done) - return self._state.trailing_metadata - - def code(self): - """See grpc.Call.code""" - with self._state.condition: - - def _done(): - return self._state.code is not None - - _common.wait(self._state.condition.wait, _done) - return self._state.code - - def details(self): - """See grpc.Call.details""" - with self._state.condition: - - def _done(): - return self._state.details is not None - - _common.wait(self._state.condition.wait, _done) - return _common.decode(self._state.details) - - def debug_error_string(self): - with self._state.condition: - - def _done(): - return self._state.debug_error_string is not None - - _common.wait(self._state.condition.wait, _done) - return _common.decode(self._state.debug_error_string) - + def initial_metadata(self): + """See grpc.Call.initial_metadata""" + with self._state.condition: + # NOTE(gnossen): Based on our initial call batch, we are guaranteed + # to receive initial metadata before any messages. + while self._state.initial_metadata is None: + self._consume_next_event() + return self._state.initial_metadata + + def trailing_metadata(self): + """See grpc.Call.trailing_metadata""" + with self._state.condition: + if self._state.trailing_metadata is None: + raise grpc.experimental.UsageError( + "Cannot get trailing metadata until RPC is completed.") + return self._state.trailing_metadata + + def code(self): + """See grpc.Call.code""" + with self._state.condition: + if self._state.code is None: + raise grpc.experimental.UsageError( + "Cannot get code until RPC is completed.") + return self._state.code + + def details(self): + """See grpc.Call.details""" + with self._state.condition: + if self._state.details is None: + raise grpc.experimental.UsageError( + "Cannot get details until RPC is completed.") + return _common.decode(self._state.details) + + def _consume_next_event(self): + event = self._call.next_event() + with self._state.condition: + callbacks = _handle_event(event, self._state, + self._response_deserializer) + for callback in callbacks: + # NOTE(gnossen): We intentionally allow exceptions to bubble up + # to the user when running on a single thread. + callback() + return event + + def _next_response(self): + while True: + self._consume_next_event() + with self._state.condition: + if self._state.response is not None: + response = self._state.response + self._state.response = None + return response + elif cygrpc.OperationType.receive_message not in self._state.due: + if self._state.code is grpc.StatusCode.OK: + raise StopIteration() + elif self._state.code is not None: + raise self + + def _next(self): + with self._state.condition: + if self._state.code is None: + operating = self._call.operate( + (cygrpc.ReceiveMessageOperation(_EMPTY_FLAGS),), None) + if operating: + self._state.due.add(cygrpc.OperationType.receive_message) + elif self._state.code is grpc.StatusCode.OK: + raise StopIteration() + else: + raise self + return self._next_response() + + def debug_error_string(self): + with self._state.condition: + if self._state.debug_error_string is None: + raise grpc.experimental.UsageError( + "Cannot get debug error string until RPC is completed.") + return _common.decode(self._state.debug_error_string) + + +class _MultiThreadedRendezvous(_Rendezvous, grpc.Call, grpc.Future): # pylint: disable=too-many-ancestors + """An RPC iterator that depends on a channel spin thread. + + This iterator relies upon a per-channel thread running in the background, + dequeueing events from the completion queue, and notifying threads waiting + on the threading.Condition object in the _RPCState object. + + This extra thread allows _MultiThreadedRendezvous to fulfill the grpc.Future interface + and to mediate a bidirection streaming RPC. + """ + + def initial_metadata(self): + """See grpc.Call.initial_metadata""" + with self._state.condition: + + def _done(): + return self._state.initial_metadata is not None + + _common.wait(self._state.condition.wait, _done) + return self._state.initial_metadata + + def trailing_metadata(self): + """See grpc.Call.trailing_metadata""" + with self._state.condition: + + def _done(): + return self._state.trailing_metadata is not None + + _common.wait(self._state.condition.wait, _done) + return self._state.trailing_metadata + + def code(self): + """See grpc.Call.code""" + with self._state.condition: + + def _done(): + return self._state.code is not None + + _common.wait(self._state.condition.wait, _done) + return self._state.code + + def details(self): + """See grpc.Call.details""" + with self._state.condition: + + def _done(): + return self._state.details is not None + + _common.wait(self._state.condition.wait, _done) + return _common.decode(self._state.details) + + def debug_error_string(self): + with self._state.condition: + + def _done(): + return self._state.debug_error_string is not None + + _common.wait(self._state.condition.wait, _done) + return _common.decode(self._state.debug_error_string) + def cancelled(self): with self._state.condition: return self._state.cancelled @@ -699,22 +699,22 @@ class _MultiThreadedRendezvous(_Rendezvous, grpc.Call, grpc.Future): # pylint: with self._state.condition: return self._state.code is not None - def _is_complete(self): - return self._state.code is not None - + def _is_complete(self): + return self._state.code is not None + def result(self, timeout=None): - """Returns the result of the computation or raises its exception. - - See grpc.Future.result for the full API contract. - """ + """Returns the result of the computation or raises its exception. + + See grpc.Future.result for the full API contract. + """ with self._state.condition: timed_out = _common.wait(self._state.condition.wait, self._is_complete, timeout=timeout) - if timed_out: - raise grpc.FutureTimeoutError() - else: - if self._state.code is grpc.StatusCode.OK: + if timed_out: + raise grpc.FutureTimeoutError() + else: + if self._state.code is grpc.StatusCode.OK: return self._state.response elif self._state.cancelled: raise grpc.FutureCancelledError() @@ -722,18 +722,18 @@ class _MultiThreadedRendezvous(_Rendezvous, grpc.Call, grpc.Future): # pylint: raise self def exception(self, timeout=None): - """Return the exception raised by the computation. - - See grpc.Future.exception for the full API contract. - """ + """Return the exception raised by the computation. + + See grpc.Future.exception for the full API contract. + """ with self._state.condition: timed_out = _common.wait(self._state.condition.wait, self._is_complete, timeout=timeout) - if timed_out: - raise grpc.FutureTimeoutError() - else: - if self._state.code is grpc.StatusCode.OK: + if timed_out: + raise grpc.FutureTimeoutError() + else: + if self._state.code is grpc.StatusCode.OK: return None elif self._state.cancelled: raise grpc.FutureCancelledError() @@ -741,18 +741,18 @@ class _MultiThreadedRendezvous(_Rendezvous, grpc.Call, grpc.Future): # pylint: return self def traceback(self, timeout=None): - """Access the traceback of the exception raised by the computation. - - See grpc.future.traceback for the full API contract. - """ + """Access the traceback of the exception raised by the computation. + + See grpc.future.traceback for the full API contract. + """ with self._state.condition: timed_out = _common.wait(self._state.condition.wait, self._is_complete, timeout=timeout) - if timed_out: - raise grpc.FutureTimeoutError() - else: - if self._state.code is grpc.StatusCode.OK: + if timed_out: + raise grpc.FutureTimeoutError() + else: + if self._state.code is grpc.StatusCode.OK: return None elif self._state.cancelled: raise grpc.FutureCancelledError() @@ -765,7 +765,7 @@ class _MultiThreadedRendezvous(_Rendezvous, grpc.Call, grpc.Future): # pylint: def add_done_callback(self, fn): with self._state.condition: if self._state.code is None: - self._state.callbacks.append(functools.partial(fn, self)) + self._state.callbacks.append(functools.partial(fn, self)) return fn(self) @@ -785,22 +785,22 @@ class _MultiThreadedRendezvous(_Rendezvous, grpc.Call, grpc.Future): # pylint: else: raise self - def _response_ready(): - return ( - self._state.response is not None or - (cygrpc.OperationType.receive_message not in self._state.due - and self._state.code is not None)) - - _common.wait(self._state.condition.wait, _response_ready) - if self._state.response is not None: - response = self._state.response - self._state.response = None - return response - elif cygrpc.OperationType.receive_message not in self._state.due: - if self._state.code is grpc.StatusCode.OK: - raise StopIteration() - elif self._state.code is not None: - raise self + def _response_ready(): + return ( + self._state.response is not None or + (cygrpc.OperationType.receive_message not in self._state.due + and self._state.code is not None)) + + _common.wait(self._state.condition.wait, _response_ready) + if self._state.response is not None: + response = self._state.response + self._state.response = None + return response + elif cygrpc.OperationType.receive_message not in self._state.due: + if self._state.code is grpc.StatusCode.OK: + raise StopIteration() + elif self._state.code is not None: + raise self def _start_unary_request(request, timeout, request_serializer): @@ -809,8 +809,8 @@ def _start_unary_request(request, timeout, request_serializer): if serialized_request is None: state = _RPCState((), (), (), grpc.StatusCode.INTERNAL, 'Exception serializing request!') - error = _InactiveRpcError(state) - return deadline, None, error + error = _InactiveRpcError(state) + return deadline, None, error else: return deadline, serialized_request, None @@ -818,12 +818,12 @@ def _start_unary_request(request, timeout, request_serializer): def _end_unary_response_blocking(state, call, with_call, deadline): if state.code is grpc.StatusCode.OK: if with_call: - rendezvous = _MultiThreadedRendezvous(state, call, None, deadline) + rendezvous = _MultiThreadedRendezvous(state, call, None, deadline) return state.response, rendezvous else: return state.response else: - raise _InactiveRpcError(state) + raise _InactiveRpcError(state) def _stream_unary_invocation_operationses(metadata, initial_metadata_flags): @@ -847,18 +847,18 @@ def _stream_unary_invocation_operationses_and_tags(metadata, metadata, initial_metadata_flags)) -def _determine_deadline(user_deadline): - parent_deadline = cygrpc.get_deadline_from_context() - if parent_deadline is None and user_deadline is None: - return None - elif parent_deadline is not None and user_deadline is None: - return parent_deadline - elif user_deadline is not None and parent_deadline is None: - return user_deadline - else: - return min(parent_deadline, user_deadline) - - +def _determine_deadline(user_deadline): + parent_deadline = cygrpc.get_deadline_from_context() + if parent_deadline is None and user_deadline is None: + return None + elif parent_deadline is not None and user_deadline is None: + return parent_deadline + elif user_deadline is not None and parent_deadline is None: + return user_deadline + else: + return min(parent_deadline, user_deadline) + + class _UnaryUnaryMultiCallable(grpc.UnaryUnaryMultiCallable): # pylint: disable=too-many-arguments @@ -871,19 +871,19 @@ class _UnaryUnaryMultiCallable(grpc.UnaryUnaryMultiCallable): self._response_deserializer = response_deserializer self._context = cygrpc.build_census_context() - def _prepare(self, request, timeout, metadata, wait_for_ready, compression): + def _prepare(self, request, timeout, metadata, wait_for_ready, compression): deadline, serialized_request, rendezvous = _start_unary_request( request, timeout, self._request_serializer) initial_metadata_flags = _InitialMetadataFlags().with_wait_for_ready( wait_for_ready) - augmented_metadata = _compression.augment_metadata( - metadata, compression) + augmented_metadata = _compression.augment_metadata( + metadata, compression) if serialized_request is None: return None, None, None, rendezvous else: state = _RPCState(_UNARY_UNARY_INITIAL_DUE, None, None, None, None) operations = ( - cygrpc.SendInitialMetadataOperation(augmented_metadata, + cygrpc.SendInitialMetadataOperation(augmented_metadata, initial_metadata_flags), cygrpc.SendMessageOperation(serialized_request, _EMPTY_FLAGS), cygrpc.SendCloseFromClientOperation(_EMPTY_FLAGS), @@ -893,17 +893,17 @@ class _UnaryUnaryMultiCallable(grpc.UnaryUnaryMultiCallable): ) return state, operations, deadline, None - def _blocking(self, request, timeout, metadata, credentials, wait_for_ready, - compression): + def _blocking(self, request, timeout, metadata, credentials, wait_for_ready, + compression): state, operations, deadline, rendezvous = self._prepare( - request, timeout, metadata, wait_for_ready, compression) + request, timeout, metadata, wait_for_ready, compression) if state is None: raise rendezvous # pylint: disable-msg=raising-bad-type else: call = self._channel.segregated_call( cygrpc.PropagationConstants.GRPC_PROPAGATE_DEFAULTS, - self._method, None, _determine_deadline(deadline), metadata, - None if credentials is None else credentials._credentials, (( + self._method, None, _determine_deadline(deadline), metadata, + None if credentials is None else credentials._credentials, (( operations, None, ),), self._context) @@ -916,10 +916,10 @@ class _UnaryUnaryMultiCallable(grpc.UnaryUnaryMultiCallable): timeout=None, metadata=None, credentials=None, - wait_for_ready=None, - compression=None): + wait_for_ready=None, + compression=None): state, call, = self._blocking(request, timeout, metadata, credentials, - wait_for_ready, compression) + wait_for_ready, compression) return _end_unary_response_blocking(state, call, False, None) def with_call(self, @@ -927,10 +927,10 @@ class _UnaryUnaryMultiCallable(grpc.UnaryUnaryMultiCallable): timeout=None, metadata=None, credentials=None, - wait_for_ready=None, - compression=None): + wait_for_ready=None, + compression=None): state, call, = self._blocking(request, timeout, metadata, credentials, - wait_for_ready, compression) + wait_for_ready, compression) return _end_unary_response_blocking(state, call, True, None) def future(self, @@ -938,10 +938,10 @@ class _UnaryUnaryMultiCallable(grpc.UnaryUnaryMultiCallable): timeout=None, metadata=None, credentials=None, - wait_for_ready=None, - compression=None): + wait_for_ready=None, + compression=None): state, operations, deadline, rendezvous = self._prepare( - request, timeout, metadata, wait_for_ready, compression) + request, timeout, metadata, wait_for_ready, compression) if state is None: raise rendezvous # pylint: disable-msg=raising-bad-type else: @@ -956,56 +956,56 @@ class _UnaryUnaryMultiCallable(grpc.UnaryUnaryMultiCallable): deadline) -class _SingleThreadedUnaryStreamMultiCallable(grpc.UnaryStreamMultiCallable): - - # pylint: disable=too-many-arguments - def __init__(self, channel, method, request_serializer, - response_deserializer): - self._channel = channel - self._method = method - self._request_serializer = request_serializer - self._response_deserializer = response_deserializer - self._context = cygrpc.build_census_context() - - def __call__( # pylint: disable=too-many-locals - self, - request, - timeout=None, - metadata=None, - credentials=None, - wait_for_ready=None, - compression=None): - deadline = _deadline(timeout) - serialized_request = _common.serialize(request, - self._request_serializer) - if serialized_request is None: - state = _RPCState((), (), (), grpc.StatusCode.INTERNAL, - 'Exception serializing request!') - raise _InactiveRpcError(state) - - state = _RPCState(_UNARY_STREAM_INITIAL_DUE, None, None, None, None) - call_credentials = None if credentials is None else credentials._credentials - initial_metadata_flags = _InitialMetadataFlags().with_wait_for_ready( - wait_for_ready) - augmented_metadata = _compression.augment_metadata( - metadata, compression) - operations = ( - (cygrpc.SendInitialMetadataOperation(augmented_metadata, - initial_metadata_flags), - cygrpc.SendMessageOperation(serialized_request, _EMPTY_FLAGS), - cygrpc.SendCloseFromClientOperation(_EMPTY_FLAGS)), - (cygrpc.ReceiveStatusOnClientOperation(_EMPTY_FLAGS),), - (cygrpc.ReceiveInitialMetadataOperation(_EMPTY_FLAGS),), - ) - operations_and_tags = tuple((ops, None) for ops in operations) - call = self._channel.segregated_call( - cygrpc.PropagationConstants.GRPC_PROPAGATE_DEFAULTS, self._method, - None, _determine_deadline(deadline), metadata, call_credentials, - operations_and_tags, self._context) - return _SingleThreadedRendezvous(state, call, - self._response_deserializer, deadline) - - +class _SingleThreadedUnaryStreamMultiCallable(grpc.UnaryStreamMultiCallable): + + # pylint: disable=too-many-arguments + def __init__(self, channel, method, request_serializer, + response_deserializer): + self._channel = channel + self._method = method + self._request_serializer = request_serializer + self._response_deserializer = response_deserializer + self._context = cygrpc.build_census_context() + + def __call__( # pylint: disable=too-many-locals + self, + request, + timeout=None, + metadata=None, + credentials=None, + wait_for_ready=None, + compression=None): + deadline = _deadline(timeout) + serialized_request = _common.serialize(request, + self._request_serializer) + if serialized_request is None: + state = _RPCState((), (), (), grpc.StatusCode.INTERNAL, + 'Exception serializing request!') + raise _InactiveRpcError(state) + + state = _RPCState(_UNARY_STREAM_INITIAL_DUE, None, None, None, None) + call_credentials = None if credentials is None else credentials._credentials + initial_metadata_flags = _InitialMetadataFlags().with_wait_for_ready( + wait_for_ready) + augmented_metadata = _compression.augment_metadata( + metadata, compression) + operations = ( + (cygrpc.SendInitialMetadataOperation(augmented_metadata, + initial_metadata_flags), + cygrpc.SendMessageOperation(serialized_request, _EMPTY_FLAGS), + cygrpc.SendCloseFromClientOperation(_EMPTY_FLAGS)), + (cygrpc.ReceiveStatusOnClientOperation(_EMPTY_FLAGS),), + (cygrpc.ReceiveInitialMetadataOperation(_EMPTY_FLAGS),), + ) + operations_and_tags = tuple((ops, None) for ops in operations) + call = self._channel.segregated_call( + cygrpc.PropagationConstants.GRPC_PROPAGATE_DEFAULTS, self._method, + None, _determine_deadline(deadline), metadata, call_credentials, + operations_and_tags, self._context) + return _SingleThreadedRendezvous(state, call, + self._response_deserializer, deadline) + + class _UnaryStreamMultiCallable(grpc.UnaryStreamMultiCallable): # pylint: disable=too-many-arguments @@ -1018,14 +1018,14 @@ class _UnaryStreamMultiCallable(grpc.UnaryStreamMultiCallable): self._response_deserializer = response_deserializer self._context = cygrpc.build_census_context() - def __call__( # pylint: disable=too-many-locals - self, - request, - timeout=None, - metadata=None, - credentials=None, - wait_for_ready=None, - compression=None): + def __call__( # pylint: disable=too-many-locals + self, + request, + timeout=None, + metadata=None, + credentials=None, + wait_for_ready=None, + compression=None): deadline, serialized_request, rendezvous = _start_unary_request( request, timeout, self._request_serializer) initial_metadata_flags = _InitialMetadataFlags().with_wait_for_ready( @@ -1033,12 +1033,12 @@ class _UnaryStreamMultiCallable(grpc.UnaryStreamMultiCallable): if serialized_request is None: raise rendezvous # pylint: disable-msg=raising-bad-type else: - augmented_metadata = _compression.augment_metadata( - metadata, compression) + augmented_metadata = _compression.augment_metadata( + metadata, compression) state = _RPCState(_UNARY_STREAM_INITIAL_DUE, None, None, None, None) operationses = ( ( - cygrpc.SendInitialMetadataOperation(augmented_metadata, + cygrpc.SendInitialMetadataOperation(augmented_metadata, initial_metadata_flags), cygrpc.SendMessageOperation(serialized_request, _EMPTY_FLAGS), @@ -1049,7 +1049,7 @@ class _UnaryStreamMultiCallable(grpc.UnaryStreamMultiCallable): ) call = self._managed_call( cygrpc.PropagationConstants.GRPC_PROPAGATE_DEFAULTS, - self._method, None, _determine_deadline(deadline), metadata, + self._method, None, _determine_deadline(deadline), metadata, None if credentials is None else credentials._credentials, operationses, _event_handler(state, self._response_deserializer), @@ -1072,19 +1072,19 @@ class _StreamUnaryMultiCallable(grpc.StreamUnaryMultiCallable): self._context = cygrpc.build_census_context() def _blocking(self, request_iterator, timeout, metadata, credentials, - wait_for_ready, compression): + wait_for_ready, compression): deadline = _deadline(timeout) state = _RPCState(_STREAM_UNARY_INITIAL_DUE, None, None, None, None) initial_metadata_flags = _InitialMetadataFlags().with_wait_for_ready( wait_for_ready) - augmented_metadata = _compression.augment_metadata( - metadata, compression) + augmented_metadata = _compression.augment_metadata( + metadata, compression) call = self._channel.segregated_call( cygrpc.PropagationConstants.GRPC_PROPAGATE_DEFAULTS, self._method, None, _determine_deadline(deadline), augmented_metadata, None if credentials is None else credentials._credentials, _stream_unary_invocation_operationses_and_tags( - augmented_metadata, initial_metadata_flags), self._context) + augmented_metadata, initial_metadata_flags), self._context) _consume_request_iterator(request_iterator, state, call, self._request_serializer, None) while True: @@ -1101,10 +1101,10 @@ class _StreamUnaryMultiCallable(grpc.StreamUnaryMultiCallable): timeout=None, metadata=None, credentials=None, - wait_for_ready=None, - compression=None): + wait_for_ready=None, + compression=None): state, call, = self._blocking(request_iterator, timeout, metadata, - credentials, wait_for_ready, compression) + credentials, wait_for_ready, compression) return _end_unary_response_blocking(state, call, False, None) def with_call(self, @@ -1112,10 +1112,10 @@ class _StreamUnaryMultiCallable(grpc.StreamUnaryMultiCallable): timeout=None, metadata=None, credentials=None, - wait_for_ready=None, - compression=None): + wait_for_ready=None, + compression=None): state, call, = self._blocking(request_iterator, timeout, metadata, - credentials, wait_for_ready, compression) + credentials, wait_for_ready, compression) return _end_unary_response_blocking(state, call, True, None) def future(self, @@ -1123,15 +1123,15 @@ class _StreamUnaryMultiCallable(grpc.StreamUnaryMultiCallable): timeout=None, metadata=None, credentials=None, - wait_for_ready=None, - compression=None): + wait_for_ready=None, + compression=None): deadline = _deadline(timeout) state = _RPCState(_STREAM_UNARY_INITIAL_DUE, None, None, None, None) event_handler = _event_handler(state, self._response_deserializer) initial_metadata_flags = _InitialMetadataFlags().with_wait_for_ready( wait_for_ready) - augmented_metadata = _compression.augment_metadata( - metadata, compression) + augmented_metadata = _compression.augment_metadata( + metadata, compression) call = self._managed_call( cygrpc.PropagationConstants.GRPC_PROPAGATE_DEFAULTS, self._method, None, deadline, augmented_metadata, @@ -1141,8 +1141,8 @@ class _StreamUnaryMultiCallable(grpc.StreamUnaryMultiCallable): event_handler, self._context) _consume_request_iterator(request_iterator, state, call, self._request_serializer, event_handler) - return _MultiThreadedRendezvous(state, call, - self._response_deserializer, deadline) + return _MultiThreadedRendezvous(state, call, + self._response_deserializer, deadline) class _StreamStreamMultiCallable(grpc.StreamStreamMultiCallable): @@ -1162,17 +1162,17 @@ class _StreamStreamMultiCallable(grpc.StreamStreamMultiCallable): timeout=None, metadata=None, credentials=None, - wait_for_ready=None, - compression=None): + wait_for_ready=None, + compression=None): deadline = _deadline(timeout) state = _RPCState(_STREAM_STREAM_INITIAL_DUE, None, None, None, None) initial_metadata_flags = _InitialMetadataFlags().with_wait_for_ready( wait_for_ready) - augmented_metadata = _compression.augment_metadata( - metadata, compression) + augmented_metadata = _compression.augment_metadata( + metadata, compression) operationses = ( ( - cygrpc.SendInitialMetadataOperation(augmented_metadata, + cygrpc.SendInitialMetadataOperation(augmented_metadata, initial_metadata_flags), cygrpc.ReceiveStatusOnClientOperation(_EMPTY_FLAGS), ), @@ -1186,8 +1186,8 @@ class _StreamStreamMultiCallable(grpc.StreamStreamMultiCallable): operationses, event_handler, self._context) _consume_request_iterator(request_iterator, state, call, self._request_serializer, event_handler) - return _MultiThreadedRendezvous(state, call, - self._response_deserializer, deadline) + return _MultiThreadedRendezvous(state, call, + self._response_deserializer, deadline) class _InitialMetadataFlags(int): @@ -1416,55 +1416,55 @@ def _unsubscribe(state, callback): break -def _augment_options(base_options, compression): - compression_option = _compression.create_channel_option(compression) - return tuple(base_options) + compression_option + (( - cygrpc.ChannelArgKey.primary_user_agent_string, - _USER_AGENT, - ),) - - -def _separate_channel_options(options): - """Separates core channel options from Python channel options.""" - core_options = [] - python_options = [] - for pair in options: - if pair[0] == grpc.experimental.ChannelOptions.SingleThreadedUnaryStream: - python_options.append(pair) - else: - core_options.append(pair) - return python_options, core_options - - +def _augment_options(base_options, compression): + compression_option = _compression.create_channel_option(compression) + return tuple(base_options) + compression_option + (( + cygrpc.ChannelArgKey.primary_user_agent_string, + _USER_AGENT, + ),) + + +def _separate_channel_options(options): + """Separates core channel options from Python channel options.""" + core_options = [] + python_options = [] + for pair in options: + if pair[0] == grpc.experimental.ChannelOptions.SingleThreadedUnaryStream: + python_options.append(pair) + else: + core_options.append(pair) + return python_options, core_options + + class Channel(grpc.Channel): """A cygrpc.Channel-backed implementation of grpc.Channel.""" - def __init__(self, target, options, credentials, compression): + def __init__(self, target, options, credentials, compression): """Constructor. Args: target: The target to which to connect. options: Configuration options for the channel. credentials: A cygrpc.ChannelCredentials or None. - compression: An optional value indicating the compression method to be - used over the lifetime of the channel. + compression: An optional value indicating the compression method to be + used over the lifetime of the channel. """ - python_options, core_options = _separate_channel_options(options) - self._single_threaded_unary_stream = _DEFAULT_SINGLE_THREADED_UNARY_STREAM - self._process_python_options(python_options) + python_options, core_options = _separate_channel_options(options) + self._single_threaded_unary_stream = _DEFAULT_SINGLE_THREADED_UNARY_STREAM + self._process_python_options(python_options) self._channel = cygrpc.Channel( - _common.encode(target), _augment_options(core_options, compression), - credentials) + _common.encode(target), _augment_options(core_options, compression), + credentials) self._call_state = _ChannelCallState(self._channel) self._connectivity_state = _ChannelConnectivityState(self._channel) cygrpc.fork_register_channel(self) - def _process_python_options(self, python_options): - """Sets channel attributes according to python-only channel options.""" - for pair in python_options: - if pair[0] == grpc.experimental.ChannelOptions.SingleThreadedUnaryStream: - self._single_threaded_unary_stream = True - + def _process_python_options(self, python_options): + """Sets channel attributes according to python-only channel options.""" + for pair in python_options: + if pair[0] == grpc.experimental.ChannelOptions.SingleThreadedUnaryStream: + self._single_threaded_unary_stream = True + def subscribe(self, callback, try_to_connect=None): _subscribe(self._connectivity_state, callback, try_to_connect) @@ -1483,15 +1483,15 @@ class Channel(grpc.Channel): method, request_serializer=None, response_deserializer=None): - # NOTE(rbellevi): Benchmarks have shown that running a unary-stream RPC - # on a single Python thread results in an appreciable speed-up. However, - # due to slight differences in capability, the multi-threaded variant - # remains the default. - if self._single_threaded_unary_stream: - return _SingleThreadedUnaryStreamMultiCallable( - self._channel, _common.encode(method), request_serializer, - response_deserializer) - else: + # NOTE(rbellevi): Benchmarks have shown that running a unary-stream RPC + # on a single Python thread results in an appreciable speed-up. However, + # due to slight differences in capability, the multi-threaded variant + # remains the default. + if self._single_threaded_unary_stream: + return _SingleThreadedUnaryStreamMultiCallable( + self._channel, _common.encode(method), request_serializer, + response_deserializer) + else: return _UnaryStreamMultiCallable( self._channel, _channel_managed_call_management(self._call_state), @@ -1514,19 +1514,19 @@ class Channel(grpc.Channel): self._channel, _channel_managed_call_management(self._call_state), _common.encode(method), request_serializer, response_deserializer) - def _unsubscribe_all(self): - state = self._connectivity_state - if state: - with state.lock: - del state.callbacks_and_connectivities[:] - + def _unsubscribe_all(self): + state = self._connectivity_state + if state: + with state.lock: + del state.callbacks_and_connectivities[:] + def _close(self): - self._unsubscribe_all() + self._unsubscribe_all() self._channel.close(cygrpc.StatusCode.cancelled, 'Channel closed!') - cygrpc.fork_unregister_channel(self) + cygrpc.fork_unregister_channel(self) def _close_on_fork(self): - self._unsubscribe_all() + self._unsubscribe_all() self._channel.close_on_fork(cygrpc.StatusCode.cancelled, 'Channel closed due to fork') @@ -1550,9 +1550,9 @@ class Channel(grpc.Channel): # for as long as they are in use and to close them after using them, # then deletion of this grpc._channel.Channel instance can be made to # effect closure of the underlying cygrpc.Channel instance. - try: - self._unsubscribe_all() - except: # pylint: disable=bare-except - # Exceptions in __del__ are ignored by Python anyway, but they can - # keep spamming logs. Just silence them. - pass + try: + self._unsubscribe_all() + except: # pylint: disable=bare-except + # Exceptions in __del__ are ignored by Python anyway, but they can + # keep spamming logs. Just silence them. + pass diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/_common.py b/contrib/libs/grpc/src/python/grpcio/grpc/_common.py index 128124c325..c18d2fca18 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/_common.py +++ b/contrib/libs/grpc/src/python/grpcio/grpc/_common.py @@ -14,7 +14,7 @@ """Shared implementation.""" import logging -import time +import time import six import grpc @@ -59,11 +59,11 @@ STATUS_CODE_TO_CYGRPC_STATUS_CODE = { CYGRPC_STATUS_CODE_TO_STATUS_CODE) } -MAXIMUM_WAIT_TIMEOUT = 0.1 +MAXIMUM_WAIT_TIMEOUT = 0.1 _ERROR_MESSAGE_PORT_BINDING_FAILED = 'Failed to bind to address %s; set ' \ 'GRPC_VERBOSITY=debug environment variable to see detailed error message.' - + def encode(s): if isinstance(s, bytes): @@ -100,53 +100,53 @@ def deserialize(serialized_message, deserializer): def fully_qualified_method(group, method): return '/{}/{}'.format(group, method) - - -def _wait_once(wait_fn, timeout, spin_cb): - wait_fn(timeout=timeout) - if spin_cb is not None: - spin_cb() - - -def wait(wait_fn, wait_complete_fn, timeout=None, spin_cb=None): - """Blocks waiting for an event without blocking the thread indefinitely. - - See https://github.com/grpc/grpc/issues/19464 for full context. CPython's - `threading.Event.wait` and `threading.Condition.wait` methods, if invoked - without a timeout kwarg, may block the calling thread indefinitely. If the - call is made from the main thread, this means that signal handlers may not - run for an arbitrarily long period of time. - - This wrapper calls the supplied wait function with an arbitrary short - timeout to ensure that no signal handler has to wait longer than - MAXIMUM_WAIT_TIMEOUT before executing. - - Args: - wait_fn: A callable acceptable a single float-valued kwarg named - `timeout`. This function is expected to be one of `threading.Event.wait` - or `threading.Condition.wait`. - wait_complete_fn: A callable taking no arguments and returning a bool. - When this function returns true, it indicates that waiting should cease. - timeout: An optional float-valued number of seconds after which the wait - should cease. - spin_cb: An optional Callable taking no arguments and returning nothing. - This callback will be called on each iteration of the spin. This may be - used for, e.g. work related to forking. - - Returns: - True if a timeout was supplied and it was reached. False otherwise. - """ - if timeout is None: - while not wait_complete_fn(): - _wait_once(wait_fn, MAXIMUM_WAIT_TIMEOUT, spin_cb) - else: - end = time.time() + timeout - while not wait_complete_fn(): - remaining = min(end - time.time(), MAXIMUM_WAIT_TIMEOUT) - if remaining < 0: - return True - _wait_once(wait_fn, remaining, spin_cb) - return False + + +def _wait_once(wait_fn, timeout, spin_cb): + wait_fn(timeout=timeout) + if spin_cb is not None: + spin_cb() + + +def wait(wait_fn, wait_complete_fn, timeout=None, spin_cb=None): + """Blocks waiting for an event without blocking the thread indefinitely. + + See https://github.com/grpc/grpc/issues/19464 for full context. CPython's + `threading.Event.wait` and `threading.Condition.wait` methods, if invoked + without a timeout kwarg, may block the calling thread indefinitely. If the + call is made from the main thread, this means that signal handlers may not + run for an arbitrarily long period of time. + + This wrapper calls the supplied wait function with an arbitrary short + timeout to ensure that no signal handler has to wait longer than + MAXIMUM_WAIT_TIMEOUT before executing. + + Args: + wait_fn: A callable acceptable a single float-valued kwarg named + `timeout`. This function is expected to be one of `threading.Event.wait` + or `threading.Condition.wait`. + wait_complete_fn: A callable taking no arguments and returning a bool. + When this function returns true, it indicates that waiting should cease. + timeout: An optional float-valued number of seconds after which the wait + should cease. + spin_cb: An optional Callable taking no arguments and returning nothing. + This callback will be called on each iteration of the spin. This may be + used for, e.g. work related to forking. + + Returns: + True if a timeout was supplied and it was reached. False otherwise. + """ + if timeout is None: + while not wait_complete_fn(): + _wait_once(wait_fn, MAXIMUM_WAIT_TIMEOUT, spin_cb) + else: + end = time.time() + timeout + while not wait_complete_fn(): + remaining = min(end - time.time(), MAXIMUM_WAIT_TIMEOUT) + if remaining < 0: + return True + _wait_once(wait_fn, remaining, spin_cb) + return False def validate_port_binding_result(address, port): diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/_compression.py b/contrib/libs/grpc/src/python/grpcio/grpc/_compression.py index 45339c3afe..18da583271 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/_compression.py +++ b/contrib/libs/grpc/src/python/grpcio/grpc/_compression.py @@ -1,55 +1,55 @@ -# Copyright 2019 The gRPC authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from grpc._cython import cygrpc - -NoCompression = cygrpc.CompressionAlgorithm.none -Deflate = cygrpc.CompressionAlgorithm.deflate -Gzip = cygrpc.CompressionAlgorithm.gzip - -_METADATA_STRING_MAPPING = { - NoCompression: 'identity', - Deflate: 'deflate', - Gzip: 'gzip', -} - - -def _compression_algorithm_to_metadata_value(compression): - return _METADATA_STRING_MAPPING[compression] - - -def compression_algorithm_to_metadata(compression): - return (cygrpc.GRPC_COMPRESSION_REQUEST_ALGORITHM_MD_KEY, - _compression_algorithm_to_metadata_value(compression)) - - -def create_channel_option(compression): - return ((cygrpc.GRPC_COMPRESSION_CHANNEL_DEFAULT_ALGORITHM, - int(compression)),) if compression else () - - -def augment_metadata(metadata, compression): - if not metadata and not compression: - return None - base_metadata = tuple(metadata) if metadata else () - compression_metadata = ( - compression_algorithm_to_metadata(compression),) if compression else () - return base_metadata + compression_metadata - - -__all__ = ( - "NoCompression", - "Deflate", - "Gzip", -) +# Copyright 2019 The gRPC authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from grpc._cython import cygrpc + +NoCompression = cygrpc.CompressionAlgorithm.none +Deflate = cygrpc.CompressionAlgorithm.deflate +Gzip = cygrpc.CompressionAlgorithm.gzip + +_METADATA_STRING_MAPPING = { + NoCompression: 'identity', + Deflate: 'deflate', + Gzip: 'gzip', +} + + +def _compression_algorithm_to_metadata_value(compression): + return _METADATA_STRING_MAPPING[compression] + + +def compression_algorithm_to_metadata(compression): + return (cygrpc.GRPC_COMPRESSION_REQUEST_ALGORITHM_MD_KEY, + _compression_algorithm_to_metadata_value(compression)) + + +def create_channel_option(compression): + return ((cygrpc.GRPC_COMPRESSION_CHANNEL_DEFAULT_ALGORITHM, + int(compression)),) if compression else () + + +def augment_metadata(metadata, compression): + if not metadata and not compression: + return None + base_metadata = tuple(metadata) if metadata else () + compression_metadata = ( + compression_algorithm_to_metadata(compression),) if compression else () + return base_metadata + compression_metadata + + +__all__ = ( + "NoCompression", + "Deflate", + "Gzip", +) diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/_hooks.pyx.pxi b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/_hooks.pyx.pxi index de4d71b819..da5317830a 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/_hooks.pyx.pxi +++ b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/_hooks.pyx.pxi @@ -16,7 +16,7 @@ cdef object _custom_op_on_c_call(int op, grpc_call *call): raise NotImplementedError("No custom hooks are implemented") -def install_context_from_request_call_event(RequestCallEvent event): +def install_context_from_request_call_event(RequestCallEvent event): pass def uninstall_context(): @@ -30,6 +30,6 @@ cdef class CensusContext: def set_census_context_on_call(_CallState call_state, CensusContext census_ctx): pass - -def get_deadline_from_context(): - return None + +def get_deadline_from_context(): + return None diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/call.pxd.pxi b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/call.pxd.pxi index 867245a694..7e7f554672 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/call.pxd.pxi +++ b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/call.pxd.pxi @@ -1,29 +1,29 @@ -# Copyright 2019 gRPC authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - +# Copyright 2019 gRPC authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + cdef class _AioCall(GrpcCallWrapper): - cdef: + cdef: readonly AioChannel _channel - list _references + list _references object _deadline list _done_callbacks # Caches the picked event loop, so we can avoid the 30ns overhead each # time we need access to the event loop. object _loop - + # Flag indicates whether cancel being called or not. Cancellation from # Core or peer works perfectly fine with normal procedure. However, we # need this flag to clean up resources for cancellation from the diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/call.pyx.pxi b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/call.pyx.pxi index 10c024e1b3..5b6edf35cf 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/call.pyx.pxi +++ b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/call.pyx.pxi @@ -1,34 +1,34 @@ -# Copyright 2019 gRPC authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -_EMPTY_FLAGS = 0 -_EMPTY_MASK = 0 +# Copyright 2019 gRPC authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +_EMPTY_FLAGS = 0 +_EMPTY_MASK = 0 _IMMUTABLE_EMPTY_METADATA = tuple() - + _UNKNOWN_CANCELLATION_DETAILS = 'RPC cancelled for unknown reason.' _OK_CALL_REPRESENTATION = ('<{} of RPC that terminated with:\n' '\tstatus = {}\n' '\tdetails = "{}"\n' '>') - + _NON_OK_CALL_REPRESENTATION = ('<{} of RPC that terminated with:\n' '\tstatus = {}\n' '\tdetails = "{}"\n' '\tdebug_error_string = "{}"\n' '>') - + cdef int _get_send_initial_metadata_flags(object wait_for_ready) except *: cdef int flags = 0 @@ -48,9 +48,9 @@ cdef class _AioCall(GrpcCallWrapper): bytes method, CallCredentials call_credentials, object wait_for_ready): init_grpc_aio() self.call = NULL - self._channel = channel + self._channel = channel self._loop = channel.loop - self._references = [] + self._references = [] self._status = None self._initial_metadata = None self._waiters_status = [] @@ -60,7 +60,7 @@ cdef class _AioCall(GrpcCallWrapper): self._deadline = deadline self._send_initial_metadata_flags = _get_send_initial_metadata_flags(wait_for_ready) self._create_grpc_call(deadline, method, call_credentials) - + def __dealloc__(self): if self.call: grpc_call_unref(self.call) @@ -71,7 +71,7 @@ cdef class _AioCall(GrpcCallWrapper): # This needs to be loaded at run time once everything # has been loaded. from grpc import _common - + if not self.done(): return '<{} object>'.format(self.__class__.__name__) @@ -97,40 +97,40 @@ cdef class _AioCall(GrpcCallWrapper): object deadline, bytes method, CallCredentials credentials) except *: - """Creates the corresponding Core object for this RPC. - + """Creates the corresponding Core object for this RPC. + For unary calls, the grpc_call lives shortly and can be destroyed after - invoke start_batch. However, if either side is streaming, the grpc_call - life span will be longer than one function. So, it would better save it - as an instance variable than a stack variable, which reflects its - nature in Core. - """ - cdef grpc_slice method_slice + invoke start_batch. However, if either side is streaming, the grpc_call + life span will be longer than one function. So, it would better save it + as an instance variable than a stack variable, which reflects its + nature in Core. + """ + cdef grpc_slice method_slice cdef gpr_timespec c_deadline = _timespec_from_time(deadline) cdef grpc_call_error set_credentials_error - - method_slice = grpc_slice_from_copied_buffer( - <const char *> method, - <size_t> len(method) - ) + + method_slice = grpc_slice_from_copied_buffer( + <const char *> method, + <size_t> len(method) + ) self.call = grpc_channel_create_call( - self._channel.channel, - NULL, - _EMPTY_MASK, + self._channel.channel, + NULL, + _EMPTY_MASK, global_completion_queue(), - method_slice, - NULL, + method_slice, + NULL, c_deadline, - NULL - ) + NULL + ) if credentials is not None: set_credentials_error = grpc_call_set_credentials(self.call, credentials.c()) if set_credentials_error != GRPC_CALL_OK: raise InternalError("Credentials couldn't have been set: {0}".format(set_credentials_error)) - grpc_slice_unref(method_slice) - + grpc_slice_unref(method_slice) + cdef void _set_status(self, AioRpcStatus status) except *: cdef list waiters @@ -177,7 +177,7 @@ cdef class _AioCall(GrpcCallWrapper): return None else: return max(0, self._deadline - time.time()) - + def cancel(self, str details): """Cancels the RPC in Core with given RPC status. @@ -185,11 +185,11 @@ cdef class _AioCall(GrpcCallWrapper): proper state. """ self._is_locally_cancelled = True - + cdef object details_bytes cdef char *c_details cdef grpc_call_error error - + self._set_status(AioRpcStatus( StatusCode.cancelled, details, @@ -294,7 +294,7 @@ cdef class _AioCall(GrpcCallWrapper): outbound_initial_metadata: optional outbound metadata. """ cdef tuple ops - + cdef SendInitialMetadataOperation initial_metadata_op = SendInitialMetadataOperation( outbound_initial_metadata, self._send_initial_metadata_flags) @@ -303,19 +303,19 @@ cdef class _AioCall(GrpcCallWrapper): cdef ReceiveInitialMetadataOperation receive_initial_metadata_op = ReceiveInitialMetadataOperation(_EMPTY_FLAGS) cdef ReceiveMessageOperation receive_message_op = ReceiveMessageOperation(_EMPTY_FLAGS) cdef ReceiveStatusOnClientOperation receive_status_on_client_op = ReceiveStatusOnClientOperation(_EMPTY_FLAGS) - + ops = (initial_metadata_op, send_message_op, send_close_op, receive_initial_metadata_op, receive_message_op, receive_status_on_client_op) - + # Executes all operations in one batch. # Might raise CancelledError, handling it in Python UnaryUnaryCall. await execute_batch(self, ops, self._loop) - + self._set_initial_metadata(receive_initial_metadata_op.initial_metadata()) - + cdef grpc_status_code code code = receive_status_on_client_op.code() @@ -325,12 +325,12 @@ cdef class _AioCall(GrpcCallWrapper): receive_status_on_client_op.trailing_metadata(), receive_status_on_client_op.error_string(), )) - + if code == StatusCode.ok: return receive_message_op.message() else: return None - + async def _handle_status_once_received(self): """Handles the status sent by peer once received.""" cdef ReceiveStatusOnClientOperation op = ReceiveStatusOnClientOperation(_EMPTY_FLAGS) @@ -347,11 +347,11 @@ cdef class _AioCall(GrpcCallWrapper): op.trailing_metadata(), op.error_string(), )) - + async def receive_serialized_message(self): """Receives one single raw message in bytes.""" cdef bytes received_message - + # Receives a message. Returns None when failed: # * EOF, no more messages to read; # * The client application cancels; @@ -364,7 +364,7 @@ cdef class _AioCall(GrpcCallWrapper): return received_message else: return EOF - + async def send_serialized_message(self, bytes message): """Sends one single raw message in bytes.""" await _send_message(self, @@ -372,7 +372,7 @@ cdef class _AioCall(GrpcCallWrapper): None, False, self._loop) - + async def send_receive_close(self): """Half close the RPC on the client-side.""" cdef SendCloseFromClientOperation op = SendCloseFromClientOperation(_EMPTY_FLAGS) @@ -401,7 +401,7 @@ cdef class _AioCall(GrpcCallWrapper): initial_metadata_op, send_message_op, send_close_op, - ) + ) try: # Sends out the request message. diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/callback_common.pxd.pxi b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/callback_common.pxd.pxi index e5620cd166..44276bbad3 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/callback_common.pxd.pxi +++ b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/callback_common.pxd.pxi @@ -1,57 +1,57 @@ -# Copyright 2019 gRPC authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -cdef class CallbackFailureHandler: - cdef str _core_function_name - cdef object _error_details - cdef object _exception_type - - cdef handle(self, object future) - - -cdef struct CallbackContext: - # C struct to store callback context in the form of pointers. - # - # Attributes: - # functor: A grpc_experimental_completion_queue_functor represents the +# Copyright 2019 gRPC authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +cdef class CallbackFailureHandler: + cdef str _core_function_name + cdef object _error_details + cdef object _exception_type + + cdef handle(self, object future) + + +cdef struct CallbackContext: + # C struct to store callback context in the form of pointers. + # + # Attributes: + # functor: A grpc_experimental_completion_queue_functor represents the # callback function in the only way Core understands. - # waiter: An asyncio.Future object that fulfills when the callback is + # waiter: An asyncio.Future object that fulfills when the callback is # invoked by Core. # failure_handler: A CallbackFailureHandler object that called when Core - # returns 'success == 0' state. + # returns 'success == 0' state. # wrapper: A self-reference to the CallbackWrapper to help life cycle # management. - grpc_experimental_completion_queue_functor functor - cpython.PyObject *waiter + grpc_experimental_completion_queue_functor functor + cpython.PyObject *waiter cpython.PyObject *loop - cpython.PyObject *failure_handler + cpython.PyObject *failure_handler cpython.PyObject *callback_wrapper - - -cdef class CallbackWrapper: - cdef CallbackContext context - cdef object _reference_of_future - cdef object _reference_of_failure_handler - - @staticmethod - cdef void functor_run( - grpc_experimental_completion_queue_functor* functor, - int succeed) - - cdef grpc_experimental_completion_queue_functor *c_functor(self) - - -cdef class GrpcCallWrapper: - cdef grpc_call* call + + +cdef class CallbackWrapper: + cdef CallbackContext context + cdef object _reference_of_future + cdef object _reference_of_failure_handler + + @staticmethod + cdef void functor_run( + grpc_experimental_completion_queue_functor* functor, + int succeed) + + cdef grpc_experimental_completion_queue_functor *c_functor(self) + + +cdef class GrpcCallWrapper: + cdef grpc_call* call diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/callback_common.pyx.pxi b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/callback_common.pyx.pxi index 86fc91e76a..00a05448ab 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/callback_common.pyx.pxi +++ b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/callback_common.pyx.pxi @@ -1,57 +1,57 @@ -# Copyright 2019 gRPC authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -cdef class CallbackFailureHandler: - - def __cinit__(self, - str core_function_name, - object error_details, - object exception_type): - """Handles failure by raising exception.""" - self._core_function_name = core_function_name - self._error_details = error_details - self._exception_type = exception_type - - cdef handle(self, object future): - future.set_exception(self._exception_type( - 'Failed "%s": %s' % (self._core_function_name, self._error_details) - )) - - -cdef class CallbackWrapper: - +# Copyright 2019 gRPC authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +cdef class CallbackFailureHandler: + + def __cinit__(self, + str core_function_name, + object error_details, + object exception_type): + """Handles failure by raising exception.""" + self._core_function_name = core_function_name + self._error_details = error_details + self._exception_type = exception_type + + cdef handle(self, object future): + future.set_exception(self._exception_type( + 'Failed "%s": %s' % (self._core_function_name, self._error_details) + )) + + +cdef class CallbackWrapper: + def __cinit__(self, object future, object loop, CallbackFailureHandler failure_handler): - self.context.functor.functor_run = self.functor_run - self.context.waiter = <cpython.PyObject*>future + self.context.functor.functor_run = self.functor_run + self.context.waiter = <cpython.PyObject*>future self.context.loop = <cpython.PyObject*>loop - self.context.failure_handler = <cpython.PyObject*>failure_handler + self.context.failure_handler = <cpython.PyObject*>failure_handler self.context.callback_wrapper = <cpython.PyObject*>self - # NOTE(lidiz) Not using a list here, because this class is critical in - # data path. We should make it as efficient as possible. - self._reference_of_future = future - self._reference_of_failure_handler = failure_handler + # NOTE(lidiz) Not using a list here, because this class is critical in + # data path. We should make it as efficient as possible. + self._reference_of_future = future + self._reference_of_failure_handler = failure_handler # NOTE(lidiz) We need to ensure when Core invokes our callback, the # callback function itself is not deallocated. Othersise, we will get # a segfault. We can view this as Core holding a ref. cpython.Py_INCREF(self) - - @staticmethod - cdef void functor_run( - grpc_experimental_completion_queue_functor* functor, - int success): - cdef CallbackContext *context = <CallbackContext *>functor + + @staticmethod + cdef void functor_run( + grpc_experimental_completion_queue_functor* functor, + int success): + cdef CallbackContext *context = <CallbackContext *>functor cdef object waiter = <object>context.waiter if not waiter.cancelled(): if success == 0: @@ -59,47 +59,47 @@ cdef class CallbackWrapper: else: waiter.set_result(None) cpython.Py_DECREF(<object>context.callback_wrapper) - - cdef grpc_experimental_completion_queue_functor *c_functor(self): - return &self.context.functor - - -cdef CallbackFailureHandler CQ_SHUTDOWN_FAILURE_HANDLER = CallbackFailureHandler( - 'grpc_completion_queue_shutdown', - 'Unknown', + + cdef grpc_experimental_completion_queue_functor *c_functor(self): + return &self.context.functor + + +cdef CallbackFailureHandler CQ_SHUTDOWN_FAILURE_HANDLER = CallbackFailureHandler( + 'grpc_completion_queue_shutdown', + 'Unknown', InternalError) - - + + class ExecuteBatchError(InternalError): """Raised when execute batch returns a failure from Core.""" - - + + async def execute_batch(GrpcCallWrapper grpc_call_wrapper, - tuple operations, - object loop): - """The callback version of start batch operations.""" - cdef _BatchOperationTag batch_operation_tag = _BatchOperationTag(None, operations, None) - batch_operation_tag.prepare() - - cdef object future = loop.create_future() - cdef CallbackWrapper wrapper = CallbackWrapper( - future, + tuple operations, + object loop): + """The callback version of start batch operations.""" + cdef _BatchOperationTag batch_operation_tag = _BatchOperationTag(None, operations, None) + batch_operation_tag.prepare() + + cdef object future = loop.create_future() + cdef CallbackWrapper wrapper = CallbackWrapper( + future, loop, CallbackFailureHandler('execute_batch', operations, ExecuteBatchError)) - cdef grpc_call_error error = grpc_call_start_batch( - grpc_call_wrapper.call, - batch_operation_tag.c_ops, - batch_operation_tag.c_nops, - wrapper.c_functor(), NULL) - - if error != GRPC_CALL_OK: + cdef grpc_call_error error = grpc_call_start_batch( + grpc_call_wrapper.call, + batch_operation_tag.c_ops, + batch_operation_tag.c_nops, + wrapper.c_functor(), NULL) + + if error != GRPC_CALL_OK: raise ExecuteBatchError("Failed grpc_call_start_batch: {}".format(error)) + + await future - await future - - cdef grpc_event c_event - # Tag.event must be called, otherwise messages won't be parsed from C - batch_operation_tag.event(c_event) + cdef grpc_event c_event + # Tag.event must be called, otherwise messages won't be parsed from C + batch_operation_tag.event(c_event) cdef prepend_send_initial_metadata_op(tuple ops, tuple metadata): diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/channel.pxd.pxi b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/channel.pxd.pxi index 03b4990e48..d25de9a741 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/channel.pxd.pxi +++ b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/channel.pxd.pxi @@ -1,27 +1,27 @@ -# Copyright 2019 gRPC authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - +# Copyright 2019 gRPC authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + cdef enum AioChannelStatus: AIO_CHANNEL_STATUS_UNKNOWN AIO_CHANNEL_STATUS_READY AIO_CHANNEL_STATUS_CLOSING AIO_CHANNEL_STATUS_DESTROYED -cdef class AioChannel: - cdef: - grpc_channel * channel +cdef class AioChannel: + cdef: + grpc_channel * channel object loop - bytes _target + bytes _target AioChannelStatus _status bint _is_secure diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/channel.pyx.pxi b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/channel.pyx.pxi index beadce67b4..45cdc5171c 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/channel.pyx.pxi +++ b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/channel.pyx.pxi @@ -1,18 +1,18 @@ -# Copyright 2019 gRPC authors. +# Copyright 2019 gRPC authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. # -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - + class _WatchConnectivityFailed(Exception): """Dedicated exception class for watch connectivity failed. @@ -25,7 +25,7 @@ cdef CallbackFailureHandler _WATCH_CONNECTIVITY_FAILURE_HANDLER = CallbackFailur _WatchConnectivityFailed) -cdef class AioChannel: +cdef class AioChannel: def __cinit__(self, bytes target, tuple options, ChannelCredentials credentials, object loop): init_grpc_aio() if options is None: @@ -34,7 +34,7 @@ cdef class AioChannel: self._target = target self.loop = loop self._status = AIO_CHANNEL_STATUS_READY - + if credentials is None: self._is_secure = False self.channel = grpc_insecure_channel_create( @@ -52,11 +52,11 @@ cdef class AioChannel: def __dealloc__(self): shutdown_grpc_aio() - def __repr__(self): - class_name = self.__class__.__name__ - id_ = id(self) - return f"<{class_name} {id_}>" - + def __repr__(self): + class_name = self.__class__.__name__ + id_ = id(self) + return f"<{class_name} {id_}>" + def check_connectivity_state(self, bint try_to_connect): """A Cython wrapper for Core's check connectivity state API.""" if self._status == AIO_CHANNEL_STATUS_DESTROYED: @@ -102,10 +102,10 @@ cdef class AioChannel: def closing(self): self._status = AIO_CHANNEL_STATUS_CLOSING - def close(self): + def close(self): self._status = AIO_CHANNEL_STATUS_DESTROYED - grpc_channel_destroy(self.channel) - + grpc_channel_destroy(self.channel) + def closed(self): return self._status in (AIO_CHANNEL_STATUS_CLOSING, AIO_CHANNEL_STATUS_DESTROYED) diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/grpc_aio.pxd.pxi b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/grpc_aio.pxd.pxi index ebf0660174..d2941b6044 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/grpc_aio.pxd.pxi +++ b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/grpc_aio.pxd.pxi @@ -1,18 +1,18 @@ -# Copyright 2019 gRPC authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# distutils: language=c++ - +# Copyright 2019 gRPC authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# distutils: language=c++ + cdef class _AioState: cdef object lock # threading.RLock cdef int refcount @@ -29,15 +29,15 @@ cpdef init_grpc_aio() cpdef shutdown_grpc_aio() -cdef extern from "src/core/lib/iomgr/timer_manager.h": +cdef extern from "src/core/lib/iomgr/timer_manager.h": void grpc_timer_manager_set_threading(bint enabled) + - -cdef extern from "src/core/lib/iomgr/iomgr_internal.h": +cdef extern from "src/core/lib/iomgr/iomgr_internal.h": void grpc_set_default_iomgr_platform() + - -cdef extern from "src/core/lib/iomgr/executor.h" namespace "grpc_core": - cdef cppclass Executor: - @staticmethod +cdef extern from "src/core/lib/iomgr/executor.h" namespace "grpc_core": + cdef cppclass Executor: + @staticmethod void SetThreadingAll(bint enable) diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/grpc_aio.pyx.pxi b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/grpc_aio.pyx.pxi index 06c92cac58..ea9b7b9a0e 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/grpc_aio.pyx.pxi +++ b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/grpc_aio.pyx.pxi @@ -1,28 +1,28 @@ -# Copyright 2019 gRPC authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - +# Copyright 2019 gRPC authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + import enum - + cdef str _GRPC_ASYNCIO_ENGINE = os.environ.get('GRPC_ASYNCIO_ENGINE', 'poller').upper() cdef _AioState _global_aio_state = _AioState() - - + + class AsyncIOEngine(enum.Enum): CUSTOM_IO_MANAGER = 'custom_io_manager' POLLER = 'poller' - - + + cdef _default_asyncio_engine(): return AsyncIOEngine.POLLER @@ -45,20 +45,20 @@ cdef _initialize_custom_io_manager(): # NOTE(lidiz) Custom IO manager must be activated before the first # `grpc_init()`. Otherwise, some special configurations in Core won't # pick up the change, and resulted in SEGFAULT or ABORT. - install_asyncio_iomgr() + install_asyncio_iomgr() # Initializes gRPC Core, must be called before other Core API - grpc_init() - - # Timers are triggered by the Asyncio loop. We disable - # the background thread that is being used by the native - # gRPC iomgr. + grpc_init() + + # Timers are triggered by the Asyncio loop. We disable + # the background thread that is being used by the native + # gRPC iomgr. grpc_timer_manager_set_threading(False) - - # gRPC callbaks are executed within the same thread used by the Asyncio - # event loop, as it is being done by the other Asyncio callbacks. + + # gRPC callbaks are executed within the same thread used by the Asyncio + # event loop, as it is being done by the other Asyncio callbacks. Executor.SetThreadingAll(False) - + # Creates the only completion queue _global_aio_state.cq = CallbackCompletionQueue() diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/iomgr/iomgr.pyx.pxi b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/iomgr/iomgr.pyx.pxi index 917ae24e11..c3b1e2fe75 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/iomgr/iomgr.pyx.pxi +++ b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/iomgr/iomgr.pyx.pxi @@ -1,217 +1,217 @@ -# Copyright 2019 gRPC authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - +# Copyright 2019 gRPC authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + import platform -from cpython cimport Py_INCREF, Py_DECREF -from libc cimport string - -import socket as native_socket -try: - import ipaddress # CPython 3.3 and above -except ImportError: - pass - -cdef grpc_socket_vtable asyncio_socket_vtable -cdef grpc_custom_resolver_vtable asyncio_resolver_vtable -cdef grpc_custom_timer_vtable asyncio_timer_vtable -cdef grpc_custom_poller_vtable asyncio_pollset_vtable +from cpython cimport Py_INCREF, Py_DECREF +from libc cimport string + +import socket as native_socket +try: + import ipaddress # CPython 3.3 and above +except ImportError: + pass + +cdef grpc_socket_vtable asyncio_socket_vtable +cdef grpc_custom_resolver_vtable asyncio_resolver_vtable +cdef grpc_custom_timer_vtable asyncio_timer_vtable +cdef grpc_custom_poller_vtable asyncio_pollset_vtable cdef bint so_reuse_port - - -cdef grpc_error* asyncio_socket_init( - grpc_custom_socket* grpc_socket, - int domain) with gil: - socket = _AsyncioSocket.create(grpc_socket, None, None) - Py_INCREF(socket) - grpc_socket.impl = <void*>socket - return <grpc_error*>0 - - -cdef void asyncio_socket_destroy(grpc_custom_socket* grpc_socket) with gil: - Py_DECREF(<_AsyncioSocket>grpc_socket.impl) - - -cdef void asyncio_socket_connect( - grpc_custom_socket* grpc_socket, - const grpc_sockaddr* addr, - size_t addr_len, - grpc_custom_connect_callback connect_cb) with gil: - host, port = sockaddr_to_tuple(addr, addr_len) - socket = <_AsyncioSocket>grpc_socket.impl - socket.connect(host, port, connect_cb) - - -cdef void asyncio_socket_close( - grpc_custom_socket* grpc_socket, - grpc_custom_close_callback close_cb) with gil: - socket = (<_AsyncioSocket>grpc_socket.impl) - socket.close() - close_cb(grpc_socket) - - -cdef void asyncio_socket_shutdown(grpc_custom_socket* grpc_socket) with gil: - socket = (<_AsyncioSocket>grpc_socket.impl) - socket.close() - - -cdef void asyncio_socket_write( - grpc_custom_socket* grpc_socket, - grpc_slice_buffer* slice_buffer, - grpc_custom_write_callback write_cb) with gil: - socket = (<_AsyncioSocket>grpc_socket.impl) - socket.write(slice_buffer, write_cb) - - -cdef void asyncio_socket_read( - grpc_custom_socket* grpc_socket, - char* buffer_, - size_t length, - grpc_custom_read_callback read_cb) with gil: - socket = (<_AsyncioSocket>grpc_socket.impl) - socket.read(buffer_, length, read_cb) - - -cdef grpc_error* asyncio_socket_getpeername( - grpc_custom_socket* grpc_socket, - const grpc_sockaddr* addr, - int* length) with gil: - peer = (<_AsyncioSocket>grpc_socket.impl).peername() - - cdef grpc_resolved_address c_addr - hostname = str_to_bytes(peer[0]) - grpc_string_to_sockaddr(&c_addr, hostname, peer[1]) - # TODO(https://github.com/grpc/grpc/issues/20684) Remove the memcpy - string.memcpy(<void*>addr, <void*>c_addr.addr, c_addr.len) - length[0] = c_addr.len - return grpc_error_none() - - -cdef grpc_error* asyncio_socket_getsockname( - grpc_custom_socket* grpc_socket, - const grpc_sockaddr* addr, - int* length) with gil: - """Supplies sock_addr in add_socket_to_server.""" - cdef grpc_resolved_address c_addr - socket = (<_AsyncioSocket>grpc_socket.impl) - if socket is None: - peer = ('0.0.0.0', 0) - else: - peer = socket.sockname() - hostname = str_to_bytes(peer[0]) - grpc_string_to_sockaddr(&c_addr, hostname, peer[1]) - # TODO(https://github.com/grpc/grpc/issues/20684) Remove the memcpy - string.memcpy(<void*>addr, <void*>c_addr.addr, c_addr.len) - length[0] = c_addr.len - return grpc_error_none() - - -cdef grpc_error* asyncio_socket_listen(grpc_custom_socket* grpc_socket) with gil: - (<_AsyncioSocket>grpc_socket.impl).listen() - return grpc_error_none() - - + + +cdef grpc_error* asyncio_socket_init( + grpc_custom_socket* grpc_socket, + int domain) with gil: + socket = _AsyncioSocket.create(grpc_socket, None, None) + Py_INCREF(socket) + grpc_socket.impl = <void*>socket + return <grpc_error*>0 + + +cdef void asyncio_socket_destroy(grpc_custom_socket* grpc_socket) with gil: + Py_DECREF(<_AsyncioSocket>grpc_socket.impl) + + +cdef void asyncio_socket_connect( + grpc_custom_socket* grpc_socket, + const grpc_sockaddr* addr, + size_t addr_len, + grpc_custom_connect_callback connect_cb) with gil: + host, port = sockaddr_to_tuple(addr, addr_len) + socket = <_AsyncioSocket>grpc_socket.impl + socket.connect(host, port, connect_cb) + + +cdef void asyncio_socket_close( + grpc_custom_socket* grpc_socket, + grpc_custom_close_callback close_cb) with gil: + socket = (<_AsyncioSocket>grpc_socket.impl) + socket.close() + close_cb(grpc_socket) + + +cdef void asyncio_socket_shutdown(grpc_custom_socket* grpc_socket) with gil: + socket = (<_AsyncioSocket>grpc_socket.impl) + socket.close() + + +cdef void asyncio_socket_write( + grpc_custom_socket* grpc_socket, + grpc_slice_buffer* slice_buffer, + grpc_custom_write_callback write_cb) with gil: + socket = (<_AsyncioSocket>grpc_socket.impl) + socket.write(slice_buffer, write_cb) + + +cdef void asyncio_socket_read( + grpc_custom_socket* grpc_socket, + char* buffer_, + size_t length, + grpc_custom_read_callback read_cb) with gil: + socket = (<_AsyncioSocket>grpc_socket.impl) + socket.read(buffer_, length, read_cb) + + +cdef grpc_error* asyncio_socket_getpeername( + grpc_custom_socket* grpc_socket, + const grpc_sockaddr* addr, + int* length) with gil: + peer = (<_AsyncioSocket>grpc_socket.impl).peername() + + cdef grpc_resolved_address c_addr + hostname = str_to_bytes(peer[0]) + grpc_string_to_sockaddr(&c_addr, hostname, peer[1]) + # TODO(https://github.com/grpc/grpc/issues/20684) Remove the memcpy + string.memcpy(<void*>addr, <void*>c_addr.addr, c_addr.len) + length[0] = c_addr.len + return grpc_error_none() + + +cdef grpc_error* asyncio_socket_getsockname( + grpc_custom_socket* grpc_socket, + const grpc_sockaddr* addr, + int* length) with gil: + """Supplies sock_addr in add_socket_to_server.""" + cdef grpc_resolved_address c_addr + socket = (<_AsyncioSocket>grpc_socket.impl) + if socket is None: + peer = ('0.0.0.0', 0) + else: + peer = socket.sockname() + hostname = str_to_bytes(peer[0]) + grpc_string_to_sockaddr(&c_addr, hostname, peer[1]) + # TODO(https://github.com/grpc/grpc/issues/20684) Remove the memcpy + string.memcpy(<void*>addr, <void*>c_addr.addr, c_addr.len) + length[0] = c_addr.len + return grpc_error_none() + + +cdef grpc_error* asyncio_socket_listen(grpc_custom_socket* grpc_socket) with gil: + (<_AsyncioSocket>grpc_socket.impl).listen() + return grpc_error_none() + + def _asyncio_apply_socket_options(object s, int flags): # Turn SO_REUSEADDR on for TCP sockets; if we want to support UDS, we will # need to update this function. - s.setsockopt(native_socket.SOL_SOCKET, native_socket.SO_REUSEADDR, 1) + s.setsockopt(native_socket.SOL_SOCKET, native_socket.SO_REUSEADDR, 1) # SO_REUSEPORT only available in POSIX systems. if platform.system() != 'Windows': if GRPC_CUSTOM_SOCKET_OPT_SO_REUSEPORT & flags: s.setsockopt(native_socket.SOL_SOCKET, native_socket.SO_REUSEPORT, 1) - s.setsockopt(native_socket.IPPROTO_TCP, native_socket.TCP_NODELAY, True) - - -cdef grpc_error* asyncio_socket_bind( - grpc_custom_socket* grpc_socket, - const grpc_sockaddr* addr, - size_t len, int flags) with gil: - host, port = sockaddr_to_tuple(addr, len) - try: - ip = ipaddress.ip_address(host) - if isinstance(ip, ipaddress.IPv6Address): - family = native_socket.AF_INET6 - else: - family = native_socket.AF_INET - - socket = native_socket.socket(family=family) + s.setsockopt(native_socket.IPPROTO_TCP, native_socket.TCP_NODELAY, True) + + +cdef grpc_error* asyncio_socket_bind( + grpc_custom_socket* grpc_socket, + const grpc_sockaddr* addr, + size_t len, int flags) with gil: + host, port = sockaddr_to_tuple(addr, len) + try: + ip = ipaddress.ip_address(host) + if isinstance(ip, ipaddress.IPv6Address): + family = native_socket.AF_INET6 + else: + family = native_socket.AF_INET + + socket = native_socket.socket(family=family) _asyncio_apply_socket_options(socket, flags) - socket.bind((host, port)) - except IOError as io_error: + socket.bind((host, port)) + except IOError as io_error: socket.close() - return socket_error("bind", str(io_error)) - else: - aio_socket = _AsyncioSocket.create_with_py_socket(grpc_socket, socket) - cpython.Py_INCREF(aio_socket) # Py_DECREF in asyncio_socket_destroy - grpc_socket.impl = <void*>aio_socket - return grpc_error_none() - - -cdef void asyncio_socket_accept( - grpc_custom_socket* grpc_socket, - grpc_custom_socket* grpc_socket_client, - grpc_custom_accept_callback accept_cb) with gil: - (<_AsyncioSocket>grpc_socket.impl).accept(grpc_socket_client, accept_cb) - - -cdef grpc_error* asyncio_resolve( + return socket_error("bind", str(io_error)) + else: + aio_socket = _AsyncioSocket.create_with_py_socket(grpc_socket, socket) + cpython.Py_INCREF(aio_socket) # Py_DECREF in asyncio_socket_destroy + grpc_socket.impl = <void*>aio_socket + return grpc_error_none() + + +cdef void asyncio_socket_accept( + grpc_custom_socket* grpc_socket, + grpc_custom_socket* grpc_socket_client, + grpc_custom_accept_callback accept_cb) with gil: + (<_AsyncioSocket>grpc_socket.impl).accept(grpc_socket_client, accept_cb) + + +cdef grpc_error* asyncio_resolve( const char* host, const char* port, - grpc_resolved_addresses** res) with gil: - result = native_socket.getaddrinfo(host, port) - res[0] = tuples_to_resolvaddr(result) - - -cdef void asyncio_resolve_async( - grpc_custom_resolver* grpc_resolver, + grpc_resolved_addresses** res) with gil: + result = native_socket.getaddrinfo(host, port) + res[0] = tuples_to_resolvaddr(result) + + +cdef void asyncio_resolve_async( + grpc_custom_resolver* grpc_resolver, const char* host, const char* port) with gil: - resolver = _AsyncioResolver.create(grpc_resolver) - resolver.resolve(host, port) - - -cdef void asyncio_timer_start(grpc_custom_timer* grpc_timer) with gil: - timer = _AsyncioTimer.create(grpc_timer, grpc_timer.timeout_ms / 1000.0) - grpc_timer.timer = <void*>timer - - -cdef void asyncio_timer_stop(grpc_custom_timer* grpc_timer) with gil: + resolver = _AsyncioResolver.create(grpc_resolver) + resolver.resolve(host, port) + + +cdef void asyncio_timer_start(grpc_custom_timer* grpc_timer) with gil: + timer = _AsyncioTimer.create(grpc_timer, grpc_timer.timeout_ms / 1000.0) + grpc_timer.timer = <void*>timer + + +cdef void asyncio_timer_stop(grpc_custom_timer* grpc_timer) with gil: # TODO(https://github.com/grpc/grpc/issues/22278) remove this if condition if grpc_timer.timer == NULL: return else: timer = <_AsyncioTimer>grpc_timer.timer timer.stop() - - -cdef void asyncio_init_loop() with gil: - pass - - -cdef void asyncio_destroy_loop() with gil: - pass - - -cdef void asyncio_kick_loop() with gil: - pass - - -cdef void asyncio_run_loop(size_t timeout_ms) with gil: - pass - - + + +cdef void asyncio_init_loop() with gil: + pass + + +cdef void asyncio_destroy_loop() with gil: + pass + + +cdef void asyncio_kick_loop() with gil: + pass + + +cdef void asyncio_run_loop(size_t timeout_ms) with gil: + pass + + def _auth_plugin_callback_wrapper(object cb, str service_url, str method_name, @@ -219,38 +219,38 @@ def _auth_plugin_callback_wrapper(object cb, get_working_loop().call_soon(cb, service_url, method_name, callback) -def install_asyncio_iomgr(): +def install_asyncio_iomgr(): # Auth plugins invoke user provided logic in another thread by default. We # need to override that behavior by registering the call to the event loop. set_async_callback_func(_auth_plugin_callback_wrapper) - asyncio_resolver_vtable.resolve = asyncio_resolve - asyncio_resolver_vtable.resolve_async = asyncio_resolve_async - - asyncio_socket_vtable.init = asyncio_socket_init - asyncio_socket_vtable.connect = asyncio_socket_connect - asyncio_socket_vtable.destroy = asyncio_socket_destroy - asyncio_socket_vtable.shutdown = asyncio_socket_shutdown - asyncio_socket_vtable.close = asyncio_socket_close - asyncio_socket_vtable.write = asyncio_socket_write - asyncio_socket_vtable.read = asyncio_socket_read - asyncio_socket_vtable.getpeername = asyncio_socket_getpeername - asyncio_socket_vtable.getsockname = asyncio_socket_getsockname - asyncio_socket_vtable.bind = asyncio_socket_bind - asyncio_socket_vtable.listen = asyncio_socket_listen - asyncio_socket_vtable.accept = asyncio_socket_accept - - asyncio_timer_vtable.start = asyncio_timer_start - asyncio_timer_vtable.stop = asyncio_timer_stop - - asyncio_pollset_vtable.init = asyncio_init_loop - asyncio_pollset_vtable.poll = asyncio_run_loop - asyncio_pollset_vtable.kick = asyncio_kick_loop - asyncio_pollset_vtable.shutdown = asyncio_destroy_loop - - grpc_custom_iomgr_init( - &asyncio_socket_vtable, - &asyncio_resolver_vtable, - &asyncio_timer_vtable, - &asyncio_pollset_vtable - ) + asyncio_resolver_vtable.resolve = asyncio_resolve + asyncio_resolver_vtable.resolve_async = asyncio_resolve_async + + asyncio_socket_vtable.init = asyncio_socket_init + asyncio_socket_vtable.connect = asyncio_socket_connect + asyncio_socket_vtable.destroy = asyncio_socket_destroy + asyncio_socket_vtable.shutdown = asyncio_socket_shutdown + asyncio_socket_vtable.close = asyncio_socket_close + asyncio_socket_vtable.write = asyncio_socket_write + asyncio_socket_vtable.read = asyncio_socket_read + asyncio_socket_vtable.getpeername = asyncio_socket_getpeername + asyncio_socket_vtable.getsockname = asyncio_socket_getsockname + asyncio_socket_vtable.bind = asyncio_socket_bind + asyncio_socket_vtable.listen = asyncio_socket_listen + asyncio_socket_vtable.accept = asyncio_socket_accept + + asyncio_timer_vtable.start = asyncio_timer_start + asyncio_timer_vtable.stop = asyncio_timer_stop + + asyncio_pollset_vtable.init = asyncio_init_loop + asyncio_pollset_vtable.poll = asyncio_run_loop + asyncio_pollset_vtable.kick = asyncio_kick_loop + asyncio_pollset_vtable.shutdown = asyncio_destroy_loop + + grpc_custom_iomgr_init( + &asyncio_socket_vtable, + &asyncio_resolver_vtable, + &asyncio_timer_vtable, + &asyncio_pollset_vtable + ) diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/iomgr/resolver.pxd.pxi b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/iomgr/resolver.pxd.pxi index 51730c1597..61449745d0 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/iomgr/resolver.pxd.pxi +++ b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/iomgr/resolver.pxd.pxi @@ -1,24 +1,24 @@ -# Copyright 2019 gRPC authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -cdef class _AsyncioResolver: - cdef: +# Copyright 2019 gRPC authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +cdef class _AsyncioResolver: + cdef: object _loop - grpc_custom_resolver* _grpc_resolver - object _task_resolve - - @staticmethod - cdef _AsyncioResolver create(grpc_custom_resolver* grpc_resolver) - + grpc_custom_resolver* _grpc_resolver + object _task_resolve + + @staticmethod + cdef _AsyncioResolver create(grpc_custom_resolver* grpc_resolver) + cdef void resolve(self, const char* host, const char* port) diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/iomgr/resolver.pyx.pxi b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/iomgr/resolver.pyx.pxi index 1a2e244ff9..70f6a86026 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/iomgr/resolver.pyx.pxi +++ b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/iomgr/resolver.pyx.pxi @@ -1,56 +1,56 @@ -# Copyright 2019 gRPC authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -cdef class _AsyncioResolver: - def __cinit__(self): +# Copyright 2019 gRPC authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +cdef class _AsyncioResolver: + def __cinit__(self): self._loop = get_working_loop() - self._grpc_resolver = NULL - self._task_resolve = None - - @staticmethod - cdef _AsyncioResolver create(grpc_custom_resolver* grpc_resolver): - resolver = _AsyncioResolver() - resolver._grpc_resolver = grpc_resolver - return resolver - - def __repr__(self): - class_name = self.__class__.__name__ - id_ = id(self) - return f"<{class_name} {id_}>" - + self._grpc_resolver = NULL + self._task_resolve = None + + @staticmethod + cdef _AsyncioResolver create(grpc_custom_resolver* grpc_resolver): + resolver = _AsyncioResolver() + resolver._grpc_resolver = grpc_resolver + return resolver + + def __repr__(self): + class_name = self.__class__.__name__ + id_ = id(self) + return f"<{class_name} {id_}>" + async def _async_resolve(self, bytes host, bytes port): self._task_resolve = None - try: + try: resolved = await self._loop.getaddrinfo(host, port) - except Exception as e: - grpc_custom_resolve_callback( - <grpc_custom_resolver*>self._grpc_resolver, + except Exception as e: + grpc_custom_resolve_callback( + <grpc_custom_resolver*>self._grpc_resolver, NULL, grpc_socket_error("Resolve address [{}:{}] failed: {}: {}".format( host, port, type(e), str(e)).encode()) - ) - else: - grpc_custom_resolve_callback( - <grpc_custom_resolver*>self._grpc_resolver, + ) + else: + grpc_custom_resolve_callback( + <grpc_custom_resolver*>self._grpc_resolver, tuples_to_resolvaddr(resolved), <grpc_error*>0 - ) - + ) + cdef void resolve(self, const char* host, const char* port): - assert not self._task_resolve - + assert not self._task_resolve + self._task_resolve = self._loop.create_task( self._async_resolve(host, port) - ) + ) diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/iomgr/socket.pxd.pxi b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/iomgr/socket.pxd.pxi index cfab5549b2..c08f7ace31 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/iomgr/socket.pxd.pxi +++ b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/iomgr/socket.pxd.pxi @@ -1,63 +1,63 @@ -# Copyright 2019 gRPC authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -cdef class _AsyncioSocket: - cdef: - # Common attributes - grpc_custom_socket * _grpc_socket - grpc_custom_read_callback _grpc_read_cb +# Copyright 2019 gRPC authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +cdef class _AsyncioSocket: + cdef: + # Common attributes + grpc_custom_socket * _grpc_socket + grpc_custom_read_callback _grpc_read_cb grpc_custom_write_callback _grpc_write_cb - object _reader - object _writer - object _task_read + object _reader + object _writer + object _task_read object _task_write - object _task_connect + object _task_connect object _task_listen - char * _read_buffer + char * _read_buffer # Caches the picked event loop, so we can avoid the 30ns overhead each # time we need access to the event loop. object _loop # TODO(lidiz) Drop after 3.6 deprecation. Python 3.7 introduces methods # like `is_closing()` to help graceful shutdown. bint _closed - - # Client-side attributes - grpc_custom_connect_callback _grpc_connect_cb - - # Server-side attributes - grpc_custom_accept_callback _grpc_accept_cb - grpc_custom_socket * _grpc_client_socket - object _server - object _py_socket - object _peername - - @staticmethod - cdef _AsyncioSocket create( - grpc_custom_socket * grpc_socket, - object reader, - object writer) - @staticmethod - cdef _AsyncioSocket create_with_py_socket(grpc_custom_socket * grpc_socket, object py_socket) - - cdef void connect(self, object host, object port, grpc_custom_connect_callback grpc_connect_cb) - cdef void write(self, grpc_slice_buffer * g_slice_buffer, grpc_custom_write_callback grpc_write_cb) - cdef void read(self, char * buffer_, size_t length, grpc_custom_read_callback grpc_read_cb) - cdef bint is_connected(self) - cdef void close(self) - - cdef accept(self, grpc_custom_socket* grpc_socket_client, grpc_custom_accept_callback grpc_accept_cb) - cdef listen(self) - cdef tuple peername(self) - cdef tuple sockname(self) + + # Client-side attributes + grpc_custom_connect_callback _grpc_connect_cb + + # Server-side attributes + grpc_custom_accept_callback _grpc_accept_cb + grpc_custom_socket * _grpc_client_socket + object _server + object _py_socket + object _peername + + @staticmethod + cdef _AsyncioSocket create( + grpc_custom_socket * grpc_socket, + object reader, + object writer) + @staticmethod + cdef _AsyncioSocket create_with_py_socket(grpc_custom_socket * grpc_socket, object py_socket) + + cdef void connect(self, object host, object port, grpc_custom_connect_callback grpc_connect_cb) + cdef void write(self, grpc_slice_buffer * g_slice_buffer, grpc_custom_write_callback grpc_write_cb) + cdef void read(self, char * buffer_, size_t length, grpc_custom_read_callback grpc_read_cb) + cdef bint is_connected(self) + cdef void close(self) + + cdef accept(self, grpc_custom_socket* grpc_socket_client, grpc_custom_accept_callback grpc_accept_cb) + cdef listen(self) + cdef tuple peername(self) + cdef tuple sockname(self) diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/iomgr/socket.pyx.pxi b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/iomgr/socket.pyx.pxi index eecef17d98..68d3d55d92 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/iomgr/socket.pyx.pxi +++ b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/iomgr/socket.pyx.pxi @@ -1,74 +1,74 @@ -# Copyright 2019 gRPC authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import socket as native_socket - -from libc cimport string - +# Copyright 2019 gRPC authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import socket as native_socket + +from libc cimport string + cdef int _ASYNCIO_STREAM_DEFAULT_SOCKET_BACKLOG = 100 # TODO(https://github.com/grpc/grpc/issues/21348) Better flow control needed. -cdef class _AsyncioSocket: - def __cinit__(self): - self._grpc_socket = NULL - self._grpc_connect_cb = NULL - self._grpc_read_cb = NULL +cdef class _AsyncioSocket: + def __cinit__(self): + self._grpc_socket = NULL + self._grpc_connect_cb = NULL + self._grpc_read_cb = NULL self._grpc_write_cb = NULL - self._reader = None - self._writer = None - self._task_connect = None - self._task_read = None + self._reader = None + self._writer = None + self._task_connect = None + self._task_read = None self._task_write = None self._task_listen = None - self._read_buffer = NULL - self._server = None - self._py_socket = None - self._peername = None + self._read_buffer = NULL + self._server = None + self._py_socket = None + self._peername = None self._closed = False self._loop = get_working_loop() - - @staticmethod - cdef _AsyncioSocket create(grpc_custom_socket * grpc_socket, - object reader, - object writer): - socket = _AsyncioSocket() - socket._grpc_socket = grpc_socket - socket._reader = reader - socket._writer = writer - if writer is not None: - socket._peername = writer.get_extra_info('peername') - return socket - - @staticmethod - cdef _AsyncioSocket create_with_py_socket(grpc_custom_socket * grpc_socket, object py_socket): - socket = _AsyncioSocket() - socket._grpc_socket = grpc_socket - socket._py_socket = py_socket - return socket - - def __repr__(self): - class_name = self.__class__.__name__ - id_ = id(self) - connected = self.is_connected() - return f"<{class_name} {id_} connected={connected}>" - + + @staticmethod + cdef _AsyncioSocket create(grpc_custom_socket * grpc_socket, + object reader, + object writer): + socket = _AsyncioSocket() + socket._grpc_socket = grpc_socket + socket._reader = reader + socket._writer = writer + if writer is not None: + socket._peername = writer.get_extra_info('peername') + return socket + + @staticmethod + cdef _AsyncioSocket create_with_py_socket(grpc_custom_socket * grpc_socket, object py_socket): + socket = _AsyncioSocket() + socket._grpc_socket = grpc_socket + socket._py_socket = py_socket + return socket + + def __repr__(self): + class_name = self.__class__.__name__ + id_ = id(self) + connected = self.is_connected() + return f"<{class_name} {id_} connected={connected}>" + async def _async_connect(self, object host, object port,): self._task_connect = None - try: + try: self._reader, self._writer = await asyncio.open_connection(host, port) - except Exception as e: + except Exception as e: self._grpc_connect_cb( <grpc_custom_socket*>self._grpc_socket, grpc_socket_error("Socket connect failed: {}: {}".format(type(e), str(e)).encode()) @@ -78,12 +78,12 @@ cdef class _AsyncioSocket: # algorithm. sock = self._writer.transport.get_extra_info('socket') sock.setsockopt(native_socket.IPPROTO_TCP, native_socket.TCP_NODELAY, True) - + self._grpc_connect_cb( <grpc_custom_socket*>self._grpc_socket, <grpc_error*>0 ) - + cdef void connect(self, object host, object port, @@ -95,10 +95,10 @@ cdef class _AsyncioSocket: self._async_connect(host, port) ) self._grpc_connect_cb = grpc_connect_cb - + async def _async_read(self, size_t length): self._task_read = None - try: + try: inbound_buffer = await self._reader.read(n=length) except ConnectionError as e: self._grpc_read_cb( @@ -107,22 +107,22 @@ cdef class _AsyncioSocket: grpc_socket_error("Read failed: {}".format(e).encode()) ) else: - string.memcpy( - <void*>self._read_buffer, + string.memcpy( + <void*>self._read_buffer, <char*>inbound_buffer, len(inbound_buffer) - ) - self._grpc_read_cb( - <grpc_custom_socket*>self._grpc_socket, + ) + self._grpc_read_cb( + <grpc_custom_socket*>self._grpc_socket, len(inbound_buffer), - <grpc_error*>0 - ) - - cdef void read(self, char * buffer_, size_t length, grpc_custom_read_callback grpc_read_cb): - assert not self._task_read - - self._grpc_read_cb = grpc_read_cb - self._read_buffer = buffer_ + <grpc_error*>0 + ) + + cdef void read(self, char * buffer_, size_t length, grpc_custom_read_callback grpc_read_cb): + assert not self._task_read + + self._grpc_read_cb = grpc_read_cb + self._read_buffer = buffer_ self._task_read = self._loop.create_task(self._async_read(length)) async def _async_write(self, bytearray outbound_buffer): @@ -140,7 +140,7 @@ cdef class _AsyncioSocket: grpc_socket_error("Socket write failed: {}".format(connection_error).encode()), ) - cdef void write(self, grpc_slice_buffer * g_slice_buffer, grpc_custom_write_callback grpc_write_cb): + cdef void write(self, grpc_slice_buffer * g_slice_buffer, grpc_custom_write_callback grpc_write_cb): """Performs write to network socket in AsyncIO. For each socket, Core guarantees there'll be only one ongoing write. @@ -148,37 +148,37 @@ cdef class _AsyncioSocket: Core that the work is done. """ assert not self._task_write - cdef char* start + cdef char* start cdef bytearray outbound_buffer = bytearray() - for i in range(g_slice_buffer.count): - start = grpc_slice_buffer_start(g_slice_buffer, i) - length = grpc_slice_buffer_length(g_slice_buffer, i) + for i in range(g_slice_buffer.count): + start = grpc_slice_buffer_start(g_slice_buffer, i) + length = grpc_slice_buffer_length(g_slice_buffer, i) outbound_buffer.extend(<bytes>start[:length]) - + self._grpc_write_cb = grpc_write_cb self._task_write = self._loop.create_task(self._async_write(outbound_buffer)) - - cdef bint is_connected(self): - return self._reader and not self._reader._transport.is_closing() - - cdef void close(self): + + cdef bint is_connected(self): + return self._reader and not self._reader._transport.is_closing() + + cdef void close(self): if self._closed: return else: self._closed = True - if self.is_connected(): - self._writer.close() + if self.is_connected(): + self._writer.close() if self._task_listen and not self._task_listen.done(): self._task_listen.close() - if self._server: - self._server.close() - # NOTE(lidiz) If the asyncio.Server is created from a Python socket, - # the server.close() won't release the fd until the close() is called - # for the Python socket. - if self._py_socket: - self._py_socket.close() - - def _new_connection_callback(self, object reader, object writer): + if self._server: + self._server.close() + # NOTE(lidiz) If the asyncio.Server is created from a Python socket, + # the server.close() won't release the fd until the close() is called + # for the Python socket. + if self._py_socket: + self._py_socket.close() + + def _new_connection_callback(self, object reader, object writer): # If the socket is closed, stop. if self._closed: return @@ -188,38 +188,38 @@ cdef class _AsyncioSocket: writer.close() return - client_socket = _AsyncioSocket.create( - self._grpc_client_socket, - reader, - writer, - ) - - self._grpc_client_socket.impl = <void*>client_socket - cpython.Py_INCREF(client_socket) # Py_DECREF in asyncio_socket_destroy - # Accept callback expects to be called with: + client_socket = _AsyncioSocket.create( + self._grpc_client_socket, + reader, + writer, + ) + + self._grpc_client_socket.impl = <void*>client_socket + cpython.Py_INCREF(client_socket) # Py_DECREF in asyncio_socket_destroy + # Accept callback expects to be called with: # * grpc_custom_socket: A grpc custom socket for server # * grpc_custom_socket: A grpc custom socket for client (with new Socket instance) # * grpc_error: An error object - self._grpc_accept_cb(self._grpc_socket, self._grpc_client_socket, grpc_error_none()) - - cdef listen(self): + self._grpc_accept_cb(self._grpc_socket, self._grpc_client_socket, grpc_error_none()) + + cdef listen(self): self._py_socket.listen(_ASYNCIO_STREAM_DEFAULT_SOCKET_BACKLOG) - async def create_asyncio_server(): - self._server = await asyncio.start_server( - self._new_connection_callback, - sock=self._py_socket, - ) - + async def create_asyncio_server(): + self._server = await asyncio.start_server( + self._new_connection_callback, + sock=self._py_socket, + ) + self._task_listen = self._loop.create_task(create_asyncio_server()) - - cdef accept(self, - grpc_custom_socket* grpc_socket_client, - grpc_custom_accept_callback grpc_accept_cb): - self._grpc_client_socket = grpc_socket_client - self._grpc_accept_cb = grpc_accept_cb - - cdef tuple peername(self): - return self._peername - - cdef tuple sockname(self): - return self._py_socket.getsockname() + + cdef accept(self, + grpc_custom_socket* grpc_socket_client, + grpc_custom_accept_callback grpc_accept_cb): + self._grpc_client_socket = grpc_socket_client + self._grpc_accept_cb = grpc_accept_cb + + cdef tuple peername(self): + return self._peername + + cdef tuple sockname(self): + return self._py_socket.getsockname() diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/iomgr/timer.pxd.pxi b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/iomgr/timer.pxd.pxi index 76c3be0c57..1079411402 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/iomgr/timer.pxd.pxi +++ b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/iomgr/timer.pxd.pxi @@ -1,25 +1,25 @@ -# Copyright 2019 gRPC authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -cdef class _AsyncioTimer: - cdef: - grpc_custom_timer * _grpc_timer +# Copyright 2019 gRPC authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +cdef class _AsyncioTimer: + cdef: + grpc_custom_timer * _grpc_timer object _timer_future bint _active object _loop - - @staticmethod + + @staticmethod cdef _AsyncioTimer create(grpc_custom_timer * grpc_timer, float timeout) - - cdef stop(self) + + cdef stop(self) diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/iomgr/timer.pyx.pxi b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/iomgr/timer.pyx.pxi index c1508373a4..bace27429f 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/iomgr/timer.pyx.pxi +++ b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/iomgr/timer.pyx.pxi @@ -1,48 +1,48 @@ -# Copyright 2019 gRPC authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -cdef class _AsyncioTimer: - def __cinit__(self): - self._grpc_timer = NULL +# Copyright 2019 gRPC authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +cdef class _AsyncioTimer: + def __cinit__(self): + self._grpc_timer = NULL self._timer_future = None self._active = False self._loop = get_working_loop() cpython.Py_INCREF(self) - - @staticmethod + + @staticmethod cdef _AsyncioTimer create(grpc_custom_timer * grpc_timer, float timeout): - timer = _AsyncioTimer() - timer._grpc_timer = grpc_timer + timer = _AsyncioTimer() + timer._grpc_timer = grpc_timer timer._timer_future = timer._loop.call_later(timeout, timer.on_time_up) timer._active = True - return timer - + return timer + def on_time_up(self): self._active = False - grpc_custom_timer_callback(self._grpc_timer, <grpc_error*>0) + grpc_custom_timer_callback(self._grpc_timer, <grpc_error*>0) cpython.Py_DECREF(self) - - def __repr__(self): - class_name = self.__class__.__name__ - id_ = id(self) - return f"<{class_name} {id_} deadline={self._deadline} active={self._active}>" - - cdef stop(self): + + def __repr__(self): + class_name = self.__class__.__name__ + id_ = id(self) + return f"<{class_name} {id_} deadline={self._deadline} active={self._active}>" + + cdef stop(self): if not self._active: - return - + return + self._timer_future.cancel() self._active = False cpython.Py_DECREF(self) diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/server.pxd.pxi b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/server.pxd.pxi index 46a47bd1ba..4623c2340c 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/server.pxd.pxi +++ b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/server.pxd.pxi @@ -1,25 +1,25 @@ -# Copyright 2019 The gRPC Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -cdef class _HandlerCallDetails: - cdef readonly str method - cdef readonly tuple invocation_metadata - - -cdef class RPCState(GrpcCallWrapper): - cdef grpc_call_details details - cdef grpc_metadata_array request_metadata +# Copyright 2019 The gRPC Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +cdef class _HandlerCallDetails: + cdef readonly str method + cdef readonly tuple invocation_metadata + + +cdef class RPCState(GrpcCallWrapper): + cdef grpc_call_details details + cdef grpc_metadata_array request_metadata cdef AioServer server # NOTE(lidiz) Under certain corner case, receiving the client close # operation won't immediately fail ongoing RECV_MESSAGE operations. Here I @@ -33,14 +33,14 @@ cdef class RPCState(GrpcCallWrapper): cdef tuple trailing_metadata cdef object compression_algorithm cdef bint disable_next_compression - - cdef bytes method(self) + + cdef bytes method(self) cdef tuple invocation_metadata(self) cdef void raise_for_termination(self) except * cdef int get_write_flag(self) cdef Operation create_send_initial_metadata_op_if_not_sent(self) - - + + cdef class _ServicerContext: cdef RPCState _rpc_state cdef object _loop # asyncio.AbstractEventLoop @@ -59,24 +59,24 @@ cdef class _MessageReceiver: cdef object _agen -cdef enum AioServerStatus: - AIO_SERVER_STATUS_UNKNOWN - AIO_SERVER_STATUS_READY - AIO_SERVER_STATUS_RUNNING - AIO_SERVER_STATUS_STOPPED - AIO_SERVER_STATUS_STOPPING - - -cdef class AioServer: - cdef Server _server - cdef list _generic_handlers - cdef AioServerStatus _status - cdef object _loop # asyncio.EventLoop - cdef object _serving_task # asyncio.Task - cdef object _shutdown_lock # asyncio.Lock - cdef object _shutdown_completed # asyncio.Future - cdef CallbackWrapper _shutdown_callback_wrapper - cdef object _crash_exception # Exception +cdef enum AioServerStatus: + AIO_SERVER_STATUS_UNKNOWN + AIO_SERVER_STATUS_READY + AIO_SERVER_STATUS_RUNNING + AIO_SERVER_STATUS_STOPPED + AIO_SERVER_STATUS_STOPPING + + +cdef class AioServer: + cdef Server _server + cdef list _generic_handlers + cdef AioServerStatus _status + cdef object _loop # asyncio.EventLoop + cdef object _serving_task # asyncio.Task + cdef object _shutdown_lock # asyncio.Lock + cdef object _shutdown_completed # asyncio.Future + cdef CallbackWrapper _shutdown_callback_wrapper + cdef object _crash_exception # Exception cdef tuple _interceptors cdef object _thread_pool # concurrent.futures.ThreadPoolExecutor diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/server.pyx.pxi b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/server.pyx.pxi index a630ed8811..74a61f2a7a 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/server.pyx.pxi +++ b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/server.pyx.pxi @@ -1,27 +1,27 @@ -# Copyright 2019 The gRPC Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - +# Copyright 2019 The gRPC Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + import inspect import traceback import functools -cdef int _EMPTY_FLAG = 0 +cdef int _EMPTY_FLAG = 0 cdef str _RPC_FINISHED_DETAILS = 'RPC already finished.' cdef str _SERVER_STOPPED_DETAILS = 'Server already stopped.' - + cdef _augment_metadata(tuple metadata, object compression): if compression is None: return metadata @@ -32,24 +32,24 @@ cdef _augment_metadata(tuple metadata, object compression): ),) + metadata -cdef class _HandlerCallDetails: - def __cinit__(self, str method, tuple invocation_metadata): - self.method = method - self.invocation_metadata = invocation_metadata - - +cdef class _HandlerCallDetails: + def __cinit__(self, str method, tuple invocation_metadata): + self.method = method + self.invocation_metadata = invocation_metadata + + class _ServerStoppedError(BaseError): """Raised if the server is stopped.""" -cdef class RPCState: - +cdef class RPCState: + def __cinit__(self, AioServer server): init_grpc_aio() self.call = NULL self.server = server - grpc_metadata_array_init(&self.request_metadata) - grpc_call_details_init(&self.details) + grpc_metadata_array_init(&self.request_metadata) + grpc_call_details_init(&self.details) self.client_closed = False self.abort_exception = None self.metadata_sent = False @@ -59,10 +59,10 @@ cdef class RPCState: self.trailing_metadata = _IMMUTABLE_EMPTY_METADATA self.compression_algorithm = None self.disable_next_compression = False - - cdef bytes method(self): + + cdef bytes method(self): return _slice_bytes(self.details.method) - + cdef tuple invocation_metadata(self): return _metadata(&self.request_metadata) @@ -101,15 +101,15 @@ cdef class RPCState: ) return op - def __dealloc__(self): - """Cleans the Core objects.""" - grpc_call_details_destroy(&self.details) - grpc_metadata_array_destroy(&self.request_metadata) - if self.call: - grpc_call_unref(self.call) + def __dealloc__(self): + """Cleans the Core objects.""" + grpc_call_details_destroy(&self.details) + grpc_metadata_array_destroy(&self.request_metadata) + if self.call: + grpc_call_unref(self.call) shutdown_grpc_aio() - - + + cdef class _ServicerContext: def __cinit__(self, @@ -346,7 +346,7 @@ async def _find_method_handler(str method, tuple metadata, list generic_handlers else: return query_handlers(handler_call_details) - + async def _finish_handler_with_unary_response(RPCState rpc_state, object unary_handler, object request, @@ -484,21 +484,21 @@ async def _finish_handler_with_stream_responses(RPCState rpc_state, await execute_batch(rpc_state, finish_ops, loop) -async def _handle_unary_unary_rpc(object method_handler, - RPCState rpc_state, - object loop): - # Receives request message +async def _handle_unary_unary_rpc(object method_handler, + RPCState rpc_state, + object loop): + # Receives request message cdef bytes request_raw = await _receive_message(rpc_state, loop) if request_raw is None: # The RPC was cancelled immediately after start on client side. return - - # Deserializes the request message + + # Deserializes the request message cdef object request_message = deserialize( method_handler.request_deserializer, request_raw, ) - + # Creates a dedecated ServicerContext cdef _ServicerContext servicer_context = _ServicerContext( rpc_state, @@ -506,7 +506,7 @@ async def _handle_unary_unary_rpc(object method_handler, None, loop, ) - + # Finishes the application handler await _finish_handler_with_unary_response( rpc_state, @@ -516,7 +516,7 @@ async def _handle_unary_unary_rpc(object method_handler, method_handler.response_serializer, loop ) - + async def _handle_unary_stream_rpc(object method_handler, RPCState rpc_state, @@ -530,8 +530,8 @@ async def _handle_unary_stream_rpc(object method_handler, cdef object request_message = deserialize( method_handler.request_deserializer, request_raw, - ) - + ) + # Creates a dedecated ServicerContext cdef _ServicerContext servicer_context = _ServicerContext( rpc_state, @@ -539,7 +539,7 @@ async def _handle_unary_stream_rpc(object method_handler, method_handler.response_serializer, loop, ) - + # Finishes the application handler await _finish_handler_with_stream_responses( rpc_state, @@ -547,16 +547,16 @@ async def _handle_unary_stream_rpc(object method_handler, request_message, servicer_context, loop, - ) - - + ) + + cdef class _MessageReceiver: """Bridge between the async generator API and the reader-writer API.""" - + def __cinit__(self, _ServicerContext servicer_context): self._servicer_context = servicer_context self._agen = None - + async def _async_message_receiver(self): """An async generator that receives messages.""" cdef object message @@ -587,7 +587,7 @@ async def _handle_stream_unary_rpc(object method_handler, None, loop, ) - + # Prepares the request generator cdef object request_iterator if _is_async_handler(method_handler.stream_unary): @@ -597,7 +597,7 @@ async def _handle_stream_unary_rpc(object method_handler, _MessageReceiver(servicer_context), loop ) - + # Finishes the application handler await _finish_handler_with_unary_response( rpc_state, @@ -611,15 +611,15 @@ async def _handle_stream_unary_rpc(object method_handler, async def _handle_stream_stream_rpc(object method_handler, RPCState rpc_state, - object loop): + object loop): # Creates a dedecated ServicerContext cdef _ServicerContext servicer_context = _ServicerContext( rpc_state, method_handler.request_deserializer, method_handler.response_serializer, loop, - ) - + ) + # Prepares the request generator cdef object request_iterator if _is_async_handler(method_handler.stream_stream): @@ -629,7 +629,7 @@ async def _handle_stream_stream_rpc(object method_handler, _MessageReceiver(servicer_context), loop ) - + # Finishes the application handler await _finish_handler_with_stream_responses( rpc_state, @@ -638,7 +638,7 @@ async def _handle_stream_stream_rpc(object method_handler, servicer_context, loop, ) - + async def _handle_exceptions(RPCState rpc_state, object rpc_coro, object loop): try: @@ -689,11 +689,11 @@ async def _handle_exceptions(RPCState rpc_state, object rpc_coro, object loop): ) -async def _handle_cancellation_from_core(object rpc_task, +async def _handle_cancellation_from_core(object rpc_task, RPCState rpc_state, object loop): - cdef ReceiveCloseOnServerOperation op = ReceiveCloseOnServerOperation(_EMPTY_FLAG) - cdef tuple ops = (op,) + cdef ReceiveCloseOnServerOperation op = ReceiveCloseOnServerOperation(_EMPTY_FLAG) + cdef tuple ops = (op,) # Awaits cancellation from peer. await execute_batch(rpc_state, ops, loop) @@ -703,9 +703,9 @@ async def _handle_cancellation_from_core(object rpc_task, # log that an RPC is both aborted and cancelled. if op.cancelled() and not rpc_task.done() and not rpc_state.status_sent: # Injects `CancelledError` to halt the RPC coroutine - rpc_task.cancel() - - + rpc_task.cancel() + + async def _schedule_rpc_coro(object rpc_coro, RPCState rpc_state, object loop): @@ -775,60 +775,60 @@ cdef CallbackFailureHandler REQUEST_CALL_FAILURE_HANDLER = CallbackFailureHandle 'grpc_server_request_call', None, _RequestCallError) -cdef CallbackFailureHandler SERVER_SHUTDOWN_FAILURE_HANDLER = CallbackFailureHandler( - 'grpc_server_shutdown_and_notify', +cdef CallbackFailureHandler SERVER_SHUTDOWN_FAILURE_HANDLER = CallbackFailureHandler( + 'grpc_server_shutdown_and_notify', None, InternalError) - - -cdef class AioServer: - - def __init__(self, loop, thread_pool, generic_handlers, interceptors, + + +cdef class AioServer: + + def __init__(self, loop, thread_pool, generic_handlers, interceptors, options, maximum_concurrent_rpcs): init_grpc_aio() - # NOTE(lidiz) Core objects won't be deallocated automatically. - # If AioServer.shutdown is not called, those objects will leak. - self._server = Server(options) - grpc_server_register_completion_queue( - self._server.c_server, + # NOTE(lidiz) Core objects won't be deallocated automatically. + # If AioServer.shutdown is not called, those objects will leak. + self._server = Server(options) + grpc_server_register_completion_queue( + self._server.c_server, global_completion_queue(), - NULL - ) - - self._loop = loop - self._status = AIO_SERVER_STATUS_READY - self._generic_handlers = [] - self.add_generic_rpc_handlers(generic_handlers) - self._serving_task = None - - self._shutdown_lock = asyncio.Lock(loop=self._loop) - self._shutdown_completed = self._loop.create_future() - self._shutdown_callback_wrapper = CallbackWrapper( - self._shutdown_completed, + NULL + ) + + self._loop = loop + self._status = AIO_SERVER_STATUS_READY + self._generic_handlers = [] + self.add_generic_rpc_handlers(generic_handlers) + self._serving_task = None + + self._shutdown_lock = asyncio.Lock(loop=self._loop) + self._shutdown_completed = self._loop.create_future() + self._shutdown_callback_wrapper = CallbackWrapper( + self._shutdown_completed, self._loop, - SERVER_SHUTDOWN_FAILURE_HANDLER) - self._crash_exception = None - - if interceptors: + SERVER_SHUTDOWN_FAILURE_HANDLER) + self._crash_exception = None + + if interceptors: self._interceptors = interceptors else: self._interceptors = () self._thread_pool = thread_pool - if maximum_concurrent_rpcs: - raise NotImplementedError() - + if maximum_concurrent_rpcs: + raise NotImplementedError() + def add_generic_rpc_handlers(self, object generic_rpc_handlers): self._generic_handlers.extend(generic_rpc_handlers) - - def add_insecure_port(self, address): - return self._server.add_http2_port(address) - - def add_secure_port(self, address, server_credentials): - return self._server.add_http2_port(address, + + def add_insecure_port(self, address): + return self._server.add_http2_port(address) + + def add_secure_port(self, address, server_credentials): + return self._server.add_http2_port(address, server_credentials._credentials) - + async def _request_call(self): cdef grpc_call_error error cdef RPCState rpc_state = RPCState(self) @@ -849,20 +849,20 @@ cdef class AioServer: await future return rpc_state - async def _server_main_loop(self, - object server_started): + async def _server_main_loop(self, + object server_started): self._server.start(backup_queue=False) - cdef RPCState rpc_state - server_started.set_result(True) - - while True: - # When shutdown begins, no more new connections. - if self._status != AIO_SERVER_STATUS_RUNNING: - break - + cdef RPCState rpc_state + server_started.set_result(True) + + while True: + # When shutdown begins, no more new connections. + if self._status != AIO_SERVER_STATUS_RUNNING: + break + # Accepts new request from Core rpc_state = await self._request_call() - + # Creates the dedicated RPC coroutine. If we schedule it right now, # there is no guarantee if the cancellation listening coroutine is # ready or not. So, we should control the ordering by scheduling @@ -874,124 +874,124 @@ cdef class AioServer: self._loop) # Fires off a task that listens on the cancellation from client. - self._loop.create_task( + self._loop.create_task( _schedule_rpc_coro( rpc_coro, - rpc_state, - self._loop - ) - ) - - def _serving_task_crash_handler(self, object task): - """Shutdown the server immediately if unexpectedly exited.""" - if task.exception() is None: - return - if self._status != AIO_SERVER_STATUS_STOPPING: - self._crash_exception = task.exception() - _LOGGER.exception(self._crash_exception) - self._loop.create_task(self.shutdown(None)) - - async def start(self): - if self._status == AIO_SERVER_STATUS_RUNNING: - return - elif self._status != AIO_SERVER_STATUS_READY: + rpc_state, + self._loop + ) + ) + + def _serving_task_crash_handler(self, object task): + """Shutdown the server immediately if unexpectedly exited.""" + if task.exception() is None: + return + if self._status != AIO_SERVER_STATUS_STOPPING: + self._crash_exception = task.exception() + _LOGGER.exception(self._crash_exception) + self._loop.create_task(self.shutdown(None)) + + async def start(self): + if self._status == AIO_SERVER_STATUS_RUNNING: + return + elif self._status != AIO_SERVER_STATUS_READY: raise UsageError('Server not in ready state') - - self._status = AIO_SERVER_STATUS_RUNNING - cdef object server_started = self._loop.create_future() - self._serving_task = self._loop.create_task(self._server_main_loop(server_started)) - self._serving_task.add_done_callback(self._serving_task_crash_handler) - # Needs to explicitly wait for the server to start up. - # Otherwise, the actual start time of the server is un-controllable. - await server_started - - async def _start_shutting_down(self): - """Prepares the server to shutting down. - - This coroutine function is NOT coroutine-safe. - """ - # The shutdown callback won't be called until there is no live RPC. - grpc_server_shutdown_and_notify( - self._server.c_server, + + self._status = AIO_SERVER_STATUS_RUNNING + cdef object server_started = self._loop.create_future() + self._serving_task = self._loop.create_task(self._server_main_loop(server_started)) + self._serving_task.add_done_callback(self._serving_task_crash_handler) + # Needs to explicitly wait for the server to start up. + # Otherwise, the actual start time of the server is un-controllable. + await server_started + + async def _start_shutting_down(self): + """Prepares the server to shutting down. + + This coroutine function is NOT coroutine-safe. + """ + # The shutdown callback won't be called until there is no live RPC. + grpc_server_shutdown_and_notify( + self._server.c_server, global_completion_queue(), - self._shutdown_callback_wrapper.c_functor()) - - # Ensures the serving task (coroutine) exits. - try: - await self._serving_task - except _RequestCallError: - pass - - async def shutdown(self, grace): + self._shutdown_callback_wrapper.c_functor()) + + # Ensures the serving task (coroutine) exits. + try: + await self._serving_task + except _RequestCallError: + pass + + async def shutdown(self, grace): """Gracefully shutdown the Core server. - - Application should only call shutdown once. - - Args: - grace: An optional float indicating the length of grace period in - seconds. - """ - if self._status == AIO_SERVER_STATUS_READY or self._status == AIO_SERVER_STATUS_STOPPED: - return - - async with self._shutdown_lock: - if self._status == AIO_SERVER_STATUS_RUNNING: - self._server.is_shutting_down = True - self._status = AIO_SERVER_STATUS_STOPPING - await self._start_shutting_down() - - if grace is None: - # Directly cancels all calls - grpc_server_cancel_all_calls(self._server.c_server) - await self._shutdown_completed - else: - try: - await asyncio.wait_for( - asyncio.shield( - self._shutdown_completed, - loop=self._loop - ), - grace, - loop=self._loop, - ) - except asyncio.TimeoutError: - # Cancels all ongoing calls by the end of grace period. - grpc_server_cancel_all_calls(self._server.c_server) - await self._shutdown_completed - - async with self._shutdown_lock: - if self._status == AIO_SERVER_STATUS_STOPPING: - grpc_server_destroy(self._server.c_server) - self._server.c_server = NULL - self._server.is_shutdown = True - self._status = AIO_SERVER_STATUS_STOPPED - + + Application should only call shutdown once. + + Args: + grace: An optional float indicating the length of grace period in + seconds. + """ + if self._status == AIO_SERVER_STATUS_READY or self._status == AIO_SERVER_STATUS_STOPPED: + return + + async with self._shutdown_lock: + if self._status == AIO_SERVER_STATUS_RUNNING: + self._server.is_shutting_down = True + self._status = AIO_SERVER_STATUS_STOPPING + await self._start_shutting_down() + + if grace is None: + # Directly cancels all calls + grpc_server_cancel_all_calls(self._server.c_server) + await self._shutdown_completed + else: + try: + await asyncio.wait_for( + asyncio.shield( + self._shutdown_completed, + loop=self._loop + ), + grace, + loop=self._loop, + ) + except asyncio.TimeoutError: + # Cancels all ongoing calls by the end of grace period. + grpc_server_cancel_all_calls(self._server.c_server) + await self._shutdown_completed + + async with self._shutdown_lock: + if self._status == AIO_SERVER_STATUS_STOPPING: + grpc_server_destroy(self._server.c_server) + self._server.c_server = NULL + self._server.is_shutdown = True + self._status = AIO_SERVER_STATUS_STOPPED + async def wait_for_termination(self, object timeout): - if timeout is None: - await self._shutdown_completed - else: - try: - await asyncio.wait_for( - asyncio.shield( - self._shutdown_completed, - loop=self._loop, - ), - timeout, - loop=self._loop, - ) - except asyncio.TimeoutError: - if self._crash_exception is not None: - raise self._crash_exception - return False - if self._crash_exception is not None: - raise self._crash_exception - return True - - def __dealloc__(self): + if timeout is None: + await self._shutdown_completed + else: + try: + await asyncio.wait_for( + asyncio.shield( + self._shutdown_completed, + loop=self._loop, + ), + timeout, + loop=self._loop, + ) + except asyncio.TimeoutError: + if self._crash_exception is not None: + raise self._crash_exception + return False + if self._crash_exception is not None: + raise self._crash_exception + return True + + def __dealloc__(self): """Deallocation of Core objects are ensured by Python layer.""" # TODO(lidiz) if users create server, and then dealloc it immediately. # There is a potential memory leak of created Core server. - if self._status != AIO_SERVER_STATUS_STOPPED: + if self._status != AIO_SERVER_STATUS_STOPPED: _LOGGER.debug( '__dealloc__ called on running server %s with status %d', self, diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/arguments.pxd.pxi b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/arguments.pxd.pxi index 251efe15b3..24c22e6771 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/arguments.pxd.pxi +++ b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/arguments.pxd.pxi @@ -23,7 +23,7 @@ cdef class _ChannelArg: cdef grpc_arg c_argument - cdef void c(self, argument, references) except * + cdef void c(self, argument, references) except * cdef class _ChannelArgs: diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/arguments.pyx.pxi b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/arguments.pyx.pxi index 9df308cdbc..c0c8d59b33 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/arguments.pyx.pxi +++ b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/arguments.pyx.pxi @@ -31,7 +31,7 @@ cdef grpc_arg _unwrap_grpc_arg(tuple wrapped_arg): cdef class _ChannelArg: - cdef void c(self, argument, references) except *: + cdef void c(self, argument, references) except *: key, value = argument cdef bytes encoded_key = _encode(key) if encoded_key is not key: @@ -54,7 +54,7 @@ cdef class _ChannelArg: # lifecycle of the pointer is fixed to the lifecycle of the # python object wrapping it. self.c_argument.type = GRPC_ARG_POINTER - self.c_argument.value.pointer.vtable = &default_vtable + self.c_argument.value.pointer.vtable = &default_vtable self.c_argument.value.pointer.address = <void*>(<intptr_t>int(value)) else: raise TypeError( @@ -73,7 +73,7 @@ cdef class _ChannelArgs: self._c_arguments.arguments_length * sizeof(grpc_arg)) for index, argument in enumerate(self._arguments): channel_arg = _ChannelArg() - channel_arg.c(argument, self._references) + channel_arg.c(argument, self._references) self._c_arguments.arguments[index] = channel_arg.c_argument self._channel_args.append(channel_arg) diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/call.pyx.pxi b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/call.pyx.pxi index bdd155bea9..b97dc738f8 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/call.pyx.pxi +++ b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/call.pyx.pxi @@ -83,10 +83,10 @@ cdef class Call: return result def __dealloc__(self): - with nogil: - if self.c_call != NULL: - grpc_call_unref(self.c_call) - grpc_shutdown_blocking() + with nogil: + if self.c_call != NULL: + grpc_call_unref(self.c_call) + grpc_shutdown_blocking() # The object *should* always be valid from Python. Used for debugging. @property diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/channel.pyx.pxi b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/channel.pyx.pxi index 74c7f6c140..9699aa1bc6 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/channel.pyx.pxi +++ b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/channel.pyx.pxi @@ -142,38 +142,38 @@ cdef _cancel( cdef _next_call_event( _ChannelState channel_state, grpc_completion_queue *c_completion_queue, - on_success, on_failure, deadline): - """Block on the next event out of the completion queue. - - On success, `on_success` will be invoked with the tag taken from the CQ. - In the case of a failure due to an exception raised in a signal handler, - `on_failure` will be invoked with no arguments. Note that this situation - can only occur on the main thread. - - Args: - channel_state: The state for the channel on which the RPC is running. - c_completion_queue: The CQ which will be polled. - on_success: A callable object to be invoked upon successful receipt of a - tag from the CQ. - on_failure: A callable object to be invoked in case a Python exception is - raised from a signal handler during polling. - deadline: The point after which the RPC will time out. - """ - try: - tag, event = _latent_event(c_completion_queue, deadline) - # NOTE(rbellevi): This broad except enables us to clean up resources before - # propagating any exceptions raised by signal handlers to the application. - except: - if on_failure is not None: - on_failure() - raise - else: - with channel_state.condition: - on_success(tag) - channel_state.condition.notify_all() - return event - - + on_success, on_failure, deadline): + """Block on the next event out of the completion queue. + + On success, `on_success` will be invoked with the tag taken from the CQ. + In the case of a failure due to an exception raised in a signal handler, + `on_failure` will be invoked with no arguments. Note that this situation + can only occur on the main thread. + + Args: + channel_state: The state for the channel on which the RPC is running. + c_completion_queue: The CQ which will be polled. + on_success: A callable object to be invoked upon successful receipt of a + tag from the CQ. + on_failure: A callable object to be invoked in case a Python exception is + raised from a signal handler during polling. + deadline: The point after which the RPC will time out. + """ + try: + tag, event = _latent_event(c_completion_queue, deadline) + # NOTE(rbellevi): This broad except enables us to clean up resources before + # propagating any exceptions raised by signal handlers to the application. + except: + if on_failure is not None: + on_failure() + raise + else: + with channel_state.condition: + on_success(tag) + channel_state.condition.notify_all() + return event + + # TODO(https://github.com/grpc/grpc/issues/14569): This could be a lot simpler. cdef void _call( _ChannelState channel_state, _CallState call_state, @@ -329,14 +329,14 @@ cdef class SegregatedCall: def on_success(tag): _process_segregated_call_tag( self._channel_state, self._call_state, self._c_completion_queue, tag) - def on_failure(): - self._call_state.due.clear() - grpc_call_unref(self._call_state.c_call) - self._call_state.c_call = NULL - self._channel_state.segregated_call_states.remove(self._call_state) - _destroy_c_completion_queue(self._c_completion_queue) + def on_failure(): + self._call_state.due.clear() + grpc_call_unref(self._call_state.c_call) + self._call_state.c_call = NULL + self._channel_state.segregated_call_states.remove(self._call_state) + _destroy_c_completion_queue(self._c_completion_queue) return _next_call_event( - self._channel_state, self._c_completion_queue, on_success, on_failure, None) + self._channel_state, self._c_completion_queue, on_success, on_failure, None) cdef SegregatedCall _segregated_call( @@ -425,7 +425,7 @@ cdef _close(Channel channel, grpc_status_code code, object details, _destroy_c_completion_queue(state.c_connectivity_completion_queue) grpc_channel_destroy(state.c_channel) state.c_channel = NULL - grpc_shutdown_blocking() + grpc_shutdown_blocking() state.condition.notify_all() else: # Another call to close already completed in the past or is currently @@ -446,12 +446,12 @@ cdef class Channel: arguments = () if arguments is None else tuple(arguments) fork_handlers_and_grpc_init() self._state = _ChannelState() - self._state.c_call_completion_queue = ( - grpc_completion_queue_create_for_next(NULL)) - self._state.c_connectivity_completion_queue = ( - grpc_completion_queue_create_for_next(NULL)) - self._arguments = arguments - cdef _ChannelArgs channel_args = _ChannelArgs(arguments) + self._state.c_call_completion_queue = ( + grpc_completion_queue_create_for_next(NULL)) + self._state.c_connectivity_completion_queue = ( + grpc_completion_queue_create_for_next(NULL)) + self._arguments = arguments + cdef _ChannelArgs channel_args = _ChannelArgs(arguments) if channel_credentials is None: self._state.c_channel = grpc_insecure_channel_create( <char *>target, channel_args.c_args(), NULL) @@ -485,11 +485,11 @@ cdef class Channel: queue_deadline = time.time() + 1.0 else: queue_deadline = None - # NOTE(gnossen): It is acceptable for on_failure to be None here because - # failure conditions can only ever happen on the main thread and this - # method is only ever invoked on the channel spin thread. + # NOTE(gnossen): It is acceptable for on_failure to be None here because + # failure conditions can only ever happen on the main thread and this + # method is only ever invoked on the channel spin thread. return _next_call_event(self._state, self._state.c_call_completion_queue, - on_success, None, queue_deadline) + on_success, None, queue_deadline) def segregated_call( self, int flags, method, host, object deadline, object metadata, diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/completion_queue.pyx.pxi b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/completion_queue.pyx.pxi index a47403ac51..a5b2c6eaed 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/completion_queue.pyx.pxi +++ b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/completion_queue.pyx.pxi @@ -26,20 +26,20 @@ cdef grpc_event _next(grpc_completion_queue *c_completion_queue, deadline) excep else: c_deadline = _timespec_from_time(deadline) - while True: - with nogil: + while True: + with nogil: c_timeout = gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), c_increment) if gpr_time_cmp(c_timeout, c_deadline) > 0: c_timeout = c_deadline - + c_event = grpc_completion_queue_next(c_completion_queue, c_timeout, NULL) - + if (c_event.type != GRPC_QUEUE_TIMEOUT or gpr_time_cmp(c_timeout, c_deadline) == 0): break - # Handle any signals - cpython.PyErr_CheckSignals() + # Handle any signals + cpython.PyErr_CheckSignals() return c_event @@ -115,4 +115,4 @@ cdef class CompletionQueue: self.c_completion_queue, c_deadline, NULL) self._interpret_event(event) grpc_completion_queue_destroy(self.c_completion_queue) - grpc_shutdown_blocking() + grpc_shutdown_blocking() diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/credentials.pxd.pxi b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/credentials.pxd.pxi index ddaedb30bd..91d2f36195 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/credentials.pxd.pxi +++ b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/credentials.pxd.pxi @@ -26,9 +26,9 @@ cdef int _get_metadata( grpc_credentials_plugin_metadata_cb cb, void *user_data, grpc_metadata creds_md[GRPC_METADATA_CREDENTIALS_PLUGIN_SYNC_MAX], size_t *num_creds_md, grpc_status_code *status, - const char **error_details) except * with gil + const char **error_details) except * with gil -cdef void _destroy(void *state) except * with gil +cdef void _destroy(void *state) except * with gil cdef class MetadataPluginCallCredentials(CallCredentials): @@ -97,11 +97,11 @@ cdef class ServerCredentials: cdef object cert_config_fetcher # whether C-core has asked for the initial_cert_config cdef bint initial_cert_config_fetched - - -cdef class LocalChannelCredentials(ChannelCredentials): - - cdef grpc_local_connect_type _local_connect_type + + +cdef class LocalChannelCredentials(ChannelCredentials): + + cdef grpc_local_connect_type _local_connect_type cdef class ALTSChannelCredentials(ChannelCredentials): diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/credentials.pyx.pxi b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/credentials.pyx.pxi index c75579cc04..7408f2960d 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/credentials.pyx.pxi +++ b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/credentials.pyx.pxi @@ -56,9 +56,9 @@ cdef int _get_metadata(void *state, return 0 # Asynchronous return -cdef void _destroy(void *state) except * with gil: +cdef void _destroy(void *state) except * with gil: cpython.Py_DECREF(<object>state) - grpc_shutdown_blocking() + grpc_shutdown_blocking() cdef class MetadataPluginCallCredentials(CallCredentials): @@ -124,7 +124,7 @@ cdef class SSLSessionCacheLRU: def __dealloc__(self): if self._cache != NULL: grpc_ssl_session_cache_destroy(self._cache) - grpc_shutdown_blocking() + grpc_shutdown_blocking() cdef class SSLChannelCredentials(ChannelCredentials): @@ -190,7 +190,7 @@ cdef class ServerCertificateConfig: def __dealloc__(self): grpc_ssl_server_certificate_config_destroy(self.c_cert_config) gpr_free(self.c_ssl_pem_key_cert_pairs) - grpc_shutdown_blocking() + grpc_shutdown_blocking() cdef class ServerCredentials: @@ -206,7 +206,7 @@ cdef class ServerCredentials: def __dealloc__(self): if self.c_credentials != NULL: grpc_server_credentials_release(self.c_credentials) - grpc_shutdown_blocking() + grpc_shutdown_blocking() cdef const char* _get_c_pem_root_certs(pem_root_certs): if pem_root_certs is None: @@ -329,28 +329,28 @@ cdef grpc_ssl_certificate_config_reload_status _server_cert_config_fetcher_wrapp cert_config.c_ssl_pem_key_cert_pairs_count) return GRPC_SSL_CERTIFICATE_CONFIG_RELOAD_NEW - -class LocalConnectionType: - uds = UDS - local_tcp = LOCAL_TCP - -cdef class LocalChannelCredentials(ChannelCredentials): - - def __cinit__(self, grpc_local_connect_type local_connect_type): - self._local_connect_type = local_connect_type - - cdef grpc_channel_credentials *c(self) except *: - cdef grpc_local_connect_type local_connect_type - local_connect_type = self._local_connect_type - return grpc_local_credentials_create(local_connect_type) - -def channel_credentials_local(grpc_local_connect_type local_connect_type): - return LocalChannelCredentials(local_connect_type) - -def server_credentials_local(grpc_local_connect_type local_connect_type): - cdef ServerCredentials credentials = ServerCredentials() - credentials.c_credentials = grpc_local_server_credentials_create(local_connect_type) - return credentials + +class LocalConnectionType: + uds = UDS + local_tcp = LOCAL_TCP + +cdef class LocalChannelCredentials(ChannelCredentials): + + def __cinit__(self, grpc_local_connect_type local_connect_type): + self._local_connect_type = local_connect_type + + cdef grpc_channel_credentials *c(self) except *: + cdef grpc_local_connect_type local_connect_type + local_connect_type = self._local_connect_type + return grpc_local_credentials_create(local_connect_type) + +def channel_credentials_local(grpc_local_connect_type local_connect_type): + return LocalChannelCredentials(local_connect_type) + +def server_credentials_local(grpc_local_connect_type local_connect_type): + cdef ServerCredentials credentials = ServerCredentials() + credentials.c_credentials = grpc_local_server_credentials_create(local_connect_type) + return credentials cdef class ALTSChannelCredentials(ChannelCredentials): diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/fork_posix.pyx.pxi b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/fork_posix.pyx.pxi index 53657e8b1a..e430ec5309 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/fork_posix.pyx.pxi +++ b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/fork_posix.pyx.pxi @@ -32,12 +32,12 @@ _GRPC_ENABLE_FORK_SUPPORT = ( os.environ.get('GRPC_ENABLE_FORK_SUPPORT', '0') .lower() in _TRUE_VALUES) -_fork_handler_failed = False - +_fork_handler_failed = False + cdef void __prefork() nogil: with gil: - global _fork_handler_failed - _fork_handler_failed = False + global _fork_handler_failed + _fork_handler_failed = False with _fork_state.fork_in_progress_condition: _fork_state.fork_in_progress = True if not _fork_state.active_thread_count.await_zero_threads( @@ -45,7 +45,7 @@ cdef void __prefork() nogil: _LOGGER.error( 'Failed to shutdown gRPC Python threads prior to fork. ' 'Behavior after fork will be undefined.') - _fork_handler_failed = True + _fork_handler_failed = True cdef void __postfork_parent() nogil: @@ -57,28 +57,28 @@ cdef void __postfork_parent() nogil: cdef void __postfork_child() nogil: with gil: - try: - if _fork_handler_failed: - return - # Thread could be holding the fork_in_progress_condition inside of - # block_if_fork_in_progress() when fork occurs. Reset the lock here. - _fork_state.fork_in_progress_condition = threading.Condition() - # A thread in return_from_user_request_generator() may hold this lock - # when fork occurs. - _fork_state.active_thread_count = _ActiveThreadCount() - for state_to_reset in _fork_state.postfork_states_to_reset: - state_to_reset.reset_postfork_child() - _fork_state.postfork_states_to_reset = [] - _fork_state.fork_epoch += 1 - for channel in _fork_state.channels: - channel._close_on_fork() - with _fork_state.fork_in_progress_condition: - _fork_state.fork_in_progress = False - except: - _LOGGER.error('Exiting child due to raised exception') - _LOGGER.error(sys.exc_info()[0]) - os._exit(os.EX_USAGE) - + try: + if _fork_handler_failed: + return + # Thread could be holding the fork_in_progress_condition inside of + # block_if_fork_in_progress() when fork occurs. Reset the lock here. + _fork_state.fork_in_progress_condition = threading.Condition() + # A thread in return_from_user_request_generator() may hold this lock + # when fork occurs. + _fork_state.active_thread_count = _ActiveThreadCount() + for state_to_reset in _fork_state.postfork_states_to_reset: + state_to_reset.reset_postfork_child() + _fork_state.postfork_states_to_reset = [] + _fork_state.fork_epoch += 1 + for channel in _fork_state.channels: + channel._close_on_fork() + with _fork_state.fork_in_progress_condition: + _fork_state.fork_in_progress = False + except: + _LOGGER.error('Exiting child due to raised exception') + _LOGGER.error(sys.exc_info()[0]) + os._exit(os.EX_USAGE) + if grpc_is_initialized() > 0: with gil: _LOGGER.error('Failed to shutdown gRPC Core after fork()') @@ -158,7 +158,7 @@ def fork_register_channel(channel): def fork_unregister_channel(channel): if _GRPC_ENABLE_FORK_SUPPORT: - _fork_state.channels.discard(channel) + _fork_state.channels.discard(channel) class _ActiveThreadCount(object): diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/grpc.pxi b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/grpc.pxi index 54eb7fdffc..1ffd1fcbd6 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/grpc.pxi +++ b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/grpc.pxi @@ -14,16 +14,16 @@ cimport libc.time -ctypedef ssize_t intptr_t -ctypedef size_t uintptr_t -ctypedef signed char int8_t -ctypedef signed short int16_t -ctypedef signed int int32_t -ctypedef signed long long int64_t -ctypedef unsigned char uint8_t -ctypedef unsigned short uint16_t -ctypedef unsigned int uint32_t -ctypedef unsigned long long uint64_t +ctypedef ssize_t intptr_t +ctypedef size_t uintptr_t +ctypedef signed char int8_t +ctypedef signed short int16_t +ctypedef signed int int32_t +ctypedef signed long long int64_t +ctypedef unsigned char uint8_t +ctypedef unsigned short uint16_t +ctypedef unsigned int uint32_t +ctypedef unsigned long long uint64_t cdef extern from "grpc/support/alloc.h": @@ -41,11 +41,11 @@ cdef extern from "grpc/byte_buffer_reader.h": pass -cdef extern from "grpc/impl/codegen/grpc_types.h": - ctypedef struct grpc_experimental_completion_queue_functor: - void (*functor_run)(grpc_experimental_completion_queue_functor*, int); - - +cdef extern from "grpc/impl/codegen/grpc_types.h": + ctypedef struct grpc_experimental_completion_queue_functor: + void (*functor_run)(grpc_experimental_completion_queue_functor*, int); + + cdef extern from "grpc/grpc.h": ctypedef struct grpc_slice: @@ -68,10 +68,10 @@ cdef extern from "grpc/grpc.h": void *grpc_slice_start_ptr "GRPC_SLICE_START_PTR" (grpc_slice s) nogil size_t grpc_slice_length "GRPC_SLICE_LENGTH" (grpc_slice s) nogil - const int GPR_MS_PER_SEC - const int GPR_US_PER_SEC - const int GPR_NS_PER_SEC - + const int GPR_MS_PER_SEC + const int GPR_US_PER_SEC + const int GPR_NS_PER_SEC + ctypedef enum gpr_clock_type: GPR_CLOCK_MONOTONIC GPR_CLOCK_REALTIME @@ -93,8 +93,8 @@ cdef extern from "grpc/grpc.h": gpr_clock_type target_clock) nogil gpr_timespec gpr_time_from_millis(int64_t ms, gpr_clock_type type) nogil - gpr_timespec gpr_time_from_nanos(int64_t ns, gpr_clock_type type) nogil - double gpr_timespec_to_micros(gpr_timespec t) nogil + gpr_timespec gpr_time_from_nanos(int64_t ns, gpr_clock_type type) nogil + double gpr_timespec_to_micros(gpr_timespec t) nogil gpr_timespec gpr_time_add(gpr_timespec a, gpr_timespec b) nogil @@ -145,8 +145,8 @@ cdef extern from "grpc/grpc.h": const char *GRPC_ARG_SECONDARY_USER_AGENT_STRING const char *GRPC_SSL_TARGET_NAME_OVERRIDE_ARG const char *GRPC_SSL_SESSION_CACHE_ARG - const char *_GRPC_COMPRESSION_CHANNEL_DEFAULT_ALGORITHM \ - "GRPC_COMPRESSION_CHANNEL_DEFAULT_ALGORITHM" + const char *_GRPC_COMPRESSION_CHANNEL_DEFAULT_ALGORITHM \ + "GRPC_COMPRESSION_CHANNEL_DEFAULT_ALGORITHM" const char *GRPC_COMPRESSION_CHANNEL_DEFAULT_LEVEL const char *GRPC_COMPRESSION_CHANNEL_ENABLED_ALGORITHMS_BITSET @@ -330,12 +330,12 @@ cdef extern from "grpc/grpc.h": ctypedef struct grpc_op: grpc_op_type type "op" uint32_t flags - void * reserved + void * reserved grpc_op_data data void grpc_dont_init_openssl() nogil void grpc_init() nogil - void grpc_shutdown_blocking() nogil + void grpc_shutdown_blocking() nogil int grpc_is_initialized() nogil ctypedef struct grpc_completion_queue_factory: @@ -357,10 +357,10 @@ cdef extern from "grpc/grpc.h": void grpc_completion_queue_shutdown(grpc_completion_queue *cq) nogil void grpc_completion_queue_destroy(grpc_completion_queue *cq) nogil - grpc_completion_queue *grpc_completion_queue_create_for_callback( - grpc_experimental_completion_queue_functor* shutdown_callback, - void *reserved) nogil - + grpc_completion_queue *grpc_completion_queue_create_for_callback( + grpc_experimental_completion_queue_functor* shutdown_callback, + void *reserved) nogil + grpc_call_error grpc_call_start_batch( grpc_call *call, const grpc_op *ops, size_t nops, void *tag, void *reserved) nogil @@ -564,8 +564,8 @@ cdef extern from "grpc/grpc_security.h": grpc_credentials_plugin_metadata_cb cb, void *user_data, grpc_metadata creds_md[GRPC_METADATA_CREDENTIALS_PLUGIN_SYNC_MAX], size_t *num_creds_md, grpc_status_code *status, - const char **error_details) except * - void (*destroy)(void *state) except * + const char **error_details) except * + void (*destroy)(void *state) except * void *state const char *type @@ -602,11 +602,11 @@ cdef extern from "grpc/grpc_security.h": void grpc_auth_context_release(grpc_auth_context *context) - grpc_channel_credentials *grpc_local_credentials_create( - grpc_local_connect_type type) - grpc_server_credentials *grpc_local_server_credentials_create( - grpc_local_connect_type type) - + grpc_channel_credentials *grpc_local_credentials_create( + grpc_local_connect_type type) + grpc_server_credentials *grpc_local_server_credentials_create( + grpc_local_connect_type type) + ctypedef struct grpc_alts_credentials_options: # We don't care about the internals (and in fact don't know them) pass @@ -615,7 +615,7 @@ cdef extern from "grpc/grpc_security.h": const grpc_alts_credentials_options *options) grpc_server_credentials *grpc_alts_server_credentials_create( const grpc_alts_credentials_options *options) - + grpc_alts_credentials_options* grpc_alts_credentials_client_options_create() grpc_alts_credentials_options* grpc_alts_credentials_server_options_create() void grpc_alts_credentials_options_destroy(grpc_alts_credentials_options *options) @@ -658,14 +658,14 @@ cdef extern from "grpc/compression.h": int grpc_compression_options_is_algorithm_enabled( const grpc_compression_options *opts, grpc_compression_algorithm algorithm) nogil - -cdef extern from "grpc/impl/codegen/compression_types.h": - - const char *_GRPC_COMPRESSION_REQUEST_ALGORITHM_MD_KEY \ - "GRPC_COMPRESSION_REQUEST_ALGORITHM_MD_KEY" - - -cdef extern from "grpc/grpc_security_constants.h": - ctypedef enum grpc_local_connect_type: - UDS - LOCAL_TCP + +cdef extern from "grpc/impl/codegen/compression_types.h": + + const char *_GRPC_COMPRESSION_REQUEST_ALGORITHM_MD_KEY \ + "GRPC_COMPRESSION_REQUEST_ALGORITHM_MD_KEY" + + +cdef extern from "grpc/grpc_security_constants.h": + ctypedef enum grpc_local_connect_type: + UDS + LOCAL_TCP diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/grpc_gevent.pyx.pxi b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/grpc_gevent.pyx.pxi index 0f693ec691..6888af71c3 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/grpc_gevent.pyx.pxi +++ b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/grpc_gevent.pyx.pxi @@ -31,16 +31,16 @@ def _spawn_greenlet(*args): cdef class SocketWrapper: def __cinit__(self): - fork_handlers_and_grpc_init() + fork_handlers_and_grpc_init() self.sockopts = [] self.socket = None self.c_socket = NULL self.c_buffer = NULL self.len = 0 - def __dealloc__(self): - grpc_shutdown_blocking() - + def __dealloc__(self): + grpc_shutdown_blocking() + cdef grpc_error* socket_init(grpc_custom_socket* socket, int domain) with gil: sw = SocketWrapper() sw.c_socket = socket @@ -261,14 +261,14 @@ cdef void socket_accept(grpc_custom_socket* socket, grpc_custom_socket* client, cdef class ResolveWrapper: def __cinit__(self): - fork_handlers_and_grpc_init() + fork_handlers_and_grpc_init() self.c_resolver = NULL self.c_host = NULL self.c_port = NULL - def __dealloc__(self): - grpc_shutdown_blocking() - + def __dealloc__(self): + grpc_shutdown_blocking() + cdef socket_resolve_async_cython(ResolveWrapper resolve_wrapper): try: res = gevent_socket.getaddrinfo(resolve_wrapper.c_host, resolve_wrapper.c_port) @@ -305,7 +305,7 @@ cdef grpc_error* socket_resolve(const char* host, const char* port, cdef class TimerWrapper: def __cinit__(self, deadline): - fork_handlers_and_grpc_init() + fork_handlers_and_grpc_init() self.timer = gevent_hub.get_hub().loop.timer(deadline) self.event = None @@ -322,9 +322,9 @@ cdef class TimerWrapper: self.event.set() self.timer.stop() - def __dealloc__(self): - grpc_shutdown_blocking() - + def __dealloc__(self): + grpc_shutdown_blocking() + cdef void timer_start(grpc_custom_timer* t) with gil: timer = TimerWrapper(t.timeout_ms / 1000.0) timer.c_timer = t diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/grpc_string.pyx.pxi b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/grpc_string.pyx.pxi index 5c1e0679a9..3bdc172585 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/grpc_string.pyx.pxi +++ b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/grpc_string.pyx.pxi @@ -13,7 +13,7 @@ # limitations under the License. -# This function will ascii encode unicode string inputs if necessary. +# This function will ascii encode unicode string inputs if necessary. # In Python3, unicode strings are the default str type. cdef bytes str_to_bytes(object s): if s is None or isinstance(s, bytes): diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/iomgr.pxd.pxi b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/iomgr.pxd.pxi index 0c5a4e5763..59abfda2cb 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/iomgr.pxd.pxi +++ b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/iomgr.pxd.pxi @@ -1,129 +1,129 @@ -# Copyright 2019 gRPC authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# distutils: language=c++ - +# Copyright 2019 gRPC authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# distutils: language=c++ + from libcpp cimport bool as bool_t from libcpp.string cimport string as cppstring -cdef extern from "grpc/impl/codegen/slice.h": - struct grpc_slice_buffer: - int count - -cdef extern from "src/core/lib/iomgr/error.h": - struct grpc_error: - pass - -# TODO(https://github.com/grpc/grpc/issues/20135) Change the filename -# for something more meaningful. -cdef extern from "src/core/lib/iomgr/python_util.h": - grpc_error* grpc_socket_error(char* error) - char* grpc_slice_buffer_start(grpc_slice_buffer* buffer, int i) - int grpc_slice_buffer_length(grpc_slice_buffer* buffer, int i) - -cdef extern from "src/core/lib/iomgr/sockaddr.h": - ctypedef struct grpc_sockaddr: - pass - -cdef extern from "src/core/lib/iomgr/resolve_address.h": - ctypedef struct grpc_resolved_addresses: - size_t naddrs - grpc_resolved_address* addrs - - ctypedef struct grpc_resolved_address: - char[128] addr - size_t len - -cdef extern from "src/core/lib/iomgr/resolve_address_custom.h": - struct grpc_custom_resolver: - pass - - struct grpc_custom_resolver_vtable: +cdef extern from "grpc/impl/codegen/slice.h": + struct grpc_slice_buffer: + int count + +cdef extern from "src/core/lib/iomgr/error.h": + struct grpc_error: + pass + +# TODO(https://github.com/grpc/grpc/issues/20135) Change the filename +# for something more meaningful. +cdef extern from "src/core/lib/iomgr/python_util.h": + grpc_error* grpc_socket_error(char* error) + char* grpc_slice_buffer_start(grpc_slice_buffer* buffer, int i) + int grpc_slice_buffer_length(grpc_slice_buffer* buffer, int i) + +cdef extern from "src/core/lib/iomgr/sockaddr.h": + ctypedef struct grpc_sockaddr: + pass + +cdef extern from "src/core/lib/iomgr/resolve_address.h": + ctypedef struct grpc_resolved_addresses: + size_t naddrs + grpc_resolved_address* addrs + + ctypedef struct grpc_resolved_address: + char[128] addr + size_t len + +cdef extern from "src/core/lib/iomgr/resolve_address_custom.h": + struct grpc_custom_resolver: + pass + + struct grpc_custom_resolver_vtable: grpc_error* (*resolve)(const char* host, const char* port, grpc_resolved_addresses** res); void (*resolve_async)(grpc_custom_resolver* resolver, const char* host, const char* port); - - void grpc_custom_resolve_callback(grpc_custom_resolver* resolver, - grpc_resolved_addresses* result, - grpc_error* error); - -cdef extern from "src/core/lib/iomgr/tcp_custom.h": + + void grpc_custom_resolve_callback(grpc_custom_resolver* resolver, + grpc_resolved_addresses* result, + grpc_error* error); + +cdef extern from "src/core/lib/iomgr/tcp_custom.h": cdef int GRPC_CUSTOM_SOCKET_OPT_SO_REUSEPORT - struct grpc_custom_socket: - void* impl - # We don't care about the rest of the fields - ctypedef void (*grpc_custom_connect_callback)(grpc_custom_socket* socket, - grpc_error* error) - ctypedef void (*grpc_custom_write_callback)(grpc_custom_socket* socket, - grpc_error* error) - ctypedef void (*grpc_custom_read_callback)(grpc_custom_socket* socket, - size_t nread, grpc_error* error) - ctypedef void (*grpc_custom_accept_callback)(grpc_custom_socket* socket, - grpc_custom_socket* client, - grpc_error* error) - ctypedef void (*grpc_custom_close_callback)(grpc_custom_socket* socket) - - struct grpc_socket_vtable: - grpc_error* (*init)(grpc_custom_socket* socket, int domain); - void (*connect)(grpc_custom_socket* socket, const grpc_sockaddr* addr, - size_t len, grpc_custom_connect_callback cb); - void (*destroy)(grpc_custom_socket* socket); - void (*shutdown)(grpc_custom_socket* socket); - void (*close)(grpc_custom_socket* socket, grpc_custom_close_callback cb); - void (*write)(grpc_custom_socket* socket, grpc_slice_buffer* slices, - grpc_custom_write_callback cb); - void (*read)(grpc_custom_socket* socket, char* buffer, size_t length, - grpc_custom_read_callback cb); - grpc_error* (*getpeername)(grpc_custom_socket* socket, - const grpc_sockaddr* addr, int* len); - grpc_error* (*getsockname)(grpc_custom_socket* socket, - const grpc_sockaddr* addr, int* len); - grpc_error* (*bind)(grpc_custom_socket* socket, const grpc_sockaddr* addr, - size_t len, int flags); - grpc_error* (*listen)(grpc_custom_socket* socket); - void (*accept)(grpc_custom_socket* socket, grpc_custom_socket* client, - grpc_custom_accept_callback cb); - -cdef extern from "src/core/lib/iomgr/timer_custom.h": - struct grpc_custom_timer: - void* timer - int timeout_ms - # We don't care about the rest of the fields - - struct grpc_custom_timer_vtable: - void (*start)(grpc_custom_timer* t); - void (*stop)(grpc_custom_timer* t); - - void grpc_custom_timer_callback(grpc_custom_timer* t, grpc_error* error); - -cdef extern from "src/core/lib/iomgr/pollset_custom.h": - struct grpc_custom_poller_vtable: - void (*init)() - void (*poll)(size_t timeout_ms) - void (*kick)() - void (*shutdown)() - -cdef extern from "src/core/lib/iomgr/iomgr_custom.h": - void grpc_custom_iomgr_init(grpc_socket_vtable* socket, - grpc_custom_resolver_vtable* resolver, - grpc_custom_timer_vtable* timer, - grpc_custom_poller_vtable* poller); - -cdef extern from "src/core/lib/iomgr/sockaddr_utils.h": - int grpc_sockaddr_get_port(const grpc_resolved_address *addr); + struct grpc_custom_socket: + void* impl + # We don't care about the rest of the fields + ctypedef void (*grpc_custom_connect_callback)(grpc_custom_socket* socket, + grpc_error* error) + ctypedef void (*grpc_custom_write_callback)(grpc_custom_socket* socket, + grpc_error* error) + ctypedef void (*grpc_custom_read_callback)(grpc_custom_socket* socket, + size_t nread, grpc_error* error) + ctypedef void (*grpc_custom_accept_callback)(grpc_custom_socket* socket, + grpc_custom_socket* client, + grpc_error* error) + ctypedef void (*grpc_custom_close_callback)(grpc_custom_socket* socket) + + struct grpc_socket_vtable: + grpc_error* (*init)(grpc_custom_socket* socket, int domain); + void (*connect)(grpc_custom_socket* socket, const grpc_sockaddr* addr, + size_t len, grpc_custom_connect_callback cb); + void (*destroy)(grpc_custom_socket* socket); + void (*shutdown)(grpc_custom_socket* socket); + void (*close)(grpc_custom_socket* socket, grpc_custom_close_callback cb); + void (*write)(grpc_custom_socket* socket, grpc_slice_buffer* slices, + grpc_custom_write_callback cb); + void (*read)(grpc_custom_socket* socket, char* buffer, size_t length, + grpc_custom_read_callback cb); + grpc_error* (*getpeername)(grpc_custom_socket* socket, + const grpc_sockaddr* addr, int* len); + grpc_error* (*getsockname)(grpc_custom_socket* socket, + const grpc_sockaddr* addr, int* len); + grpc_error* (*bind)(grpc_custom_socket* socket, const grpc_sockaddr* addr, + size_t len, int flags); + grpc_error* (*listen)(grpc_custom_socket* socket); + void (*accept)(grpc_custom_socket* socket, grpc_custom_socket* client, + grpc_custom_accept_callback cb); + +cdef extern from "src/core/lib/iomgr/timer_custom.h": + struct grpc_custom_timer: + void* timer + int timeout_ms + # We don't care about the rest of the fields + + struct grpc_custom_timer_vtable: + void (*start)(grpc_custom_timer* t); + void (*stop)(grpc_custom_timer* t); + + void grpc_custom_timer_callback(grpc_custom_timer* t, grpc_error* error); + +cdef extern from "src/core/lib/iomgr/pollset_custom.h": + struct grpc_custom_poller_vtable: + void (*init)() + void (*poll)(size_t timeout_ms) + void (*kick)() + void (*shutdown)() + +cdef extern from "src/core/lib/iomgr/iomgr_custom.h": + void grpc_custom_iomgr_init(grpc_socket_vtable* socket, + grpc_custom_resolver_vtable* resolver, + grpc_custom_timer_vtable* timer, + grpc_custom_poller_vtable* poller); + +cdef extern from "src/core/lib/iomgr/sockaddr_utils.h": + int grpc_sockaddr_get_port(const grpc_resolved_address *addr); cppstring grpc_sockaddr_to_string(const grpc_resolved_address *addr, bool_t normalize); - void grpc_string_to_sockaddr(grpc_resolved_address *out, char* addr, int port); - int grpc_sockaddr_set_port(const grpc_resolved_address *resolved_addr, - int port) - const char* grpc_sockaddr_get_uri_scheme(const grpc_resolved_address* resolved_addr) + void grpc_string_to_sockaddr(grpc_resolved_address *out, char* addr, int port); + int grpc_sockaddr_set_port(const grpc_resolved_address *resolved_addr, + int port) + const char* grpc_sockaddr_get_uri_scheme(const grpc_resolved_address* resolved_addr) diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/iomgr.pyx.pxi b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/iomgr.pyx.pxi index 3d6bb24f9a..65d61cce38 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/iomgr.pyx.pxi +++ b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/iomgr.pyx.pxi @@ -1,63 +1,63 @@ -# Copyright 2019 gRPC authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# distutils: language=c++ - -from libc cimport string -from libc.stdlib cimport malloc +# Copyright 2019 gRPC authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# distutils: language=c++ + +from libc cimport string +from libc.stdlib cimport malloc from libcpp.string cimport string as cppstring - -cdef grpc_error* grpc_error_none(): - return <grpc_error*>0 - -cdef grpc_error* socket_error(str syscall, str err): - error_str = "{} failed: {}".format(syscall, err) - error_bytes = str_to_bytes(error_str) - return grpc_socket_error(error_bytes) - -cdef resolved_addr_to_tuple(grpc_resolved_address* address): + +cdef grpc_error* grpc_error_none(): + return <grpc_error*>0 + +cdef grpc_error* socket_error(str syscall, str err): + error_str = "{} failed: {}".format(syscall, err) + error_bytes = str_to_bytes(error_str) + return grpc_socket_error(error_bytes) + +cdef resolved_addr_to_tuple(grpc_resolved_address* address): cdef cppstring res_str - port = grpc_sockaddr_get_port(address) + port = grpc_sockaddr_get_port(address) res_str = grpc_sockaddr_to_string(address, False) byte_str = _decode(res_str) - if byte_str.endswith(':' + str(port)): - byte_str = byte_str[:(0 - len(str(port)) - 1)] - byte_str = byte_str.lstrip('[') - byte_str = byte_str.rstrip(']') - byte_str = '{}'.format(byte_str) - return byte_str, port - -cdef sockaddr_to_tuple(const grpc_sockaddr* address, size_t length): - cdef grpc_resolved_address c_addr - string.memcpy(<void*>c_addr.addr, <void*> address, length) - c_addr.len = length - return resolved_addr_to_tuple(&c_addr) - -cdef sockaddr_is_ipv4(const grpc_sockaddr* address, size_t length): - cdef grpc_resolved_address c_addr - string.memcpy(<void*>c_addr.addr, <void*> address, length) - c_addr.len = length - return grpc_sockaddr_get_uri_scheme(&c_addr) == b'ipv4' - -cdef grpc_resolved_addresses* tuples_to_resolvaddr(tups): - cdef grpc_resolved_addresses* addresses - tups_set = set((tup[4][0], tup[4][1]) for tup in tups) - addresses = <grpc_resolved_addresses*> malloc(sizeof(grpc_resolved_addresses)) - addresses.naddrs = len(tups_set) - addresses.addrs = <grpc_resolved_address*> malloc(sizeof(grpc_resolved_address) * len(tups_set)) - i = 0 - for tup in set(tups_set): - hostname = str_to_bytes(tup[0]) - grpc_string_to_sockaddr(&addresses.addrs[i], hostname, tup[1]) - i += 1 - return addresses + if byte_str.endswith(':' + str(port)): + byte_str = byte_str[:(0 - len(str(port)) - 1)] + byte_str = byte_str.lstrip('[') + byte_str = byte_str.rstrip(']') + byte_str = '{}'.format(byte_str) + return byte_str, port + +cdef sockaddr_to_tuple(const grpc_sockaddr* address, size_t length): + cdef grpc_resolved_address c_addr + string.memcpy(<void*>c_addr.addr, <void*> address, length) + c_addr.len = length + return resolved_addr_to_tuple(&c_addr) + +cdef sockaddr_is_ipv4(const grpc_sockaddr* address, size_t length): + cdef grpc_resolved_address c_addr + string.memcpy(<void*>c_addr.addr, <void*> address, length) + c_addr.len = length + return grpc_sockaddr_get_uri_scheme(&c_addr) == b'ipv4' + +cdef grpc_resolved_addresses* tuples_to_resolvaddr(tups): + cdef grpc_resolved_addresses* addresses + tups_set = set((tup[4][0], tup[4][1]) for tup in tups) + addresses = <grpc_resolved_addresses*> malloc(sizeof(grpc_resolved_addresses)) + addresses.naddrs = len(tups_set) + addresses.addrs = <grpc_resolved_address*> malloc(sizeof(grpc_resolved_address) * len(tups_set)) + i = 0 + for tup in set(tups_set): + hostname = str_to_bytes(tup[0]) + grpc_string_to_sockaddr(&addresses.addrs[i], hostname, tup[1]) + i += 1 + return addresses diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/records.pyx.pxi b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/records.pyx.pxi index 308d677695..9e1e6b3ba4 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/records.pyx.pxi +++ b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/records.pyx.pxi @@ -108,12 +108,12 @@ class OperationType: receive_status_on_client = GRPC_OP_RECV_STATUS_ON_CLIENT receive_close_on_server = GRPC_OP_RECV_CLOSE_ON_SERVER -GRPC_COMPRESSION_CHANNEL_DEFAULT_ALGORITHM= ( - _GRPC_COMPRESSION_CHANNEL_DEFAULT_ALGORITHM) - -GRPC_COMPRESSION_REQUEST_ALGORITHM_MD_KEY = ( - _GRPC_COMPRESSION_REQUEST_ALGORITHM_MD_KEY) +GRPC_COMPRESSION_CHANNEL_DEFAULT_ALGORITHM= ( + _GRPC_COMPRESSION_CHANNEL_DEFAULT_ALGORITHM) +GRPC_COMPRESSION_REQUEST_ALGORITHM_MD_KEY = ( + _GRPC_COMPRESSION_REQUEST_ALGORITHM_MD_KEY) + class CompressionAlgorithm: none = GRPC_COMPRESS_NONE deflate = GRPC_COMPRESS_DEFLATE @@ -137,7 +137,7 @@ cdef class CallDetails: def __dealloc__(self): with nogil: grpc_call_details_destroy(&self.c_details) - grpc_shutdown_blocking() + grpc_shutdown_blocking() @property def method(self): diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/server.pxd.pxi b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/server.pxd.pxi index b89ed99d97..8c777169cb 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/server.pxd.pxi +++ b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/server.pxd.pxi @@ -15,7 +15,7 @@ cdef class Server: cdef grpc_server *c_server - + cdef bint is_started # start has been called cdef bint is_shutting_down # shutdown has been called cdef bint is_shutdown # notification of complete shutdown received diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/server.pyx.pxi b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/server.pyx.pxi index eff95c4f29..306b779601 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/server.pyx.pxi +++ b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/server.pyx.pxi @@ -22,10 +22,10 @@ cdef class Server: self.is_started = False self.is_shutting_down = False self.is_shutdown = False - self.c_server = NULL - cdef _ChannelArgs channel_args = _ChannelArgs(arguments) - self.c_server = grpc_server_create(channel_args.c_args(), NULL) - self.references.append(arguments) + self.c_server = NULL + cdef _ChannelArgs channel_args = _ChannelArgs(arguments) + self.c_server = grpc_server_create(channel_args.c_args(), NULL) + self.references.append(arguments) def request_call( self, CompletionQueue call_queue not None, @@ -53,25 +53,25 @@ cdef class Server: self.c_server, queue.c_completion_queue, NULL) self.registered_completion_queues.append(queue) - def start(self, backup_queue=True): - """Start the Cython gRPC Server. - - Args: - backup_queue: a bool indicates whether to spawn a backup completion - queue. In the case that no CQ is bound to the server, and the shutdown - of server becomes un-observable. - """ + def start(self, backup_queue=True): + """Start the Cython gRPC Server. + + Args: + backup_queue: a bool indicates whether to spawn a backup completion + queue. In the case that no CQ is bound to the server, and the shutdown + of server becomes un-observable. + """ if self.is_started: raise ValueError("the server has already started") - if backup_queue: - self.backup_shutdown_queue = CompletionQueue(shutdown_cq=True) - self.register_completion_queue(self.backup_shutdown_queue) + if backup_queue: + self.backup_shutdown_queue = CompletionQueue(shutdown_cq=True) + self.register_completion_queue(self.backup_shutdown_queue) self.is_started = True with nogil: grpc_server_start(self.c_server) - if backup_queue: - # Ensure the core has gotten a chance to do the start-up work - self.backup_shutdown_queue.poll(deadline=time.time()) + if backup_queue: + # Ensure the core has gotten a chance to do the start-up work + self.backup_shutdown_queue.poll(deadline=time.time()) def add_http2_port(self, bytes address, ServerCredentials server_credentials=None): @@ -135,14 +135,14 @@ cdef class Server: elif self.is_shutdown: pass elif not self.is_shutting_down: - if self.backup_shutdown_queue is None: + if self.backup_shutdown_queue is None: raise InternalError('Server shutdown failed: no completion queue.') - else: - # the user didn't call shutdown - use our backup queue - self._c_shutdown(self.backup_shutdown_queue, None) - # and now we wait - while not self.is_shutdown: - self.backup_shutdown_queue.poll() + else: + # the user didn't call shutdown - use our backup queue + self._c_shutdown(self.backup_shutdown_queue, None) + # and now we wait + while not self.is_shutdown: + self.backup_shutdown_queue.poll() else: # We're in the process of shutting down, but have not shutdown; can't do # much but repeatedly release the GIL and wait @@ -154,4 +154,4 @@ cdef class Server: def __dealloc__(self): if self.c_server == NULL: - grpc_shutdown_blocking() + grpc_shutdown_blocking() diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/tag.pyx.pxi b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/tag.pyx.pxi index e80dc88767..e3cc059e65 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/tag.pyx.pxi +++ b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/tag.pyx.pxi @@ -56,19 +56,19 @@ cdef class _BatchOperationTag: self._retained_call = call cdef void prepare(self) except *: - cdef Operation operation + cdef Operation operation self.c_nops = 0 if self._operations is None else len(self._operations) if 0 < self.c_nops: self.c_ops = <grpc_op *>gpr_malloc(sizeof(grpc_op) * self.c_nops) for index, operation in enumerate(self._operations): - operation.c() - self.c_ops[index] = operation.c_op + operation.c() + self.c_ops[index] = operation.c_op cdef BatchOperationEvent event(self, grpc_event c_event): - cdef Operation operation + cdef Operation operation if 0 < self.c_nops: - for operation in self._operations: - operation.un_c() + for operation in self._operations: + operation.un_c() gpr_free(self.c_ops) return BatchOperationEvent( c_event.type, c_event.success, self._user_tag, self._operations) @@ -85,4 +85,4 @@ cdef class _ServerShutdownTag(_Tag): cdef ServerShutdownEvent event(self, grpc_event c_event): self._shutting_down_server.notify_shutdown_complete() - return ServerShutdownEvent(c_event.type, c_event.success, self._user_tag) + return ServerShutdownEvent(c_event.type, c_event.success, self._user_tag) diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/time.pxd.pxi b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/time.pxd.pxi index c46e8a98b0..f81ac229c3 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/time.pxd.pxi +++ b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/time.pxd.pxi @@ -13,7 +13,7 @@ # limitations under the License. -cdef gpr_timespec _timespec_from_time(object time) except * +cdef gpr_timespec _timespec_from_time(object time) except * cdef double _time_from_timespec(gpr_timespec timespec) except * diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/time.pyx.pxi b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/time.pyx.pxi index 6d181bb1d6..c8d1b6307e 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/time.pyx.pxi +++ b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/time.pyx.pxi @@ -13,17 +13,17 @@ # limitations under the License. -cdef gpr_timespec _timespec_from_time(object time) except *: +cdef gpr_timespec _timespec_from_time(object time) except *: if time is None: return gpr_inf_future(GPR_CLOCK_REALTIME) else: - return gpr_time_from_nanos( - <int64_t>(<double>time * GPR_NS_PER_SEC), - GPR_CLOCK_REALTIME, - ) + return gpr_time_from_nanos( + <int64_t>(<double>time * GPR_NS_PER_SEC), + GPR_CLOCK_REALTIME, + ) cdef double _time_from_timespec(gpr_timespec timespec) except *: cdef gpr_timespec real_timespec = gpr_convert_clock_type( timespec, GPR_CLOCK_REALTIME) - return gpr_timespec_to_micros(real_timespec) / GPR_US_PER_SEC + return gpr_timespec_to_micros(real_timespec) / GPR_US_PER_SEC diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/vtable.pxd.pxi b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/vtable.pxd.pxi index c96e5cb669..8d1f75064e 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/vtable.pxd.pxi +++ b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/vtable.pxd.pxi @@ -1,23 +1,23 @@ -# Copyright 2019 gRPC authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -cdef void* _copy_pointer(void* pointer) - -cdef void _destroy_pointer(void* pointer) - -cdef int _compare_pointer(void* first_pointer, void* second_pointer) - - -cdef grpc_arg_pointer_vtable default_vtable +# Copyright 2019 gRPC authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +cdef void* _copy_pointer(void* pointer) + +cdef void _destroy_pointer(void* pointer) + +cdef int _compare_pointer(void* first_pointer, void* second_pointer) + + +cdef grpc_arg_pointer_vtable default_vtable diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/vtable.pyx.pxi b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/vtable.pyx.pxi index da4b81bd97..71f927dcff 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/vtable.pyx.pxi +++ b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/vtable.pyx.pxi @@ -1,36 +1,36 @@ -# Copyright 2019 gRPC authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# TODO(https://github.com/grpc/grpc/issues/15662): Reform this. -cdef void* _copy_pointer(void* pointer): - return pointer - - -# TODO(https://github.com/grpc/grpc/issues/15662): Reform this. -cdef void _destroy_pointer(void* pointer): - pass - - -cdef int _compare_pointer(void* first_pointer, void* second_pointer): - if first_pointer < second_pointer: - return -1 - elif first_pointer > second_pointer: - return 1 - else: - return 0 - -cdef grpc_arg_pointer_vtable default_vtable -default_vtable.copy = &_copy_pointer -default_vtable.destroy = &_destroy_pointer -default_vtable.cmp = &_compare_pointer +# Copyright 2019 gRPC authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# TODO(https://github.com/grpc/grpc/issues/15662): Reform this. +cdef void* _copy_pointer(void* pointer): + return pointer + + +# TODO(https://github.com/grpc/grpc/issues/15662): Reform this. +cdef void _destroy_pointer(void* pointer): + pass + + +cdef int _compare_pointer(void* first_pointer, void* second_pointer): + if first_pointer < second_pointer: + return -1 + elif first_pointer > second_pointer: + return 1 + else: + return 0 + +cdef grpc_arg_pointer_vtable default_vtable +default_vtable.copy = &_copy_pointer +default_vtable.destroy = &_destroy_pointer +default_vtable.cmp = &_compare_pointer diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/cygrpc.pxd b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/cygrpc.pxd index 166be37022..a20909b5ae 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/cygrpc.pxd +++ b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/cygrpc.pxd @@ -25,30 +25,30 @@ include "_cygrpc/completion_queue.pxd.pxi" include "_cygrpc/event.pxd.pxi" include "_cygrpc/metadata.pxd.pxi" include "_cygrpc/operation.pxd.pxi" -include "_cygrpc/propagation_bits.pxd.pxi" +include "_cygrpc/propagation_bits.pxd.pxi" include "_cygrpc/records.pxd.pxi" include "_cygrpc/security.pxd.pxi" include "_cygrpc/server.pxd.pxi" include "_cygrpc/tag.pxd.pxi" include "_cygrpc/time.pxd.pxi" -include "_cygrpc/vtable.pxd.pxi" +include "_cygrpc/vtable.pxd.pxi" include "_cygrpc/_hooks.pxd.pxi" -include "_cygrpc/iomgr.pxd.pxi" - +include "_cygrpc/iomgr.pxd.pxi" + include "_cygrpc/grpc_gevent.pxd.pxi" IF UNAME_SYSNAME != "Windows": include "_cygrpc/fork_posix.pxd.pxi" - -# Following pxi files are part of the Aio module -include "_cygrpc/aio/iomgr/socket.pxd.pxi" -include "_cygrpc/aio/iomgr/timer.pxd.pxi" -include "_cygrpc/aio/iomgr/resolver.pxd.pxi" + +# Following pxi files are part of the Aio module +include "_cygrpc/aio/iomgr/socket.pxd.pxi" +include "_cygrpc/aio/iomgr/timer.pxd.pxi" +include "_cygrpc/aio/iomgr/resolver.pxd.pxi" include "_cygrpc/aio/completion_queue.pxd.pxi" include "_cygrpc/aio/rpc_status.pxd.pxi" -include "_cygrpc/aio/grpc_aio.pxd.pxi" -include "_cygrpc/aio/callback_common.pxd.pxi" -include "_cygrpc/aio/call.pxd.pxi" -include "_cygrpc/aio/channel.pxd.pxi" -include "_cygrpc/aio/server.pxd.pxi" +include "_cygrpc/aio/grpc_aio.pxd.pxi" +include "_cygrpc/aio/callback_common.pxd.pxi" +include "_cygrpc/aio/call.pxd.pxi" +include "_cygrpc/aio/channel.pxd.pxi" +include "_cygrpc/aio/server.pxd.pxi" diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/cygrpc.pyx b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/cygrpc.pyx index 8d355c6fbb..702a583461 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/cygrpc.pyx +++ b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/cygrpc.pyx @@ -23,13 +23,13 @@ import time import grpc -try: - import asyncio -except ImportError: - # TODO(https://github.com/grpc/grpc/issues/19728) Improve how Aio Cython is - # distributed without breaking none compatible Python versions. For now, if - # Asyncio package is not available we just skip it. - pass +try: + import asyncio +except ImportError: + # TODO(https://github.com/grpc/grpc/issues/19728) Improve how Aio Cython is + # distributed without breaking none compatible Python versions. For now, if + # Asyncio package is not available we just skip it. + pass # The only copy of Python logger for the Cython extension _LOGGER = logging.getLogger(__name__) @@ -40,23 +40,23 @@ include "_cygrpc/grpc_string.pyx.pxi" include "_cygrpc/arguments.pyx.pxi" include "_cygrpc/call.pyx.pxi" include "_cygrpc/channel.pyx.pxi" -include "_cygrpc/channelz.pyx.pxi" +include "_cygrpc/channelz.pyx.pxi" include "_cygrpc/credentials.pyx.pxi" include "_cygrpc/completion_queue.pyx.pxi" include "_cygrpc/event.pyx.pxi" include "_cygrpc/metadata.pyx.pxi" include "_cygrpc/operation.pyx.pxi" -include "_cygrpc/propagation_bits.pyx.pxi" +include "_cygrpc/propagation_bits.pyx.pxi" include "_cygrpc/records.pyx.pxi" include "_cygrpc/security.pyx.pxi" include "_cygrpc/server.pyx.pxi" include "_cygrpc/tag.pyx.pxi" include "_cygrpc/time.pyx.pxi" -include "_cygrpc/vtable.pyx.pxi" +include "_cygrpc/vtable.pyx.pxi" include "_cygrpc/_hooks.pyx.pxi" -include "_cygrpc/iomgr.pyx.pxi" - +include "_cygrpc/iomgr.pyx.pxi" + include "_cygrpc/grpc_gevent.pyx.pxi" include "_cygrpc/thread.pyx.pxi" @@ -66,21 +66,21 @@ IF UNAME_SYSNAME == "Windows": ELSE: include "_cygrpc/fork_posix.pyx.pxi" -# Following pxi files are part of the Aio module -include "_cygrpc/aio/iomgr/iomgr.pyx.pxi" -include "_cygrpc/aio/iomgr/socket.pyx.pxi" -include "_cygrpc/aio/iomgr/timer.pyx.pxi" -include "_cygrpc/aio/iomgr/resolver.pyx.pxi" +# Following pxi files are part of the Aio module +include "_cygrpc/aio/iomgr/iomgr.pyx.pxi" +include "_cygrpc/aio/iomgr/socket.pyx.pxi" +include "_cygrpc/aio/iomgr/timer.pyx.pxi" +include "_cygrpc/aio/iomgr/resolver.pyx.pxi" include "_cygrpc/aio/common.pyx.pxi" include "_cygrpc/aio/rpc_status.pyx.pxi" include "_cygrpc/aio/completion_queue.pyx.pxi" include "_cygrpc/aio/callback_common.pyx.pxi" -include "_cygrpc/aio/grpc_aio.pyx.pxi" -include "_cygrpc/aio/call.pyx.pxi" -include "_cygrpc/aio/channel.pyx.pxi" -include "_cygrpc/aio/server.pyx.pxi" - - +include "_cygrpc/aio/grpc_aio.pyx.pxi" +include "_cygrpc/aio/call.pyx.pxi" +include "_cygrpc/aio/channel.pyx.pxi" +include "_cygrpc/aio/server.pyx.pxi" + + # # initialize gRPC # diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/_interceptor.py b/contrib/libs/grpc/src/python/grpcio/grpc/_interceptor.py index ee63cb3145..4219be1548 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/_interceptor.py +++ b/contrib/libs/grpc/src/python/grpcio/grpc/_interceptor.py @@ -44,9 +44,9 @@ def service_pipeline(interceptors): class _ClientCallDetails( - collections.namedtuple('_ClientCallDetails', - ('method', 'timeout', 'metadata', 'credentials', - 'wait_for_ready', 'compression')), + collections.namedtuple('_ClientCallDetails', + ('method', 'timeout', 'metadata', 'credentials', + 'wait_for_ready', 'compression')), grpc.ClientCallDetails): pass @@ -77,16 +77,16 @@ def _unwrap_client_call_details(call_details, default_details): except AttributeError: wait_for_ready = default_details.wait_for_ready - try: - compression = call_details.compression - except AttributeError: - compression = default_details.compression - - return method, timeout, metadata, credentials, wait_for_ready, compression + try: + compression = call_details.compression + except AttributeError: + compression = default_details.compression + return method, timeout, metadata, credentials, wait_for_ready, compression -class _FailureOutcome(grpc.RpcError, grpc.Future, grpc.Call): # pylint: disable=too-many-ancestors +class _FailureOutcome(grpc.RpcError, grpc.Future, grpc.Call): # pylint: disable=too-many-ancestors + def __init__(self, exception, traceback): super(_FailureOutcome, self).__init__() self._exception = exception @@ -131,7 +131,7 @@ class _FailureOutcome(grpc.RpcError, grpc.Future, grpc.Call): # pylint: disable def traceback(self, ignored_timeout=None): return self._traceback - def add_callback(self, unused_callback): + def add_callback(self, unused_callback): return False def add_done_callback(self, fn): @@ -211,8 +211,8 @@ class _UnaryUnaryMultiCallable(grpc.UnaryUnaryMultiCallable): timeout=None, metadata=None, credentials=None, - wait_for_ready=None, - compression=None): + wait_for_ready=None, + compression=None): response, ignored_call = self._with_call(request, timeout=timeout, metadata=metadata, @@ -226,25 +226,25 @@ class _UnaryUnaryMultiCallable(grpc.UnaryUnaryMultiCallable): timeout=None, metadata=None, credentials=None, - wait_for_ready=None, - compression=None): - client_call_details = _ClientCallDetails(self._method, timeout, - metadata, credentials, - wait_for_ready, compression) + wait_for_ready=None, + compression=None): + client_call_details = _ClientCallDetails(self._method, timeout, + metadata, credentials, + wait_for_ready, compression) def continuation(new_details, request): - (new_method, new_timeout, new_metadata, new_credentials, - new_wait_for_ready, - new_compression) = (_unwrap_client_call_details( - new_details, client_call_details)) + (new_method, new_timeout, new_metadata, new_credentials, + new_wait_for_ready, + new_compression) = (_unwrap_client_call_details( + new_details, client_call_details)) try: response, call = self._thunk(new_method).with_call( request, timeout=new_timeout, metadata=new_metadata, credentials=new_credentials, - wait_for_ready=new_wait_for_ready, - compression=new_compression) + wait_for_ready=new_wait_for_ready, + compression=new_compression) return _UnaryOutcome(response, call) except grpc.RpcError as rpc_error: return rpc_error @@ -261,8 +261,8 @@ class _UnaryUnaryMultiCallable(grpc.UnaryUnaryMultiCallable): timeout=None, metadata=None, credentials=None, - wait_for_ready=None, - compression=None): + wait_for_ready=None, + compression=None): return self._with_call(request, timeout=timeout, metadata=metadata, @@ -275,24 +275,24 @@ class _UnaryUnaryMultiCallable(grpc.UnaryUnaryMultiCallable): timeout=None, metadata=None, credentials=None, - wait_for_ready=None, - compression=None): - client_call_details = _ClientCallDetails(self._method, timeout, - metadata, credentials, - wait_for_ready, compression) + wait_for_ready=None, + compression=None): + client_call_details = _ClientCallDetails(self._method, timeout, + metadata, credentials, + wait_for_ready, compression) def continuation(new_details, request): - (new_method, new_timeout, new_metadata, new_credentials, - new_wait_for_ready, - new_compression) = (_unwrap_client_call_details( - new_details, client_call_details)) + (new_method, new_timeout, new_metadata, new_credentials, + new_wait_for_ready, + new_compression) = (_unwrap_client_call_details( + new_details, client_call_details)) return self._thunk(new_method).future( request, timeout=new_timeout, metadata=new_metadata, credentials=new_credentials, - wait_for_ready=new_wait_for_ready, - compression=new_compression) + wait_for_ready=new_wait_for_ready, + compression=new_compression) try: return self._interceptor.intercept_unary_unary( @@ -313,17 +313,17 @@ class _UnaryStreamMultiCallable(grpc.UnaryStreamMultiCallable): timeout=None, metadata=None, credentials=None, - wait_for_ready=None, - compression=None): - client_call_details = _ClientCallDetails(self._method, timeout, - metadata, credentials, - wait_for_ready, compression) + wait_for_ready=None, + compression=None): + client_call_details = _ClientCallDetails(self._method, timeout, + metadata, credentials, + wait_for_ready, compression) def continuation(new_details, request): - (new_method, new_timeout, new_metadata, new_credentials, - new_wait_for_ready, - new_compression) = (_unwrap_client_call_details( - new_details, client_call_details)) + (new_method, new_timeout, new_metadata, new_credentials, + new_wait_for_ready, + new_compression) = (_unwrap_client_call_details( + new_details, client_call_details)) return self._thunk(new_method)(request, timeout=new_timeout, metadata=new_metadata, @@ -350,8 +350,8 @@ class _StreamUnaryMultiCallable(grpc.StreamUnaryMultiCallable): timeout=None, metadata=None, credentials=None, - wait_for_ready=None, - compression=None): + wait_for_ready=None, + compression=None): response, ignored_call = self._with_call(request_iterator, timeout=timeout, metadata=metadata, @@ -365,25 +365,25 @@ class _StreamUnaryMultiCallable(grpc.StreamUnaryMultiCallable): timeout=None, metadata=None, credentials=None, - wait_for_ready=None, - compression=None): - client_call_details = _ClientCallDetails(self._method, timeout, - metadata, credentials, - wait_for_ready, compression) + wait_for_ready=None, + compression=None): + client_call_details = _ClientCallDetails(self._method, timeout, + metadata, credentials, + wait_for_ready, compression) def continuation(new_details, request_iterator): - (new_method, new_timeout, new_metadata, new_credentials, - new_wait_for_ready, - new_compression) = (_unwrap_client_call_details( - new_details, client_call_details)) + (new_method, new_timeout, new_metadata, new_credentials, + new_wait_for_ready, + new_compression) = (_unwrap_client_call_details( + new_details, client_call_details)) try: response, call = self._thunk(new_method).with_call( request_iterator, timeout=new_timeout, metadata=new_metadata, credentials=new_credentials, - wait_for_ready=new_wait_for_ready, - compression=new_compression) + wait_for_ready=new_wait_for_ready, + compression=new_compression) return _UnaryOutcome(response, call) except grpc.RpcError as rpc_error: return rpc_error @@ -400,8 +400,8 @@ class _StreamUnaryMultiCallable(grpc.StreamUnaryMultiCallable): timeout=None, metadata=None, credentials=None, - wait_for_ready=None, - compression=None): + wait_for_ready=None, + compression=None): return self._with_call(request_iterator, timeout=timeout, metadata=metadata, @@ -414,24 +414,24 @@ class _StreamUnaryMultiCallable(grpc.StreamUnaryMultiCallable): timeout=None, metadata=None, credentials=None, - wait_for_ready=None, - compression=None): - client_call_details = _ClientCallDetails(self._method, timeout, - metadata, credentials, - wait_for_ready, compression) + wait_for_ready=None, + compression=None): + client_call_details = _ClientCallDetails(self._method, timeout, + metadata, credentials, + wait_for_ready, compression) def continuation(new_details, request_iterator): - (new_method, new_timeout, new_metadata, new_credentials, - new_wait_for_ready, - new_compression) = (_unwrap_client_call_details( - new_details, client_call_details)) + (new_method, new_timeout, new_metadata, new_credentials, + new_wait_for_ready, + new_compression) = (_unwrap_client_call_details( + new_details, client_call_details)) return self._thunk(new_method).future( request_iterator, timeout=new_timeout, metadata=new_metadata, credentials=new_credentials, - wait_for_ready=new_wait_for_ready, - compression=new_compression) + wait_for_ready=new_wait_for_ready, + compression=new_compression) try: return self._interceptor.intercept_stream_unary( @@ -452,17 +452,17 @@ class _StreamStreamMultiCallable(grpc.StreamStreamMultiCallable): timeout=None, metadata=None, credentials=None, - wait_for_ready=None, - compression=None): - client_call_details = _ClientCallDetails(self._method, timeout, - metadata, credentials, - wait_for_ready, compression) + wait_for_ready=None, + compression=None): + client_call_details = _ClientCallDetails(self._method, timeout, + metadata, credentials, + wait_for_ready, compression) def continuation(new_details, request_iterator): - (new_method, new_timeout, new_metadata, new_credentials, - new_wait_for_ready, - new_compression) = (_unwrap_client_call_details( - new_details, client_call_details)) + (new_method, new_timeout, new_metadata, new_credentials, + new_wait_for_ready, + new_compression) = (_unwrap_client_call_details( + new_details, client_call_details)) return self._thunk(new_method)(request_iterator, timeout=new_timeout, metadata=new_metadata, diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/_server.py b/contrib/libs/grpc/src/python/grpcio/grpc/_server.py index 48ff743995..d77bbf755d 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/_server.py +++ b/contrib/libs/grpc/src/python/grpcio/grpc/_server.py @@ -19,12 +19,12 @@ import logging import threading import time -from concurrent import futures +from concurrent import futures import six import grpc from grpc import _common -from grpc import _compression +from grpc import _compression from grpc import _interceptor from grpc._cython import cygrpc @@ -50,7 +50,7 @@ _CANCELLED = 'cancelled' _EMPTY_FLAGS = 0 _DEALLOCATED_SERVER_CHECK_PERIOD_S = 1.0 -_INF_TIMEOUT = 1e9 +_INF_TIMEOUT = 1e9 def _serialized_request(request_event): @@ -96,7 +96,7 @@ class _RPCState(object): self.request = None self.client = _OPEN self.initial_metadata_allowed = True - self.compression_algorithm = None + self.compression_algorithm = None self.disable_next_compression = False self.trailing_metadata = None self.code = None @@ -115,7 +115,7 @@ def _raise_rpc_error(state): def _possibly_finish_call(state, token): state.due.remove(token) - if not _is_rpc_state_active(state) and not state.due: + if not _is_rpc_state_active(state) and not state.due: callbacks = state.callbacks state.callbacks = None return state, callbacks @@ -132,33 +132,33 @@ def _send_status_from_server(state, token): return send_status_from_server -def _get_initial_metadata(state, metadata): - with state.condition: - if state.compression_algorithm: - compression_metadata = ( - _compression.compression_algorithm_to_metadata( - state.compression_algorithm),) - if metadata is None: - return compression_metadata - else: - return compression_metadata + tuple(metadata) - else: - return metadata - - -def _get_initial_metadata_operation(state, metadata): - operation = cygrpc.SendInitialMetadataOperation( - _get_initial_metadata(state, metadata), _EMPTY_FLAGS) - return operation - - +def _get_initial_metadata(state, metadata): + with state.condition: + if state.compression_algorithm: + compression_metadata = ( + _compression.compression_algorithm_to_metadata( + state.compression_algorithm),) + if metadata is None: + return compression_metadata + else: + return compression_metadata + tuple(metadata) + else: + return metadata + + +def _get_initial_metadata_operation(state, metadata): + operation = cygrpc.SendInitialMetadataOperation( + _get_initial_metadata(state, metadata), _EMPTY_FLAGS) + return operation + + def _abort(state, call, code, details): if state.client is not _CANCELLED: effective_code = _abortion_code(state, code) effective_details = details if state.details is None else state.details if state.initial_metadata_allowed: operations = ( - _get_initial_metadata_operation(state, None), + _get_initial_metadata_operation(state, None), cygrpc.SendStatusFromServerOperation(state.trailing_metadata, effective_code, effective_details, @@ -243,7 +243,7 @@ class _Context(grpc.ServicerContext): def is_active(self): with self._state.condition: - return _is_rpc_state_active(self._state) + return _is_rpc_state_active(self._state) def time_remaining(self): return max(self._rpc_event.call_details.deadline - time.time(), 0) @@ -282,18 +282,18 @@ class _Context(grpc.ServicerContext): cygrpc.auth_context(self._rpc_event.call)) } - def set_compression(self, compression): - with self._state.condition: - self._state.compression_algorithm = compression - + def set_compression(self, compression): + with self._state.condition: + self._state.compression_algorithm = compression + def send_initial_metadata(self, initial_metadata): with self._state.condition: if self._state.client is _CANCELLED: _raise_rpc_error(self._state) else: if self._state.initial_metadata_allowed: - operation = _get_initial_metadata_operation( - self._state, initial_metadata) + operation = _get_initial_metadata_operation( + self._state, initial_metadata) self._rpc_event.call.start_server_batch( (operation,), _send_initial_metadata(self._state)) self._state.initial_metadata_allowed = False @@ -330,10 +330,10 @@ class _Context(grpc.ServicerContext): with self._state.condition: self._state.details = _common.encode(details) - def _finalize_state(self): - pass - + def _finalize_state(self): + pass + class _RequestIterator(object): def __init__(self, state, call, request_deserializer): @@ -344,7 +344,7 @@ class _RequestIterator(object): def _raise_or_start_receive_message(self): if self._state.client is _CANCELLED: _raise_rpc_error(self._state) - elif not _is_rpc_state_active(self._state): + elif not _is_rpc_state_active(self._state): raise StopIteration() else: self._call.start_server_batch( @@ -389,7 +389,7 @@ def _unary_request(rpc_event, state, request_deserializer): def unary_request(): with state.condition: - if not _is_rpc_state_active(state): + if not _is_rpc_state_active(state): return None else: rpc_event.call.start_server_batch( @@ -417,35 +417,35 @@ def _unary_request(rpc_event, state, request_deserializer): return unary_request -def _call_behavior(rpc_event, - state, - behavior, - argument, - request_deserializer, - send_response_callback=None): - from grpc import _create_servicer_context - with _create_servicer_context(rpc_event, state, - request_deserializer) as context: - try: - response_or_iterator = None - if send_response_callback is not None: - response_or_iterator = behavior(argument, context, - send_response_callback) - else: - response_or_iterator = behavior(argument, context) - return response_or_iterator, True - except Exception as exception: # pylint: disable=broad-except - with state.condition: - if state.aborted: - _abort(state, rpc_event.call, cygrpc.StatusCode.unknown, - b'RPC Aborted') - elif exception not in state.rpc_errors: - details = 'Exception calling application: {}'.format( - exception) - _LOGGER.exception(details) - _abort(state, rpc_event.call, cygrpc.StatusCode.unknown, - _common.encode(details)) - return None, False +def _call_behavior(rpc_event, + state, + behavior, + argument, + request_deserializer, + send_response_callback=None): + from grpc import _create_servicer_context + with _create_servicer_context(rpc_event, state, + request_deserializer) as context: + try: + response_or_iterator = None + if send_response_callback is not None: + response_or_iterator = behavior(argument, context, + send_response_callback) + else: + response_or_iterator = behavior(argument, context) + return response_or_iterator, True + except Exception as exception: # pylint: disable=broad-except + with state.condition: + if state.aborted: + _abort(state, rpc_event.call, cygrpc.StatusCode.unknown, + b'RPC Aborted') + elif exception not in state.rpc_errors: + details = 'Exception calling application: {}'.format( + exception) + _LOGGER.exception(details) + _abort(state, rpc_event.call, cygrpc.StatusCode.unknown, + _common.encode(details)) + return None, False def _take_response_from_response_iterator(rpc_event, state, response_iterator): @@ -477,45 +477,45 @@ def _serialize_response(rpc_event, state, response, response_serializer): return serialized_response -def _get_send_message_op_flags_from_state(state): - if state.disable_next_compression: - return cygrpc.WriteFlag.no_compress - else: - return _EMPTY_FLAGS - - -def _reset_per_message_state(state): - with state.condition: - state.disable_next_compression = False - - +def _get_send_message_op_flags_from_state(state): + if state.disable_next_compression: + return cygrpc.WriteFlag.no_compress + else: + return _EMPTY_FLAGS + + +def _reset_per_message_state(state): + with state.condition: + state.disable_next_compression = False + + def _send_response(rpc_event, state, serialized_response): with state.condition: - if not _is_rpc_state_active(state): + if not _is_rpc_state_active(state): return False else: if state.initial_metadata_allowed: operations = ( - _get_initial_metadata_operation(state, None), - cygrpc.SendMessageOperation( - serialized_response, - _get_send_message_op_flags_from_state(state)), + _get_initial_metadata_operation(state, None), + cygrpc.SendMessageOperation( + serialized_response, + _get_send_message_op_flags_from_state(state)), ) state.initial_metadata_allowed = False token = _SEND_INITIAL_METADATA_AND_SEND_MESSAGE_TOKEN else: operations = (cygrpc.SendMessageOperation( - serialized_response, - _get_send_message_op_flags_from_state(state)),) + serialized_response, + _get_send_message_op_flags_from_state(state)),) token = _SEND_MESSAGE_TOKEN rpc_event.call.start_server_batch(operations, _send_message(state, token)) state.due.add(token) - _reset_per_message_state(state) + _reset_per_message_state(state) while True: state.condition.wait() if token not in state.due: - return _is_rpc_state_active(state) + return _is_rpc_state_active(state) def _status(rpc_event, state, serialized_response): @@ -529,23 +529,23 @@ def _status(rpc_event, state, serialized_response): _EMPTY_FLAGS), ] if state.initial_metadata_allowed: - operations.append(_get_initial_metadata_operation(state, None)) + operations.append(_get_initial_metadata_operation(state, None)) if serialized_response is not None: operations.append( - cygrpc.SendMessageOperation( - serialized_response, - _get_send_message_op_flags_from_state(state))) + cygrpc.SendMessageOperation( + serialized_response, + _get_send_message_op_flags_from_state(state))) rpc_event.call.start_server_batch( operations, _send_status_from_server(state, _SEND_STATUS_FROM_SERVER_TOKEN)) state.statused = True - _reset_per_message_state(state) + _reset_per_message_state(state) state.due.add(_SEND_STATUS_FROM_SERVER_TOKEN) def _unary_response_in_pool(rpc_event, state, behavior, argument_thunk, request_deserializer, response_serializer): - cygrpc.install_context_from_request_call_event(rpc_event) + cygrpc.install_context_from_request_call_event(rpc_event) try: argument = argument_thunk() if argument is not None: @@ -562,92 +562,92 @@ def _unary_response_in_pool(rpc_event, state, behavior, argument_thunk, def _stream_response_in_pool(rpc_event, state, behavior, argument_thunk, request_deserializer, response_serializer): - cygrpc.install_context_from_request_call_event(rpc_event) - - def send_response(response): - if response is None: - _status(rpc_event, state, None) - else: + cygrpc.install_context_from_request_call_event(rpc_event) + + def send_response(response): + if response is None: + _status(rpc_event, state, None) + else: serialized_response = _serialize_response(rpc_event, state, response, response_serializer) - if serialized_response is not None: - _send_response(rpc_event, state, serialized_response) - + if serialized_response is not None: + _send_response(rpc_event, state, serialized_response) + try: argument = argument_thunk() if argument is not None: - if hasattr(behavior, 'experimental_non_blocking' - ) and behavior.experimental_non_blocking: + if hasattr(behavior, 'experimental_non_blocking' + ) and behavior.experimental_non_blocking: _call_behavior(rpc_event, state, behavior, argument, request_deserializer, send_response_callback=send_response) - else: - response_iterator, proceed = _call_behavior( - rpc_event, state, behavior, argument, request_deserializer) - if proceed: - _send_message_callback_to_blocking_iterator_adapter( - rpc_event, state, send_response, response_iterator) + else: + response_iterator, proceed = _call_behavior( + rpc_event, state, behavior, argument, request_deserializer) + if proceed: + _send_message_callback_to_blocking_iterator_adapter( + rpc_event, state, send_response, response_iterator) finally: cygrpc.uninstall_context() -def _is_rpc_state_active(state): - return state.client is not _CANCELLED and not state.statused - - +def _is_rpc_state_active(state): + return state.client is not _CANCELLED and not state.statused + + def _send_message_callback_to_blocking_iterator_adapter(rpc_event, state, send_response_callback, response_iterator): - while True: - response, proceed = _take_response_from_response_iterator( - rpc_event, state, response_iterator) - if proceed: - send_response_callback(response) - if not _is_rpc_state_active(state): - break - else: - break - - -def _select_thread_pool_for_behavior(behavior, default_thread_pool): - if hasattr(behavior, 'experimental_thread_pool') and isinstance( - behavior.experimental_thread_pool, futures.ThreadPoolExecutor): - return behavior.experimental_thread_pool - else: - return default_thread_pool - - -def _handle_unary_unary(rpc_event, state, method_handler, default_thread_pool): + while True: + response, proceed = _take_response_from_response_iterator( + rpc_event, state, response_iterator) + if proceed: + send_response_callback(response) + if not _is_rpc_state_active(state): + break + else: + break + + +def _select_thread_pool_for_behavior(behavior, default_thread_pool): + if hasattr(behavior, 'experimental_thread_pool') and isinstance( + behavior.experimental_thread_pool, futures.ThreadPoolExecutor): + return behavior.experimental_thread_pool + else: + return default_thread_pool + + +def _handle_unary_unary(rpc_event, state, method_handler, default_thread_pool): unary_request = _unary_request(rpc_event, state, method_handler.request_deserializer) - thread_pool = _select_thread_pool_for_behavior(method_handler.unary_unary, - default_thread_pool) + thread_pool = _select_thread_pool_for_behavior(method_handler.unary_unary, + default_thread_pool) return thread_pool.submit(_unary_response_in_pool, rpc_event, state, method_handler.unary_unary, unary_request, method_handler.request_deserializer, method_handler.response_serializer) -def _handle_unary_stream(rpc_event, state, method_handler, default_thread_pool): +def _handle_unary_stream(rpc_event, state, method_handler, default_thread_pool): unary_request = _unary_request(rpc_event, state, method_handler.request_deserializer) - thread_pool = _select_thread_pool_for_behavior(method_handler.unary_stream, - default_thread_pool) + thread_pool = _select_thread_pool_for_behavior(method_handler.unary_stream, + default_thread_pool) return thread_pool.submit(_stream_response_in_pool, rpc_event, state, method_handler.unary_stream, unary_request, method_handler.request_deserializer, method_handler.response_serializer) -def _handle_stream_unary(rpc_event, state, method_handler, default_thread_pool): +def _handle_stream_unary(rpc_event, state, method_handler, default_thread_pool): request_iterator = _RequestIterator(state, rpc_event.call, method_handler.request_deserializer) - thread_pool = _select_thread_pool_for_behavior(method_handler.stream_unary, - default_thread_pool) + thread_pool = _select_thread_pool_for_behavior(method_handler.stream_unary, + default_thread_pool) return thread_pool.submit(_unary_response_in_pool, rpc_event, state, method_handler.stream_unary, lambda: request_iterator, @@ -655,12 +655,12 @@ def _handle_stream_unary(rpc_event, state, method_handler, default_thread_pool): method_handler.response_serializer) -def _handle_stream_stream(rpc_event, state, method_handler, - default_thread_pool): +def _handle_stream_stream(rpc_event, state, method_handler, + default_thread_pool): request_iterator = _RequestIterator(state, rpc_event.call, method_handler.request_deserializer) - thread_pool = _select_thread_pool_for_behavior(method_handler.stream_stream, - default_thread_pool) + thread_pool = _select_thread_pool_for_behavior(method_handler.stream_stream, + default_thread_pool) return thread_pool.submit(_stream_response_in_pool, rpc_event, state, method_handler.stream_stream, lambda: request_iterator, @@ -689,9 +689,9 @@ def _find_method_handler(rpc_event, generic_handlers, interceptor_pipeline): def _reject_rpc(rpc_event, status, details): - rpc_state = _RPCState() + rpc_state = _RPCState() operations = ( - _get_initial_metadata_operation(rpc_state, None), + _get_initial_metadata_operation(rpc_state, None), cygrpc.ReceiveCloseOnServerOperation(_EMPTY_FLAGS), cygrpc.SendStatusFromServerOperation(None, status, details, _EMPTY_FLAGS), @@ -771,8 +771,8 @@ class _ServerState(object): self.interceptor_pipeline = interceptor_pipeline self.thread_pool = thread_pool self.stage = _ServerStage.STOPPED - self.termination_event = threading.Event() - self.shutdown_events = [self.termination_event] + self.termination_event = threading.Event() + self.shutdown_events = [self.termination_event] self.maximum_concurrent_rpcs = maximum_concurrent_rpcs self.active_rpc_count = 0 @@ -936,18 +936,18 @@ def _validate_generic_rpc_handlers(generic_rpc_handlers): 'not have "service" method!'.format(generic_rpc_handler)) -def _augment_options(base_options, compression): - compression_option = _compression.create_channel_option(compression) - return tuple(base_options) + compression_option - - +def _augment_options(base_options, compression): + compression_option = _compression.create_channel_option(compression) + return tuple(base_options) + compression_option + + class _Server(grpc.Server): # pylint: disable=too-many-arguments def __init__(self, thread_pool, generic_handlers, interceptors, options, - maximum_concurrent_rpcs, compression): + maximum_concurrent_rpcs, compression): completion_queue = cygrpc.CompletionQueue() - server = cygrpc.Server(_augment_options(options, compression)) + server = cygrpc.Server(_augment_options(options, compression)) server.register_completion_queue(completion_queue) self._state = _ServerState(completion_queue, server, generic_handlers, _interceptor.service_pipeline(interceptors), @@ -970,14 +970,14 @@ class _Server(grpc.Server): def start(self): _start(self._state) - def wait_for_termination(self, timeout=None): - # NOTE(https://bugs.python.org/issue35935) - # Remove this workaround once threading.Event.wait() is working with - # CTRL+C across platforms. + def wait_for_termination(self, timeout=None): + # NOTE(https://bugs.python.org/issue35935) + # Remove this workaround once threading.Event.wait() is working with + # CTRL+C across platforms. return _common.wait(self._state.termination_event.wait, self._state.termination_event.is_set, timeout=timeout) - + def stop(self, grace): return _stop(self._state, grace) @@ -989,7 +989,7 @@ class _Server(grpc.Server): def create_server(thread_pool, generic_rpc_handlers, interceptors, options, - maximum_concurrent_rpcs, compression): + maximum_concurrent_rpcs, compression): _validate_generic_rpc_handlers(generic_rpc_handlers) return _Server(thread_pool, generic_rpc_handlers, interceptors, options, - maximum_concurrent_rpcs, compression) + maximum_concurrent_rpcs, compression) diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/experimental/__init__.py b/contrib/libs/grpc/src/python/grpcio/grpc/experimental/__init__.py index a4e2660fb4..7814f49a1a 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/experimental/__init__.py +++ b/contrib/libs/grpc/src/python/grpcio/grpc/experimental/__init__.py @@ -15,30 +15,30 @@ These APIs are subject to be removed during any minor version release. """ - + import copy import functools import sys import warnings - + import grpc _EXPERIMENTAL_APIS_USED = set() -class ChannelOptions(object): - """Indicates a channel option unique to gRPC Python. - - This enumeration is part of an EXPERIMENTAL API. - - Attributes: - SingleThreadedUnaryStream: Perform unary-stream RPCs on a single thread. - """ - SingleThreadedUnaryStream = "SingleThreadedUnaryStream" - - -class UsageError(Exception): - """Raised by the gRPC library to indicate usage not allowed by the API.""" +class ChannelOptions(object): + """Indicates a channel option unique to gRPC Python. + + This enumeration is part of an EXPERIMENTAL API. + + Attributes: + SingleThreadedUnaryStream: Perform unary-stream RPCs on a single thread. + """ + SingleThreadedUnaryStream = "SingleThreadedUnaryStream" + + +class UsageError(Exception): + """Raised by the gRPC library to indicate usage not allowed by the API.""" _insecure_channel_credentials_sentinel = object() diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/experimental/aio/__init__.py b/contrib/libs/grpc/src/python/grpcio/grpc/experimental/aio/__init__.py index 576cb8dcde..bdfcd76b2f 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/experimental/aio/__init__.py +++ b/contrib/libs/grpc/src/python/grpcio/grpc/experimental/aio/__init__.py @@ -1,16 +1,16 @@ # Copyright 2020 The gRPC Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. """Alias of grpc.aio to keep backward compatibility.""" - + from grpc.aio import * diff --git a/contrib/libs/grpc/src/python/grpcio/grpc_core_dependencies.py b/contrib/libs/grpc/src/python/grpcio/grpc_core_dependencies.py index 67f985e1f4..424a6751d2 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc_core_dependencies.py +++ b/contrib/libs/grpc/src/python/grpcio/grpc_core_dependencies.py @@ -15,112 +15,112 @@ # AUTO-GENERATED FROM `$REPO_ROOT/templates/src/python/grpcio/grpc_core_dependencies.py.template`!!! CORE_SOURCE_FILES = [ - 'src/core/ext/filters/census/grpc_context.cc', - 'src/core/ext/filters/client_channel/backend_metric.cc', - 'src/core/ext/filters/client_channel/backup_poller.cc', - 'src/core/ext/filters/client_channel/channel_connectivity.cc', - 'src/core/ext/filters/client_channel/client_channel.cc', - 'src/core/ext/filters/client_channel/client_channel_channelz.cc', - 'src/core/ext/filters/client_channel/client_channel_factory.cc', - 'src/core/ext/filters/client_channel/client_channel_plugin.cc', + 'src/core/ext/filters/census/grpc_context.cc', + 'src/core/ext/filters/client_channel/backend_metric.cc', + 'src/core/ext/filters/client_channel/backup_poller.cc', + 'src/core/ext/filters/client_channel/channel_connectivity.cc', + 'src/core/ext/filters/client_channel/client_channel.cc', + 'src/core/ext/filters/client_channel/client_channel_channelz.cc', + 'src/core/ext/filters/client_channel/client_channel_factory.cc', + 'src/core/ext/filters/client_channel/client_channel_plugin.cc', 'src/core/ext/filters/client_channel/config_selector.cc', - 'src/core/ext/filters/client_channel/global_subchannel_pool.cc', - 'src/core/ext/filters/client_channel/health/health_check_client.cc', - 'src/core/ext/filters/client_channel/http_connect_handshaker.cc', - 'src/core/ext/filters/client_channel/http_proxy.cc', - 'src/core/ext/filters/client_channel/lb_policy.cc', + 'src/core/ext/filters/client_channel/global_subchannel_pool.cc', + 'src/core/ext/filters/client_channel/health/health_check_client.cc', + 'src/core/ext/filters/client_channel/http_connect_handshaker.cc', + 'src/core/ext/filters/client_channel/http_proxy.cc', + 'src/core/ext/filters/client_channel/lb_policy.cc', 'src/core/ext/filters/client_channel/lb_policy/address_filtering.cc', 'src/core/ext/filters/client_channel/lb_policy/child_policy_handler.cc', - 'src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc', - 'src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc', + 'src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc', + 'src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc', 'src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_balancer_addresses.cc', - 'src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc', - 'src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.cc', - 'src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc', - 'src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc', + 'src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc', + 'src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.cc', + 'src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc', + 'src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc', 'src/core/ext/filters/client_channel/lb_policy/priority/priority.cc', - 'src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc', + 'src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc', 'src/core/ext/filters/client_channel/lb_policy/weighted_target/weighted_target.cc', - 'src/core/ext/filters/client_channel/lb_policy/xds/cds.cc', + 'src/core/ext/filters/client_channel/lb_policy/xds/cds.cc', 'src/core/ext/filters/client_channel/lb_policy/xds/eds.cc', 'src/core/ext/filters/client_channel/lb_policy/xds/eds_drop.cc', 'src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_manager.cc', - 'src/core/ext/filters/client_channel/lb_policy_registry.cc', - 'src/core/ext/filters/client_channel/local_subchannel_pool.cc', - 'src/core/ext/filters/client_channel/proxy_mapper_registry.cc', - 'src/core/ext/filters/client_channel/resolver.cc', - 'src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc', - 'src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.cc', - 'src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_libuv.cc', - 'src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc', - 'src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc', - 'src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc', - 'src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_fallback.cc', - 'src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_libuv.cc', - 'src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_posix.cc', - 'src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc', - 'src/core/ext/filters/client_channel/resolver/dns/dns_resolver_selection.cc', - 'src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc', - 'src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc', - 'src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc', - 'src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc', - 'src/core/ext/filters/client_channel/resolver_registry.cc', - 'src/core/ext/filters/client_channel/resolver_result_parsing.cc', - 'src/core/ext/filters/client_channel/resolving_lb_policy.cc', - 'src/core/ext/filters/client_channel/retry_throttle.cc', - 'src/core/ext/filters/client_channel/server_address.cc', - 'src/core/ext/filters/client_channel/service_config.cc', + 'src/core/ext/filters/client_channel/lb_policy_registry.cc', + 'src/core/ext/filters/client_channel/local_subchannel_pool.cc', + 'src/core/ext/filters/client_channel/proxy_mapper_registry.cc', + 'src/core/ext/filters/client_channel/resolver.cc', + 'src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc', + 'src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.cc', + 'src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_libuv.cc', + 'src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc', + 'src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc', + 'src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc', + 'src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_fallback.cc', + 'src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_libuv.cc', + 'src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_posix.cc', + 'src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc', + 'src/core/ext/filters/client_channel/resolver/dns/dns_resolver_selection.cc', + 'src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc', + 'src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc', + 'src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc', + 'src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc', + 'src/core/ext/filters/client_channel/resolver_registry.cc', + 'src/core/ext/filters/client_channel/resolver_result_parsing.cc', + 'src/core/ext/filters/client_channel/resolving_lb_policy.cc', + 'src/core/ext/filters/client_channel/retry_throttle.cc', + 'src/core/ext/filters/client_channel/server_address.cc', + 'src/core/ext/filters/client_channel/service_config.cc', 'src/core/ext/filters/client_channel/service_config_channel_arg_filter.cc', 'src/core/ext/filters/client_channel/service_config_parser.cc', - 'src/core/ext/filters/client_channel/subchannel.cc', - 'src/core/ext/filters/client_channel/subchannel_pool_interface.cc', - 'src/core/ext/filters/client_idle/client_idle_filter.cc', - 'src/core/ext/filters/deadline/deadline_filter.cc', - 'src/core/ext/filters/http/client/http_client_filter.cc', - 'src/core/ext/filters/http/client_authority_filter.cc', - 'src/core/ext/filters/http/http_filters_plugin.cc', - 'src/core/ext/filters/http/message_compress/message_compress_filter.cc', + 'src/core/ext/filters/client_channel/subchannel.cc', + 'src/core/ext/filters/client_channel/subchannel_pool_interface.cc', + 'src/core/ext/filters/client_idle/client_idle_filter.cc', + 'src/core/ext/filters/deadline/deadline_filter.cc', + 'src/core/ext/filters/http/client/http_client_filter.cc', + 'src/core/ext/filters/http/client_authority_filter.cc', + 'src/core/ext/filters/http/http_filters_plugin.cc', + 'src/core/ext/filters/http/message_compress/message_compress_filter.cc', 'src/core/ext/filters/http/message_compress/message_decompress_filter.cc', - 'src/core/ext/filters/http/server/http_server_filter.cc', - 'src/core/ext/filters/max_age/max_age_filter.cc', - 'src/core/ext/filters/message_size/message_size_filter.cc', - 'src/core/ext/filters/workarounds/workaround_cronet_compression_filter.cc', - 'src/core/ext/filters/workarounds/workaround_utils.cc', - 'src/core/ext/transport/chttp2/alpn/alpn.cc', - 'src/core/ext/transport/chttp2/client/authority.cc', - 'src/core/ext/transport/chttp2/client/chttp2_connector.cc', - 'src/core/ext/transport/chttp2/client/insecure/channel_create.cc', - 'src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc', - 'src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc', - 'src/core/ext/transport/chttp2/server/chttp2_server.cc', - 'src/core/ext/transport/chttp2/server/insecure/server_chttp2.cc', - 'src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc', - 'src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.cc', - 'src/core/ext/transport/chttp2/transport/bin_decoder.cc', - 'src/core/ext/transport/chttp2/transport/bin_encoder.cc', - 'src/core/ext/transport/chttp2/transport/chttp2_plugin.cc', - 'src/core/ext/transport/chttp2/transport/chttp2_transport.cc', - 'src/core/ext/transport/chttp2/transport/context_list.cc', - 'src/core/ext/transport/chttp2/transport/flow_control.cc', - 'src/core/ext/transport/chttp2/transport/frame_data.cc', - 'src/core/ext/transport/chttp2/transport/frame_goaway.cc', - 'src/core/ext/transport/chttp2/transport/frame_ping.cc', - 'src/core/ext/transport/chttp2/transport/frame_rst_stream.cc', - 'src/core/ext/transport/chttp2/transport/frame_settings.cc', - 'src/core/ext/transport/chttp2/transport/frame_window_update.cc', - 'src/core/ext/transport/chttp2/transport/hpack_encoder.cc', - 'src/core/ext/transport/chttp2/transport/hpack_parser.cc', - 'src/core/ext/transport/chttp2/transport/hpack_table.cc', - 'src/core/ext/transport/chttp2/transport/http2_settings.cc', - 'src/core/ext/transport/chttp2/transport/huffsyms.cc', - 'src/core/ext/transport/chttp2/transport/incoming_metadata.cc', - 'src/core/ext/transport/chttp2/transport/parsing.cc', - 'src/core/ext/transport/chttp2/transport/stream_lists.cc', - 'src/core/ext/transport/chttp2/transport/stream_map.cc', - 'src/core/ext/transport/chttp2/transport/varint.cc', - 'src/core/ext/transport/chttp2/transport/writing.cc', - 'src/core/ext/transport/inproc/inproc_plugin.cc', - 'src/core/ext/transport/inproc/inproc_transport.cc', + 'src/core/ext/filters/http/server/http_server_filter.cc', + 'src/core/ext/filters/max_age/max_age_filter.cc', + 'src/core/ext/filters/message_size/message_size_filter.cc', + 'src/core/ext/filters/workarounds/workaround_cronet_compression_filter.cc', + 'src/core/ext/filters/workarounds/workaround_utils.cc', + 'src/core/ext/transport/chttp2/alpn/alpn.cc', + 'src/core/ext/transport/chttp2/client/authority.cc', + 'src/core/ext/transport/chttp2/client/chttp2_connector.cc', + 'src/core/ext/transport/chttp2/client/insecure/channel_create.cc', + 'src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc', + 'src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc', + 'src/core/ext/transport/chttp2/server/chttp2_server.cc', + 'src/core/ext/transport/chttp2/server/insecure/server_chttp2.cc', + 'src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc', + 'src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.cc', + 'src/core/ext/transport/chttp2/transport/bin_decoder.cc', + 'src/core/ext/transport/chttp2/transport/bin_encoder.cc', + 'src/core/ext/transport/chttp2/transport/chttp2_plugin.cc', + 'src/core/ext/transport/chttp2/transport/chttp2_transport.cc', + 'src/core/ext/transport/chttp2/transport/context_list.cc', + 'src/core/ext/transport/chttp2/transport/flow_control.cc', + 'src/core/ext/transport/chttp2/transport/frame_data.cc', + 'src/core/ext/transport/chttp2/transport/frame_goaway.cc', + 'src/core/ext/transport/chttp2/transport/frame_ping.cc', + 'src/core/ext/transport/chttp2/transport/frame_rst_stream.cc', + 'src/core/ext/transport/chttp2/transport/frame_settings.cc', + 'src/core/ext/transport/chttp2/transport/frame_window_update.cc', + 'src/core/ext/transport/chttp2/transport/hpack_encoder.cc', + 'src/core/ext/transport/chttp2/transport/hpack_parser.cc', + 'src/core/ext/transport/chttp2/transport/hpack_table.cc', + 'src/core/ext/transport/chttp2/transport/http2_settings.cc', + 'src/core/ext/transport/chttp2/transport/huffsyms.cc', + 'src/core/ext/transport/chttp2/transport/incoming_metadata.cc', + 'src/core/ext/transport/chttp2/transport/parsing.cc', + 'src/core/ext/transport/chttp2/transport/stream_lists.cc', + 'src/core/ext/transport/chttp2/transport/stream_map.cc', + 'src/core/ext/transport/chttp2/transport/varint.cc', + 'src/core/ext/transport/chttp2/transport/writing.cc', + 'src/core/ext/transport/inproc/inproc_plugin.cc', + 'src/core/ext/transport/inproc/inproc_transport.cc', 'src/core/ext/upb-generated/envoy/annotations/deprecation.upb.c', 'src/core/ext/upb-generated/envoy/annotations/resource.upb.c', 'src/core/ext/upb-generated/envoy/config/accesslog/v3/accesslog.upb.c', @@ -178,23 +178,23 @@ CORE_SOURCE_FILES = [ 'src/core/ext/upb-generated/envoy/type/v3/percent.upb.c', 'src/core/ext/upb-generated/envoy/type/v3/range.upb.c', 'src/core/ext/upb-generated/envoy/type/v3/semantic_version.upb.c', - 'src/core/ext/upb-generated/google/api/annotations.upb.c', + 'src/core/ext/upb-generated/google/api/annotations.upb.c', 'src/core/ext/upb-generated/google/api/expr/v1alpha1/checked.upb.c', 'src/core/ext/upb-generated/google/api/expr/v1alpha1/syntax.upb.c', - 'src/core/ext/upb-generated/google/api/http.upb.c', - 'src/core/ext/upb-generated/google/protobuf/any.upb.c', - 'src/core/ext/upb-generated/google/protobuf/descriptor.upb.c', - 'src/core/ext/upb-generated/google/protobuf/duration.upb.c', - 'src/core/ext/upb-generated/google/protobuf/empty.upb.c', - 'src/core/ext/upb-generated/google/protobuf/struct.upb.c', - 'src/core/ext/upb-generated/google/protobuf/timestamp.upb.c', - 'src/core/ext/upb-generated/google/protobuf/wrappers.upb.c', - 'src/core/ext/upb-generated/google/rpc/status.upb.c', - 'src/core/ext/upb-generated/src/proto/grpc/gcp/altscontext.upb.c', - 'src/core/ext/upb-generated/src/proto/grpc/gcp/handshaker.upb.c', - 'src/core/ext/upb-generated/src/proto/grpc/gcp/transport_security_common.upb.c', - 'src/core/ext/upb-generated/src/proto/grpc/health/v1/health.upb.c', - 'src/core/ext/upb-generated/src/proto/grpc/lb/v1/load_balancer.upb.c', + 'src/core/ext/upb-generated/google/api/http.upb.c', + 'src/core/ext/upb-generated/google/protobuf/any.upb.c', + 'src/core/ext/upb-generated/google/protobuf/descriptor.upb.c', + 'src/core/ext/upb-generated/google/protobuf/duration.upb.c', + 'src/core/ext/upb-generated/google/protobuf/empty.upb.c', + 'src/core/ext/upb-generated/google/protobuf/struct.upb.c', + 'src/core/ext/upb-generated/google/protobuf/timestamp.upb.c', + 'src/core/ext/upb-generated/google/protobuf/wrappers.upb.c', + 'src/core/ext/upb-generated/google/rpc/status.upb.c', + 'src/core/ext/upb-generated/src/proto/grpc/gcp/altscontext.upb.c', + 'src/core/ext/upb-generated/src/proto/grpc/gcp/handshaker.upb.c', + 'src/core/ext/upb-generated/src/proto/grpc/gcp/transport_security_common.upb.c', + 'src/core/ext/upb-generated/src/proto/grpc/health/v1/health.upb.c', + 'src/core/ext/upb-generated/src/proto/grpc/lb/v1/load_balancer.upb.c', 'src/core/ext/upb-generated/udpa/annotations/migrate.upb.c', 'src/core/ext/upb-generated/udpa/annotations/security.upb.c', 'src/core/ext/upb-generated/udpa/annotations/sensitive.upb.c', @@ -206,36 +206,36 @@ CORE_SOURCE_FILES = [ 'src/core/ext/upb-generated/udpa/core/v1/resource.upb.c', 'src/core/ext/upb-generated/udpa/core/v1/resource_locator.upb.c', 'src/core/ext/upb-generated/udpa/core/v1/resource_name.upb.c', - 'src/core/ext/upb-generated/udpa/data/orca/v1/orca_load_report.upb.c', - 'src/core/ext/upb-generated/validate/validate.upb.c', + 'src/core/ext/upb-generated/udpa/data/orca/v1/orca_load_report.upb.c', + 'src/core/ext/upb-generated/validate/validate.upb.c', 'src/core/ext/xds/certificate_provider_registry.cc', 'src/core/ext/xds/google_mesh_ca_certificate_provider_factory.cc', 'src/core/ext/xds/xds_api.cc', 'src/core/ext/xds/xds_bootstrap.cc', 'src/core/ext/xds/xds_client.cc', 'src/core/ext/xds/xds_client_stats.cc', - 'src/core/lib/avl/avl.cc', - 'src/core/lib/backoff/backoff.cc', - 'src/core/lib/channel/channel_args.cc', - 'src/core/lib/channel/channel_stack.cc', - 'src/core/lib/channel/channel_stack_builder.cc', - 'src/core/lib/channel/channel_trace.cc', - 'src/core/lib/channel/channelz.cc', - 'src/core/lib/channel/channelz_registry.cc', - 'src/core/lib/channel/connected_channel.cc', - 'src/core/lib/channel/handshaker.cc', - 'src/core/lib/channel/handshaker_registry.cc', - 'src/core/lib/channel/status_util.cc', - 'src/core/lib/compression/compression.cc', - 'src/core/lib/compression/compression_args.cc', - 'src/core/lib/compression/compression_internal.cc', - 'src/core/lib/compression/message_compress.cc', - 'src/core/lib/compression/stream_compression.cc', - 'src/core/lib/compression/stream_compression_gzip.cc', - 'src/core/lib/compression/stream_compression_identity.cc', - 'src/core/lib/debug/stats.cc', - 'src/core/lib/debug/stats_data.cc', - 'src/core/lib/debug/trace.cc', + 'src/core/lib/avl/avl.cc', + 'src/core/lib/backoff/backoff.cc', + 'src/core/lib/channel/channel_args.cc', + 'src/core/lib/channel/channel_stack.cc', + 'src/core/lib/channel/channel_stack_builder.cc', + 'src/core/lib/channel/channel_trace.cc', + 'src/core/lib/channel/channelz.cc', + 'src/core/lib/channel/channelz_registry.cc', + 'src/core/lib/channel/connected_channel.cc', + 'src/core/lib/channel/handshaker.cc', + 'src/core/lib/channel/handshaker_registry.cc', + 'src/core/lib/channel/status_util.cc', + 'src/core/lib/compression/compression.cc', + 'src/core/lib/compression/compression_args.cc', + 'src/core/lib/compression/compression_internal.cc', + 'src/core/lib/compression/message_compress.cc', + 'src/core/lib/compression/stream_compression.cc', + 'src/core/lib/compression/stream_compression_gzip.cc', + 'src/core/lib/compression/stream_compression_identity.cc', + 'src/core/lib/debug/stats.cc', + 'src/core/lib/debug/stats_data.cc', + 'src/core/lib/debug/trace.cc', 'src/core/lib/gpr/alloc.cc', 'src/core/lib/gpr/atm.cc', 'src/core/lib/gpr/cpu_iphone.cc', @@ -268,29 +268,29 @@ CORE_SOURCE_FILES = [ 'src/core/lib/gpr/tmpfile_posix.cc', 'src/core/lib/gpr/tmpfile_windows.cc', 'src/core/lib/gpr/wrap_memcpy.cc', - 'src/core/lib/gprpp/arena.cc', + 'src/core/lib/gprpp/arena.cc', 'src/core/lib/gprpp/fork.cc', - 'src/core/lib/gprpp/global_config_env.cc', - 'src/core/lib/gprpp/host_port.cc', - 'src/core/lib/gprpp/mpscq.cc', + 'src/core/lib/gprpp/global_config_env.cc', + 'src/core/lib/gprpp/host_port.cc', + 'src/core/lib/gprpp/mpscq.cc', 'src/core/lib/gprpp/thd_posix.cc', 'src/core/lib/gprpp/thd_windows.cc', 'src/core/lib/http/format_request.cc', 'src/core/lib/http/httpcli.cc', - 'src/core/lib/http/httpcli_security_connector.cc', + 'src/core/lib/http/httpcli_security_connector.cc', 'src/core/lib/http/parser.cc', 'src/core/lib/iomgr/buffer_list.cc', 'src/core/lib/iomgr/call_combiner.cc', - 'src/core/lib/iomgr/cfstream_handle.cc', + 'src/core/lib/iomgr/cfstream_handle.cc', 'src/core/lib/iomgr/combiner.cc', 'src/core/lib/iomgr/dualstack_socket_posix.cc', 'src/core/lib/iomgr/endpoint.cc', - 'src/core/lib/iomgr/endpoint_cfstream.cc', + 'src/core/lib/iomgr/endpoint_cfstream.cc', 'src/core/lib/iomgr/endpoint_pair_posix.cc', 'src/core/lib/iomgr/endpoint_pair_uv.cc', 'src/core/lib/iomgr/endpoint_pair_windows.cc', 'src/core/lib/iomgr/error.cc', - 'src/core/lib/iomgr/error_cfstream.cc', + 'src/core/lib/iomgr/error_cfstream.cc', 'src/core/lib/iomgr/ev_apple.cc', 'src/core/lib/iomgr/ev_epoll1_linux.cc', 'src/core/lib/iomgr/ev_epollex_linux.cc', @@ -299,8 +299,8 @@ CORE_SOURCE_FILES = [ 'src/core/lib/iomgr/ev_windows.cc', 'src/core/lib/iomgr/exec_ctx.cc', 'src/core/lib/iomgr/executor.cc', - 'src/core/lib/iomgr/executor/mpmcqueue.cc', - 'src/core/lib/iomgr/executor/threadpool.cc', + 'src/core/lib/iomgr/executor/mpmcqueue.cc', + 'src/core/lib/iomgr/executor/threadpool.cc', 'src/core/lib/iomgr/fork_posix.cc', 'src/core/lib/iomgr/fork_windows.cc', 'src/core/lib/iomgr/gethostname_fallback.cc', @@ -314,7 +314,7 @@ CORE_SOURCE_FILES = [ 'src/core/lib/iomgr/iomgr_custom.cc', 'src/core/lib/iomgr/iomgr_internal.cc', 'src/core/lib/iomgr/iomgr_posix.cc', - 'src/core/lib/iomgr/iomgr_posix_cfstream.cc', + 'src/core/lib/iomgr/iomgr_posix_cfstream.cc', 'src/core/lib/iomgr/iomgr_uv.cc', 'src/core/lib/iomgr/iomgr_windows.cc', 'src/core/lib/iomgr/is_epollexclusive_available.cc', @@ -345,7 +345,7 @@ CORE_SOURCE_FILES = [ 'src/core/lib/iomgr/socket_utils_windows.cc', 'src/core/lib/iomgr/socket_windows.cc', 'src/core/lib/iomgr/tcp_client.cc', - 'src/core/lib/iomgr/tcp_client_cfstream.cc', + 'src/core/lib/iomgr/tcp_client_cfstream.cc', 'src/core/lib/iomgr/tcp_client_custom.cc', 'src/core/lib/iomgr/tcp_client_posix.cc', 'src/core/lib/iomgr/tcp_client_windows.cc', @@ -378,53 +378,53 @@ CORE_SOURCE_FILES = [ 'src/core/lib/json/json_reader.cc', 'src/core/lib/json/json_util.cc', 'src/core/lib/json/json_writer.cc', - 'src/core/lib/profiling/basic_timers.cc', - 'src/core/lib/profiling/stap_timers.cc', + 'src/core/lib/profiling/basic_timers.cc', + 'src/core/lib/profiling/stap_timers.cc', 'src/core/lib/security/authorization/authorization_engine.cc', 'src/core/lib/security/authorization/evaluate_args.cc', - 'src/core/lib/security/context/security_context.cc', - 'src/core/lib/security/credentials/alts/alts_credentials.cc', - 'src/core/lib/security/credentials/alts/check_gcp_environment.cc', - 'src/core/lib/security/credentials/alts/check_gcp_environment_linux.cc', - 'src/core/lib/security/credentials/alts/check_gcp_environment_no_op.cc', - 'src/core/lib/security/credentials/alts/check_gcp_environment_windows.cc', - 'src/core/lib/security/credentials/alts/grpc_alts_credentials_client_options.cc', - 'src/core/lib/security/credentials/alts/grpc_alts_credentials_options.cc', - 'src/core/lib/security/credentials/alts/grpc_alts_credentials_server_options.cc', - 'src/core/lib/security/credentials/composite/composite_credentials.cc', - 'src/core/lib/security/credentials/credentials.cc', - 'src/core/lib/security/credentials/credentials_metadata.cc', - 'src/core/lib/security/credentials/fake/fake_credentials.cc', - 'src/core/lib/security/credentials/google_default/credentials_generic.cc', - 'src/core/lib/security/credentials/google_default/google_default_credentials.cc', - 'src/core/lib/security/credentials/iam/iam_credentials.cc', - 'src/core/lib/security/credentials/jwt/json_token.cc', - 'src/core/lib/security/credentials/jwt/jwt_credentials.cc', - 'src/core/lib/security/credentials/jwt/jwt_verifier.cc', - 'src/core/lib/security/credentials/local/local_credentials.cc', - 'src/core/lib/security/credentials/oauth2/oauth2_credentials.cc', - 'src/core/lib/security/credentials/plugin/plugin_credentials.cc', - 'src/core/lib/security/credentials/ssl/ssl_credentials.cc', + 'src/core/lib/security/context/security_context.cc', + 'src/core/lib/security/credentials/alts/alts_credentials.cc', + 'src/core/lib/security/credentials/alts/check_gcp_environment.cc', + 'src/core/lib/security/credentials/alts/check_gcp_environment_linux.cc', + 'src/core/lib/security/credentials/alts/check_gcp_environment_no_op.cc', + 'src/core/lib/security/credentials/alts/check_gcp_environment_windows.cc', + 'src/core/lib/security/credentials/alts/grpc_alts_credentials_client_options.cc', + 'src/core/lib/security/credentials/alts/grpc_alts_credentials_options.cc', + 'src/core/lib/security/credentials/alts/grpc_alts_credentials_server_options.cc', + 'src/core/lib/security/credentials/composite/composite_credentials.cc', + 'src/core/lib/security/credentials/credentials.cc', + 'src/core/lib/security/credentials/credentials_metadata.cc', + 'src/core/lib/security/credentials/fake/fake_credentials.cc', + 'src/core/lib/security/credentials/google_default/credentials_generic.cc', + 'src/core/lib/security/credentials/google_default/google_default_credentials.cc', + 'src/core/lib/security/credentials/iam/iam_credentials.cc', + 'src/core/lib/security/credentials/jwt/json_token.cc', + 'src/core/lib/security/credentials/jwt/jwt_credentials.cc', + 'src/core/lib/security/credentials/jwt/jwt_verifier.cc', + 'src/core/lib/security/credentials/local/local_credentials.cc', + 'src/core/lib/security/credentials/oauth2/oauth2_credentials.cc', + 'src/core/lib/security/credentials/plugin/plugin_credentials.cc', + 'src/core/lib/security/credentials/ssl/ssl_credentials.cc', 'src/core/lib/security/credentials/tls/grpc_tls_certificate_distributor.cc', - 'src/core/lib/security/credentials/tls/grpc_tls_credentials_options.cc', + 'src/core/lib/security/credentials/tls/grpc_tls_credentials_options.cc', 'src/core/lib/security/credentials/tls/tls_credentials.cc', 'src/core/lib/security/credentials/xds/xds_credentials.cc', - 'src/core/lib/security/security_connector/alts/alts_security_connector.cc', - 'src/core/lib/security/security_connector/fake/fake_security_connector.cc', - 'src/core/lib/security/security_connector/load_system_roots_fallback.cc', - 'src/core/lib/security/security_connector/load_system_roots_linux.cc', - 'src/core/lib/security/security_connector/local/local_security_connector.cc', - 'src/core/lib/security/security_connector/security_connector.cc', - 'src/core/lib/security/security_connector/ssl/ssl_security_connector.cc', - 'src/core/lib/security/security_connector/ssl_utils.cc', - 'src/core/lib/security/security_connector/ssl_utils_config.cc', + 'src/core/lib/security/security_connector/alts/alts_security_connector.cc', + 'src/core/lib/security/security_connector/fake/fake_security_connector.cc', + 'src/core/lib/security/security_connector/load_system_roots_fallback.cc', + 'src/core/lib/security/security_connector/load_system_roots_linux.cc', + 'src/core/lib/security/security_connector/local/local_security_connector.cc', + 'src/core/lib/security/security_connector/security_connector.cc', + 'src/core/lib/security/security_connector/ssl/ssl_security_connector.cc', + 'src/core/lib/security/security_connector/ssl_utils.cc', + 'src/core/lib/security/security_connector/ssl_utils_config.cc', 'src/core/lib/security/security_connector/tls/tls_security_connector.cc', - 'src/core/lib/security/transport/client_auth_filter.cc', - 'src/core/lib/security/transport/secure_endpoint.cc', - 'src/core/lib/security/transport/security_handshaker.cc', - 'src/core/lib/security/transport/server_auth_filter.cc', - 'src/core/lib/security/transport/tsi_error.cc', - 'src/core/lib/security/util/json_util.cc', + 'src/core/lib/security/transport/client_auth_filter.cc', + 'src/core/lib/security/transport/secure_endpoint.cc', + 'src/core/lib/security/transport/security_handshaker.cc', + 'src/core/lib/security/transport/server_auth_filter.cc', + 'src/core/lib/security/transport/tsi_error.cc', + 'src/core/lib/security/util/json_util.cc', 'src/core/lib/slice/b64.cc', 'src/core/lib/slice/percent_encoding.cc', 'src/core/lib/slice/slice.cc', @@ -444,8 +444,8 @@ CORE_SOURCE_FILES = [ 'src/core/lib/surface/completion_queue.cc', 'src/core/lib/surface/completion_queue_factory.cc', 'src/core/lib/surface/event_string.cc', - 'src/core/lib/surface/init.cc', - 'src/core/lib/surface/init_secure.cc', + 'src/core/lib/surface/init.cc', + 'src/core/lib/surface/init_secure.cc', 'src/core/lib/surface/lame_client.cc', 'src/core/lib/surface/metadata_array.cc', 'src/core/lib/surface/server.cc', @@ -466,7 +466,7 @@ CORE_SOURCE_FILES = [ 'src/core/lib/transport/transport.cc', 'src/core/lib/transport/transport_op_string.cc', 'src/core/lib/uri/uri_parser.cc', - 'src/core/plugin_registry/grpc_plugin_registry.cc', + 'src/core/plugin_registry/grpc_plugin_registry.cc', 'src/core/tsi/alts/crypt/aes_gcm.cc', 'src/core/tsi/alts/crypt/gsec.cc', 'src/core/tsi/alts/frame_protector/alts_counter.cc', @@ -479,8 +479,8 @@ CORE_SOURCE_FILES = [ 'src/core/tsi/alts/handshaker/alts_handshaker_client.cc', 'src/core/tsi/alts/handshaker/alts_shared_resource.cc', 'src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc', - 'src/core/tsi/alts/handshaker/alts_tsi_utils.cc', - 'src/core/tsi/alts/handshaker/transport_security_common_api.cc', + 'src/core/tsi/alts/handshaker/alts_tsi_utils.cc', + 'src/core/tsi/alts/handshaker/transport_security_common_api.cc', 'src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.cc', 'src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.cc', 'src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.cc', @@ -492,7 +492,7 @@ CORE_SOURCE_FILES = [ 'src/core/tsi/ssl/session_cache/ssl_session_cache.cc', 'src/core/tsi/ssl/session_cache/ssl_session_openssl.cc', 'src/core/tsi/ssl_transport_security.cc', - 'src/core/tsi/transport_security.cc', + 'src/core/tsi/transport_security.cc', 'src/core/tsi/transport_security_grpc.cc', 'third_party/abseil-cpp/y_absl/base/dynamic_annotations.cc', 'third_party/abseil-cpp/y_absl/base/internal/cycleclock.cc', @@ -568,9 +568,9 @@ CORE_SOURCE_FILES = [ 'third_party/abseil-cpp/y_absl/time/time.cc', 'third_party/abseil-cpp/y_absl/types/bad_optional_access.cc', 'third_party/abseil-cpp/y_absl/types/bad_variant_access.cc', - 'third_party/address_sorting/address_sorting.c', - 'third_party/address_sorting/address_sorting_posix.c', - 'third_party/address_sorting/address_sorting_windows.c', + 'third_party/address_sorting/address_sorting.c', + 'third_party/address_sorting/address_sorting_posix.c', + 'third_party/address_sorting/address_sorting_windows.c', 'third_party/boringssl-with-bazel/err_data.c', 'third_party/boringssl-with-bazel/src/crypto/asn1/a_bitstr.c', 'third_party/boringssl-with-bazel/src/crypto/asn1/a_bool.c', @@ -879,7 +879,7 @@ CORE_SOURCE_FILES = [ 'third_party/cares/cares/ares_strcasecmp.c', 'third_party/cares/cares/ares_strdup.c', 'third_party/cares/cares/ares_strerror.c', - 'third_party/cares/cares/ares_strsplit.c', + 'third_party/cares/cares/ares_strsplit.c', 'third_party/cares/cares/ares_timeout.c', 'third_party/cares/cares/ares_version.c', 'third_party/cares/cares/ares_writev.c', @@ -910,27 +910,27 @@ CORE_SOURCE_FILES = [ 'third_party/re2/util/pcre.cc', 'third_party/re2/util/rune.cc', 'third_party/re2/util/strutil.cc', - 'third_party/upb/upb/decode.c', - 'third_party/upb/upb/encode.c', - 'third_party/upb/upb/msg.c', - 'third_party/upb/upb/port.c', - 'third_party/upb/upb/table.c', - 'third_party/upb/upb/upb.c', - 'third_party/zlib/adler32.c', - 'third_party/zlib/compress.c', - 'third_party/zlib/crc32.c', - 'third_party/zlib/deflate.c', - 'third_party/zlib/gzclose.c', - 'third_party/zlib/gzlib.c', - 'third_party/zlib/gzread.c', - 'third_party/zlib/gzwrite.c', - 'third_party/zlib/infback.c', - 'third_party/zlib/inffast.c', - 'third_party/zlib/inflate.c', - 'third_party/zlib/inftrees.c', - 'third_party/zlib/trees.c', - 'third_party/zlib/uncompr.c', - 'third_party/zlib/zutil.c', + 'third_party/upb/upb/decode.c', + 'third_party/upb/upb/encode.c', + 'third_party/upb/upb/msg.c', + 'third_party/upb/upb/port.c', + 'third_party/upb/upb/table.c', + 'third_party/upb/upb/upb.c', + 'third_party/zlib/adler32.c', + 'third_party/zlib/compress.c', + 'third_party/zlib/crc32.c', + 'third_party/zlib/deflate.c', + 'third_party/zlib/gzclose.c', + 'third_party/zlib/gzlib.c', + 'third_party/zlib/gzread.c', + 'third_party/zlib/gzwrite.c', + 'third_party/zlib/infback.c', + 'third_party/zlib/inffast.c', + 'third_party/zlib/inflate.c', + 'third_party/zlib/inftrees.c', + 'third_party/zlib/trees.c', + 'third_party/zlib/uncompr.c', + 'third_party/zlib/zutil.c', ] ASM_SOURCE_FILES = { diff --git a/contrib/libs/grpc/src/python/grpcio/ya.make b/contrib/libs/grpc/src/python/grpcio/ya.make index 5cdb0230c4..5de0a4d591 100644 --- a/contrib/libs/grpc/src/python/grpcio/ya.make +++ b/contrib/libs/grpc/src/python/grpcio/ya.make @@ -5,13 +5,13 @@ LICENSE(Apache-2.0) LICENSE_TEXTS(.yandex_meta/licenses.list.txt) OWNER( - akastornov - g:contrib - g:cpp-contrib + akastornov + g:contrib + g:cpp-contrib ) PEERDIR( - contrib/libs/grpc/grpc + contrib/libs/grpc/grpc contrib/python/six ) @@ -31,10 +31,10 @@ ADDINCL( IF (SANITIZER_TYPE == undefined) # https://github.com/grpc/grpc/blob/v1.15.1/tools/bazel.rc#L43 CXXFLAGS(-fno-sanitize=function) -ENDIF() +ENDIF() NO_LINT() - + NO_COMPILER_WARNINGS() PY_SRCS( @@ -43,7 +43,7 @@ PY_SRCS( grpc/_auth.py grpc/_channel.py grpc/_common.py - grpc/_compression.py + grpc/_compression.py grpc/_cython/__init__.py grpc/_cython/_cygrpc/__init__.py grpc/_cython/cygrpc.pyx @@ -83,9 +83,9 @@ PY_SRCS( grpc/framework/interfaces/face/utilities.py ) -IF (PYTHON3) - PY_SRCS( - TOP_LEVEL +IF (PYTHON3) + PY_SRCS( + TOP_LEVEL grpc/_simple_stubs.py grpc/aio/_base_call.py grpc/aio/_base_channel.py @@ -98,8 +98,8 @@ IF (PYTHON3) grpc/aio/_server.py grpc/aio/_typing.py grpc/aio/_utils.py - grpc/experimental/aio/__init__.py - ) -ENDIF() - + grpc/experimental/aio/__init__.py + ) +ENDIF() + END() |