22import asyncio
33import typing
44from dataclasses import dataclass
5- from enum import IntEnum
65
76import grpc
87from google .protobuf .message import Message
98
109import ydb .aio
1110
12- from .. import issues , connection
13-
14- # Workaround for good autocomplete in IDE and universal import at runtime
11+ # Workaround for good IDE and universal for runtime
1512# noinspection PyUnreachableCode
1613if False :
17- from ydb ._grpc .v4 .protos import (
18- ydb_issue_message_pb2 ,
19- ydb_topic_pb2 ,
20- )
14+ from ..v4 .protos import ydb_topic_pb2 , ydb_issue_message_pb2
2115else :
22- # noinspection PyUnresolvedReferences
23- from ydb ._grpc .common .protos import (
24- ydb_issue_message_pb2 ,
25- ydb_topic_pb2 ,
26- )
27-
28-
29- class Codec (IntEnum ):
30- CODEC_UNSPECIFIED = 0
31- CODEC_RAW = 1
32- CODEC_GZIP = 2
33- CODEC_LZOP = 3
34- CODEC_ZSTD = 4
16+ from ..common .protos import ydb_topic_pb2 , ydb_issue_message_pb2
3517
36-
37- class IToProto (abc .ABC ):
38- @abc .abstractmethod
39- def to_proto (self ) -> Message :
40- pass
41-
42-
43- class UnknownGrpcMessageError (ydb .Error ):
44- pass
18+ from ... import issues , connection
4519
4620
4721class IFromProto (abc .ABC ):
@@ -51,17 +25,14 @@ def from_proto(msg: Message) -> typing.Any:
5125 pass
5226
5327
54- @ dataclass
55- class OffsetsRange ( IFromProto ):
56- start : int
57- end : int
28+ class IToProto ( abc . ABC ):
29+ @ abc . abstractmethod
30+ def to_proto ( self ) -> Message :
31+ pass
5832
59- @staticmethod
60- def from_proto (msg : ydb_topic_pb2 .OffsetsRange ) -> "OffsetsRange" :
61- return OffsetsRange (
62- start = msg .start ,
63- end = msg .end ,
64- )
33+
34+ class UnknownGrpcMessageError (issues .Error ):
35+ pass
6536
6637
6738class QueueToIteratorAsyncIO :
@@ -119,19 +90,6 @@ async def __anext__(self):
11990 raise StopIteration ()
12091
12192
122- class IteratorToQueueAsyncIO :
123- __slots__ = ("_iterator" ,)
124-
125- def __init__ (self , iterator : typing .AsyncIterator [typing .Any ]):
126- self ._iterator = iterator
127-
128- async def get (self ) -> typing .Any :
129- try :
130- return self ._iterator .__anext__ ()
131- except StopAsyncIteration :
132- raise asyncio .QueueEmpty ()
133-
134-
13593class IGrpcWrapperAsyncIO (abc .ABC ):
13694 @abc .abstractmethod
13795 async def receive (self ) -> typing .Any :
@@ -239,26 +197,6 @@ def issue_to_str(cls, issue: ydb_issue_message_pb2.IssueMessage):
239197 return res
240198
241199
242- @dataclass
243- class UpdateTokenRequest (IToProto ):
244- token : str
245-
246- def to_proto (self ) -> Message :
247- res = ydb_topic_pb2 .UpdateTokenRequest ()
248- res .token = self .token
249- return res
250-
251-
252- @dataclass
253- class UpdateTokenResponse (IFromProto ):
254- @staticmethod
255- def from_proto (msg : ydb_topic_pb2 .UpdateTokenResponse ) -> typing .Any :
256- return UpdateTokenResponse ()
257-
258-
259- TokenGetterFuncType = typing .Optional [typing .Callable [[], str ]]
260-
261-
262200def callback_from_asyncio (
263201 callback : typing .Union [typing .Callable , typing .Coroutine ]
264202) -> [asyncio .Future , asyncio .Task ]:
0 commit comments