summaryrefslogtreecommitdiffstats
path: root/contrib/python/grpcio/py3/grpc/_utilities.py
diff options
context:
space:
mode:
authorrobot-piglet <[email protected]>2025-08-29 14:19:24 +0300
committerrobot-piglet <[email protected]>2025-08-29 14:40:38 +0300
commit5715939b5b1a1812ed85171fb519f9c1c3c326e8 (patch)
tree5d981253427e490749bbb50d3616507fa0d6d1bc /contrib/python/grpcio/py3/grpc/_utilities.py
parentc390a008ee5d15e1d8f49326671908f375e0851b (diff)
Intermediate changes
commit_hash:88dd3a7e237f5ebeb9b302a0e6866042635fda83
Diffstat (limited to 'contrib/python/grpcio/py3/grpc/_utilities.py')
-rw-r--r--contrib/python/grpcio/py3/grpc/_utilities.py74
1 files changed, 58 insertions, 16 deletions
diff --git a/contrib/python/grpcio/py3/grpc/_utilities.py b/contrib/python/grpcio/py3/grpc/_utilities.py
index 3dafa7a03d3..620cab3838c 100644
--- a/contrib/python/grpcio/py3/grpc/_utilities.py
+++ b/contrib/python/grpcio/py3/grpc/_utilities.py
@@ -26,20 +26,26 @@ from grpc._typing import DoneCallbackType
_LOGGER = logging.getLogger(__name__)
_DONE_CALLBACK_EXCEPTION_LOG_MESSAGE = (
- 'Exception calling connectivity future "done" callback!')
+ 'Exception calling connectivity future "done" callback!'
+)
class RpcMethodHandler(
- collections.namedtuple('_RpcMethodHandler', (
- 'request_streaming',
- 'response_streaming',
- 'request_deserializer',
- 'response_serializer',
- 'unary_unary',
- 'unary_stream',
- 'stream_unary',
- 'stream_stream',
- )), grpc.RpcMethodHandler):
+ collections.namedtuple(
+ "_RpcMethodHandler",
+ (
+ "request_streaming",
+ "response_streaming",
+ "request_deserializer",
+ "response_serializer",
+ "unary_unary",
+ "unary_stream",
+ "stream_unary",
+ "stream_stream",
+ ),
+ ),
+ grpc.RpcMethodHandler,
+):
pass
@@ -47,8 +53,9 @@ class DictionaryGenericHandler(grpc.ServiceRpcHandler):
_name: str
_method_handlers: Dict[str, grpc.RpcMethodHandler]
- def __init__(self, service: str,
- method_handlers: Dict[str, grpc.RpcMethodHandler]):
+ def __init__(
+ self, service: str, method_handlers: Dict[str, grpc.RpcMethodHandler]
+ ):
self._name = service
self._method_handlers = {
_common.fully_qualified_method(service, method): method_handler
@@ -62,7 +69,9 @@ class DictionaryGenericHandler(grpc.ServiceRpcHandler):
self, handler_call_details: grpc.HandlerCallDetails
) -> Optional[grpc.RpcMethodHandler]:
details_method = handler_call_details.method
- return self._method_handlers.get(details_method) # pytype: disable=attribute-error
+ return self._method_handlers.get(
+ details_method
+ ) # pytype: disable=attribute-error
class _ChannelReadyFuture(grpc.Future):
@@ -100,8 +109,10 @@ class _ChannelReadyFuture(grpc.Future):
def _update(self, connectivity: Optional[grpc.ChannelConnectivity]) -> None:
with self._condition:
- if (not self._cancelled and
- connectivity is grpc.ChannelConnectivity.READY):
+ if (
+ not self._cancelled
+ and connectivity is grpc.ChannelConnectivity.READY
+ ):
self._matured = True
self._channel.unsubscribe(self._update)
self._condition.notify_all()
@@ -178,3 +189,34 @@ def channel_ready_future(channel: grpc.Channel) -> _ChannelReadyFuture:
ready_future = _ChannelReadyFuture(channel)
ready_future.start()
return ready_future
+
+
+def first_version_is_lower(version1: str, version2: str) -> bool:
+ """
+ Compares two versions in the format '1.60.1' or '1.60.1.dev0'.
+
+ This method will be used in all stubs generated by grpcio-tools to check whether
+ the stub version is compatible with the runtime grpcio.
+
+ Args:
+ version1: The first version string.
+ version2: The second version string.
+
+ Returns:
+ True if version1 is lower, False otherwise.
+ """
+ version1_list = version1.split(".")
+ version2_list = version2.split(".")
+
+ try:
+ for i in range(3):
+ if int(version1_list[i]) < int(version2_list[i]):
+ return True
+ elif int(version1_list[i]) > int(version2_list[i]):
+ return False
+ except ValueError:
+ # Return false in case we can't convert version to int.
+ return False
+
+ # The version without dev0 will be considered lower.
+ return len(version1_list) < len(version2_list)