Skip to content

Commit 5a107cc

Browse files
authored
Merge pull request #149 move topic grpc wrapper code to one file
2 parents 779fe85 + 9960511 commit 5a107cc

File tree

19 files changed

+691
-718
lines changed

19 files changed

+691
-718
lines changed

tox.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ deps =
4646
[testenv:black-format]
4747
skip_install = true
4848
commands =
49-
black ydb examples tests --extend-exclude ydb/_grpc
49+
black ydb examples tests --extend-exclude "ydb/_grpc/v3|ydb/_grpc/v4"
5050

5151
[testenv:black]
5252
skip_install = true
5353
commands =
54-
black --diff --check ydb examples tests --extend-exclude ydb/_grpc
54+
black --diff --check ydb examples tests --extend-exclude "ydb/_grpc/v3|ydb/_grpc/v4"
5555

5656
[testenv:pylint]
5757
deps = pylint

ydb/_grpc/common/__init__.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@
99
protobuf_version = Version(google.protobuf.__version__)
1010

1111
if protobuf_version < Version("4.0"):
12-
from ydb._grpc.v3 import * # noqa
13-
from ydb._grpc.v3 import protos # noqa
12+
from ydb._grpc.v3 import * # noqa
13+
from ydb._grpc.v3 import protos # noqa
14+
1415
sys.modules["ydb._grpc.common"] = sys.modules["ydb._grpc.v3"]
1516
sys.modules["ydb._grpc.common.protos"] = sys.modules["ydb._grpc.v3.protos"]
1617
else:
17-
from ydb._grpc.v4 import * # noqa
18-
from ydb._grpc.v4 import protos # noqa
18+
from ydb._grpc.v4 import * # noqa
19+
from ydb._grpc.v4 import protos # noqa
20+
1921
sys.modules["ydb._grpc.common"] = sys.modules["ydb._grpc.v4"]
2022
sys.modules["ydb._grpc.common.protos"] = sys.modules["ydb._grpc.v4.protos"]
Lines changed: 11 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,20 @@
22
import asyncio
33
import typing
44
from dataclasses import dataclass
5-
from enum import IntEnum
65

76
import grpc
87
from google.protobuf.message import Message
98

109
import 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
1613
if 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
2115
else:
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

4721
class 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

6738
class 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-
13593
class 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-
262200
def callback_from_asyncio(
263201
callback: typing.Union[typing.Callable, typing.Coroutine]
264202
) -> [asyncio.Future, asyncio.Task]:

0 commit comments

Comments
 (0)