telegrinder 1.0.0rc1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- telegrinder/__init__.py +258 -0
- telegrinder/__meta__.py +1 -0
- telegrinder/api/__init__.py +15 -0
- telegrinder/api/api.py +175 -0
- telegrinder/api/error.py +50 -0
- telegrinder/api/response.py +23 -0
- telegrinder/api/token.py +30 -0
- telegrinder/api/validators.py +30 -0
- telegrinder/bot/__init__.py +144 -0
- telegrinder/bot/bot.py +70 -0
- telegrinder/bot/cute_types/__init__.py +41 -0
- telegrinder/bot/cute_types/base.py +228 -0
- telegrinder/bot/cute_types/base.pyi +49 -0
- telegrinder/bot/cute_types/business_connection.py +9 -0
- telegrinder/bot/cute_types/business_messages_deleted.py +9 -0
- telegrinder/bot/cute_types/callback_query.py +248 -0
- telegrinder/bot/cute_types/chat_boost_removed.py +9 -0
- telegrinder/bot/cute_types/chat_boost_updated.py +9 -0
- telegrinder/bot/cute_types/chat_join_request.py +59 -0
- telegrinder/bot/cute_types/chat_member_updated.py +158 -0
- telegrinder/bot/cute_types/chosen_inline_result.py +11 -0
- telegrinder/bot/cute_types/inline_query.py +41 -0
- telegrinder/bot/cute_types/message.py +2809 -0
- telegrinder/bot/cute_types/message_reaction_count_updated.py +9 -0
- telegrinder/bot/cute_types/message_reaction_updated.py +9 -0
- telegrinder/bot/cute_types/paid_media_purchased.py +11 -0
- telegrinder/bot/cute_types/poll.py +9 -0
- telegrinder/bot/cute_types/poll_answer.py +9 -0
- telegrinder/bot/cute_types/pre_checkout_query.py +36 -0
- telegrinder/bot/cute_types/shipping_query.py +11 -0
- telegrinder/bot/cute_types/update.py +209 -0
- telegrinder/bot/cute_types/utils.py +141 -0
- telegrinder/bot/dispatch/__init__.py +99 -0
- telegrinder/bot/dispatch/abc.py +74 -0
- telegrinder/bot/dispatch/action.py +99 -0
- telegrinder/bot/dispatch/context.py +162 -0
- telegrinder/bot/dispatch/dispatch.py +362 -0
- telegrinder/bot/dispatch/handler/__init__.py +23 -0
- telegrinder/bot/dispatch/handler/abc.py +25 -0
- telegrinder/bot/dispatch/handler/audio_reply.py +43 -0
- telegrinder/bot/dispatch/handler/base.py +34 -0
- telegrinder/bot/dispatch/handler/document_reply.py +43 -0
- telegrinder/bot/dispatch/handler/func.py +73 -0
- telegrinder/bot/dispatch/handler/media_group_reply.py +43 -0
- telegrinder/bot/dispatch/handler/message_reply.py +35 -0
- telegrinder/bot/dispatch/handler/photo_reply.py +43 -0
- telegrinder/bot/dispatch/handler/sticker_reply.py +36 -0
- telegrinder/bot/dispatch/handler/video_reply.py +43 -0
- telegrinder/bot/dispatch/middleware/__init__.py +13 -0
- telegrinder/bot/dispatch/middleware/abc.py +112 -0
- telegrinder/bot/dispatch/middleware/box.py +32 -0
- telegrinder/bot/dispatch/middleware/filter.py +88 -0
- telegrinder/bot/dispatch/middleware/media_group.py +69 -0
- telegrinder/bot/dispatch/process.py +93 -0
- telegrinder/bot/dispatch/return_manager/__init__.py +21 -0
- telegrinder/bot/dispatch/return_manager/abc.py +107 -0
- telegrinder/bot/dispatch/return_manager/callback_query.py +19 -0
- telegrinder/bot/dispatch/return_manager/inline_query.py +14 -0
- telegrinder/bot/dispatch/return_manager/message.py +34 -0
- telegrinder/bot/dispatch/return_manager/pre_checkout_query.py +19 -0
- telegrinder/bot/dispatch/return_manager/utils.py +20 -0
- telegrinder/bot/dispatch/router/__init__.py +4 -0
- telegrinder/bot/dispatch/router/abc.py +15 -0
- telegrinder/bot/dispatch/router/base.py +154 -0
- telegrinder/bot/dispatch/view/__init__.py +15 -0
- telegrinder/bot/dispatch/view/abc.py +15 -0
- telegrinder/bot/dispatch/view/base.py +226 -0
- telegrinder/bot/dispatch/view/box.py +207 -0
- telegrinder/bot/dispatch/view/media_group.py +25 -0
- telegrinder/bot/dispatch/waiter_machine/__init__.py +25 -0
- telegrinder/bot/dispatch/waiter_machine/actions.py +16 -0
- telegrinder/bot/dispatch/waiter_machine/hasher/__init__.py +13 -0
- telegrinder/bot/dispatch/waiter_machine/hasher/callback.py +53 -0
- telegrinder/bot/dispatch/waiter_machine/hasher/hasher.py +61 -0
- telegrinder/bot/dispatch/waiter_machine/hasher/message.py +49 -0
- telegrinder/bot/dispatch/waiter_machine/machine.py +264 -0
- telegrinder/bot/dispatch/waiter_machine/middleware.py +77 -0
- telegrinder/bot/dispatch/waiter_machine/short_state.py +105 -0
- telegrinder/bot/polling/__init__.py +4 -0
- telegrinder/bot/polling/abc.py +25 -0
- telegrinder/bot/polling/error_handler.py +93 -0
- telegrinder/bot/polling/polling.py +167 -0
- telegrinder/bot/polling/utils.py +12 -0
- telegrinder/bot/rules/__init__.py +166 -0
- telegrinder/bot/rules/abc.py +150 -0
- telegrinder/bot/rules/button.py +20 -0
- telegrinder/bot/rules/callback_data.py +109 -0
- telegrinder/bot/rules/chat_join.py +28 -0
- telegrinder/bot/rules/chat_member_updated.py +145 -0
- telegrinder/bot/rules/command.py +137 -0
- telegrinder/bot/rules/enum_text.py +29 -0
- telegrinder/bot/rules/func.py +21 -0
- telegrinder/bot/rules/fuzzy.py +21 -0
- telegrinder/bot/rules/inline.py +45 -0
- telegrinder/bot/rules/integer.py +19 -0
- telegrinder/bot/rules/is_from.py +213 -0
- telegrinder/bot/rules/logic.py +22 -0
- telegrinder/bot/rules/magic.py +60 -0
- telegrinder/bot/rules/markup.py +51 -0
- telegrinder/bot/rules/media.py +13 -0
- telegrinder/bot/rules/mention.py +15 -0
- telegrinder/bot/rules/message_entities.py +37 -0
- telegrinder/bot/rules/node.py +43 -0
- telegrinder/bot/rules/payload.py +89 -0
- telegrinder/bot/rules/payment_invoice.py +14 -0
- telegrinder/bot/rules/regex.py +34 -0
- telegrinder/bot/rules/rule_enum.py +71 -0
- telegrinder/bot/rules/start.py +73 -0
- telegrinder/bot/rules/state.py +35 -0
- telegrinder/bot/rules/text.py +27 -0
- telegrinder/bot/rules/update.py +14 -0
- telegrinder/bot/scenario/__init__.py +5 -0
- telegrinder/bot/scenario/abc.py +16 -0
- telegrinder/bot/scenario/checkbox.py +183 -0
- telegrinder/bot/scenario/choice.py +44 -0
- telegrinder/client/__init__.py +11 -0
- telegrinder/client/abc.py +136 -0
- telegrinder/client/form_data.py +34 -0
- telegrinder/client/rnet.py +198 -0
- telegrinder/model.py +133 -0
- telegrinder/model.pyi +57 -0
- telegrinder/modules.py +1081 -0
- telegrinder/msgspec_utils/__init__.py +42 -0
- telegrinder/msgspec_utils/abc.py +16 -0
- telegrinder/msgspec_utils/custom_types/__init__.py +6 -0
- telegrinder/msgspec_utils/custom_types/datetime.py +24 -0
- telegrinder/msgspec_utils/custom_types/enum_meta.py +61 -0
- telegrinder/msgspec_utils/custom_types/literal.py +25 -0
- telegrinder/msgspec_utils/custom_types/option.py +17 -0
- telegrinder/msgspec_utils/decoder.py +388 -0
- telegrinder/msgspec_utils/encoder.py +204 -0
- telegrinder/msgspec_utils/json.py +15 -0
- telegrinder/msgspec_utils/tools.py +80 -0
- telegrinder/node/__init__.py +80 -0
- telegrinder/node/compose.py +193 -0
- telegrinder/node/nodes/__init__.py +96 -0
- telegrinder/node/nodes/attachment.py +169 -0
- telegrinder/node/nodes/callback_query.py +25 -0
- telegrinder/node/nodes/channel.py +97 -0
- telegrinder/node/nodes/command.py +33 -0
- telegrinder/node/nodes/error.py +43 -0
- telegrinder/node/nodes/event.py +70 -0
- telegrinder/node/nodes/file.py +39 -0
- telegrinder/node/nodes/global_node.py +66 -0
- telegrinder/node/nodes/i18n.py +110 -0
- telegrinder/node/nodes/me.py +26 -0
- telegrinder/node/nodes/message_entities.py +15 -0
- telegrinder/node/nodes/payload.py +84 -0
- telegrinder/node/nodes/reply_message.py +14 -0
- telegrinder/node/nodes/source.py +172 -0
- telegrinder/node/nodes/state_mutator.py +71 -0
- telegrinder/node/nodes/text.py +62 -0
- telegrinder/node/scope.py +88 -0
- telegrinder/node/utils.py +38 -0
- telegrinder/py.typed +0 -0
- telegrinder/rules.py +1 -0
- telegrinder/tools/__init__.py +183 -0
- telegrinder/tools/aio.py +147 -0
- telegrinder/tools/final.py +21 -0
- telegrinder/tools/formatting/__init__.py +85 -0
- telegrinder/tools/formatting/deep_links/__init__.py +39 -0
- telegrinder/tools/formatting/deep_links/links.py +468 -0
- telegrinder/tools/formatting/deep_links/parsing.py +88 -0
- telegrinder/tools/formatting/deep_links/validators.py +8 -0
- telegrinder/tools/formatting/html.py +241 -0
- telegrinder/tools/fullname.py +82 -0
- telegrinder/tools/global_context/__init__.py +13 -0
- telegrinder/tools/global_context/abc.py +63 -0
- telegrinder/tools/global_context/builtin_context.py +45 -0
- telegrinder/tools/global_context/global_context.py +614 -0
- telegrinder/tools/input_file_directory.py +30 -0
- telegrinder/tools/keyboard/__init__.py +6 -0
- telegrinder/tools/keyboard/abc.py +84 -0
- telegrinder/tools/keyboard/base.py +108 -0
- telegrinder/tools/keyboard/button.py +181 -0
- telegrinder/tools/keyboard/data.py +31 -0
- telegrinder/tools/keyboard/keyboard.py +160 -0
- telegrinder/tools/keyboard/utils.py +95 -0
- telegrinder/tools/lifespan.py +188 -0
- telegrinder/tools/limited_dict.py +35 -0
- telegrinder/tools/loop_wrapper.py +271 -0
- telegrinder/tools/magic/__init__.py +29 -0
- telegrinder/tools/magic/annotations.py +172 -0
- telegrinder/tools/magic/descriptors.py +57 -0
- telegrinder/tools/magic/function.py +254 -0
- telegrinder/tools/magic/inspect.py +16 -0
- telegrinder/tools/magic/shortcut.py +107 -0
- telegrinder/tools/member_descriptor_proxy.py +95 -0
- telegrinder/tools/parse_mode.py +12 -0
- telegrinder/tools/serialization/__init__.py +5 -0
- telegrinder/tools/serialization/abc.py +34 -0
- telegrinder/tools/serialization/json_ser.py +60 -0
- telegrinder/tools/serialization/msgpack_ser.py +197 -0
- telegrinder/tools/serialization/utils.py +18 -0
- telegrinder/tools/singleton/__init__.py +4 -0
- telegrinder/tools/singleton/abc.py +14 -0
- telegrinder/tools/singleton/singleton.py +18 -0
- telegrinder/tools/state_mutator/__init__.py +4 -0
- telegrinder/tools/state_mutator/mutation.py +85 -0
- telegrinder/tools/state_storage/__init__.py +4 -0
- telegrinder/tools/state_storage/abc.py +38 -0
- telegrinder/tools/state_storage/memory.py +27 -0
- telegrinder/tools/strings.py +22 -0
- telegrinder/types/__init__.py +323 -0
- telegrinder/types/enums.py +754 -0
- telegrinder/types/input_file.py +51 -0
- telegrinder/types/methods.py +6143 -0
- telegrinder/types/methods_utils.py +66 -0
- telegrinder/types/objects.py +8184 -0
- telegrinder/types/webapp.py +129 -0
- telegrinder/verification_utils.py +35 -0
- telegrinder-1.0.0rc1.dist-info/METADATA +166 -0
- telegrinder-1.0.0rc1.dist-info/RECORD +215 -0
- telegrinder-1.0.0rc1.dist-info/WHEEL +4 -0
- telegrinder-1.0.0rc1.dist-info/licenses/LICENSE +22 -0
telegrinder/model.py
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import keyword
|
|
2
|
+
import types
|
|
3
|
+
import typing
|
|
4
|
+
from functools import cache
|
|
5
|
+
from reprlib import recursive_repr
|
|
6
|
+
|
|
7
|
+
import msgspec
|
|
8
|
+
from kungfu.library.monad.option import NOTHING
|
|
9
|
+
|
|
10
|
+
from telegrinder.msgspec_utils import Option, decoder, encoder, is_none, struct_asdict
|
|
11
|
+
|
|
12
|
+
type From[T] = T
|
|
13
|
+
|
|
14
|
+
UNSET: typing.Final = typing.cast("typing.Any", msgspec.UNSET)
|
|
15
|
+
MODEL_CONFIG: typing.Final[dict[str, typing.Any]] = {
|
|
16
|
+
"dict": True,
|
|
17
|
+
"rename": {kw + "_": kw for kw in keyword.kwlist},
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def field(**kwargs: typing.Any) -> typing.Any:
|
|
22
|
+
if kwargs.get("default") is Ellipsis:
|
|
23
|
+
kwargs["default"] = UNSET
|
|
24
|
+
|
|
25
|
+
kwargs.pop("converter", None)
|
|
26
|
+
return msgspec.field(**kwargs)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class Model(msgspec.Struct, **MODEL_CONFIG):
|
|
30
|
+
def __init_subclass__(cls, *args: typing.Any, **kwargs: typing.Any) -> typing.Any:
|
|
31
|
+
from telegrinder.tools.member_descriptor_proxy import MemberDescriptorProxy
|
|
32
|
+
|
|
33
|
+
result = super().__init_subclass__(*args, **kwargs)
|
|
34
|
+
|
|
35
|
+
for field_name in getattr(cls, "__slots__", ()):
|
|
36
|
+
setattr(cls, field_name, MemberDescriptorProxy(getattr(cls, field_name)))
|
|
37
|
+
|
|
38
|
+
return result
|
|
39
|
+
|
|
40
|
+
def __getattribute__(self, name: str, /) -> typing.Any:
|
|
41
|
+
class_ = type(self)
|
|
42
|
+
val = object.__getattribute__(self, name)
|
|
43
|
+
|
|
44
|
+
if name not in class_.__struct_fields__:
|
|
45
|
+
return val
|
|
46
|
+
|
|
47
|
+
if name in class_.get_optional_fields():
|
|
48
|
+
return NOTHING if val is UNSET else val
|
|
49
|
+
|
|
50
|
+
if val is UNSET:
|
|
51
|
+
raise AttributeError(f"{class_.__name__!r} object has no attribute {name!r}")
|
|
52
|
+
|
|
53
|
+
return val
|
|
54
|
+
|
|
55
|
+
def __post_init__(self) -> None:
|
|
56
|
+
for field, value in struct_asdict(self, exclude_unset=False).items():
|
|
57
|
+
if is_none(value):
|
|
58
|
+
setattr(self, field, UNSET)
|
|
59
|
+
|
|
60
|
+
@recursive_repr()
|
|
61
|
+
def __repr__(self) -> str:
|
|
62
|
+
return "{}({})".format(
|
|
63
|
+
type(self).__name__,
|
|
64
|
+
", ".join(
|
|
65
|
+
f"{f}={val!r}" for f, val in struct_asdict(self, exclude_unset=False, unset_as_nothing=True).items()
|
|
66
|
+
),
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
@classmethod
|
|
70
|
+
@cache
|
|
71
|
+
def get_fields(cls) -> types.MappingProxyType[str, msgspec.inspect.Field]:
|
|
72
|
+
return types.MappingProxyType(
|
|
73
|
+
mapping={f.name: f for f in msgspec.inspect.type_info(cls).fields}, # type: ignore
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
@classmethod
|
|
77
|
+
@cache
|
|
78
|
+
def get_optional_fields(cls) -> frozenset[str]:
|
|
79
|
+
return frozenset(
|
|
80
|
+
f.name
|
|
81
|
+
for f in cls.get_fields().values()
|
|
82
|
+
if isinstance(f.type, msgspec.inspect.CustomType) and issubclass(f.type.cls, Option) # type: ignore
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
@classmethod
|
|
86
|
+
def from_data[**P, T](cls: typing.Callable[P, T], *args: P.args, **kwargs: P.kwargs) -> T:
|
|
87
|
+
return decoder.convert(msgspec.structs.asdict(cls(*args, **kwargs)), type=cls) # type: ignore
|
|
88
|
+
|
|
89
|
+
@classmethod
|
|
90
|
+
def from_dict(cls, obj: dict[str, typing.Any], /) -> typing.Self:
|
|
91
|
+
return decoder.convert(obj, type=cls)
|
|
92
|
+
|
|
93
|
+
@classmethod
|
|
94
|
+
def from_raw(cls, raw: str | bytes, /) -> typing.Self:
|
|
95
|
+
return decoder.decode(raw, type=cls)
|
|
96
|
+
|
|
97
|
+
def _to_dict(
|
|
98
|
+
self,
|
|
99
|
+
dct_name: str,
|
|
100
|
+
exclude_fields: set[str],
|
|
101
|
+
full: bool,
|
|
102
|
+
) -> dict[str, typing.Any]:
|
|
103
|
+
if dct_name not in self.__dict__:
|
|
104
|
+
self.__dict__[dct_name] = ( # type: ignore
|
|
105
|
+
struct_asdict(self)
|
|
106
|
+
if not full
|
|
107
|
+
else encoder.to_builtins(self.to_dict(exclude_fields=exclude_fields), order="deterministic")
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
if not exclude_fields:
|
|
111
|
+
return self.__dict__[dct_name]
|
|
112
|
+
|
|
113
|
+
return {key: value for key, value in self.__dict__[dct_name].items() if key not in exclude_fields}
|
|
114
|
+
|
|
115
|
+
def to_raw(self) -> str:
|
|
116
|
+
return encoder.encode(self)
|
|
117
|
+
|
|
118
|
+
def to_dict(
|
|
119
|
+
self,
|
|
120
|
+
*,
|
|
121
|
+
exclude_fields: set[str] | None = None,
|
|
122
|
+
) -> dict[str, typing.Any]:
|
|
123
|
+
return self._to_dict("model_as_dict", exclude_fields or set(), full=False)
|
|
124
|
+
|
|
125
|
+
def to_full_dict(
|
|
126
|
+
self,
|
|
127
|
+
*,
|
|
128
|
+
exclude_fields: set[str] | None = None,
|
|
129
|
+
) -> dict[str, typing.Any]:
|
|
130
|
+
return self._to_dict("model_as_full_dict", exclude_fields or set(), full=True)
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
__all__ = ("UNSET", "From", "Model", "field", "is_none")
|
telegrinder/model.pyi
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import typing
|
|
2
|
+
|
|
3
|
+
import msgspec
|
|
4
|
+
from kungfu.library.monad.option import Nothing
|
|
5
|
+
|
|
6
|
+
UNSET: typing.Final = typing.cast("typing.Any", msgspec.UNSET)
|
|
7
|
+
|
|
8
|
+
def is_none(obj: typing.Any, /) -> typing.TypeIs[Nothing | None]: ...
|
|
9
|
+
|
|
10
|
+
@typing.overload
|
|
11
|
+
def field() -> typing.Any: ...
|
|
12
|
+
@typing.overload
|
|
13
|
+
def field(*, name: str | None = ...) -> typing.Any: ...
|
|
14
|
+
@typing.overload
|
|
15
|
+
def field(*, default: typing.Any, name: str | None = ...) -> typing.Any: ...
|
|
16
|
+
@typing.overload
|
|
17
|
+
def field(*, default_factory: typing.Callable[[], typing.Any], name: str | None = None) -> typing.Any: ...
|
|
18
|
+
@typing.overload
|
|
19
|
+
def field(*, converter: typing.Callable[[typing.Any], typing.Any], name: str | None = ...) -> typing.Any: ...
|
|
20
|
+
@typing.overload
|
|
21
|
+
def field(*, default: typing.Any, converter: typing.Callable[[typing.Any], typing.Any], name: str | None = ...) -> typing.Any: ...
|
|
22
|
+
@typing.overload
|
|
23
|
+
def field(
|
|
24
|
+
*,
|
|
25
|
+
default_factory: typing.Callable[[], typing.Any],
|
|
26
|
+
converter: typing.Callable[[typing.Any], typing.Any],
|
|
27
|
+
name: str | None = None,
|
|
28
|
+
) -> typing.Any: ...
|
|
29
|
+
|
|
30
|
+
class From[T]:
|
|
31
|
+
def __new__(cls, _: T, /) -> typing.Any: ...
|
|
32
|
+
|
|
33
|
+
@typing.dataclass_transform(field_specifiers=(field,))
|
|
34
|
+
class Model(msgspec.Struct, dict=True):
|
|
35
|
+
@classmethod
|
|
36
|
+
def get_fields(cls) -> typing.Mapping[str, msgspec.inspect.Field]: ...
|
|
37
|
+
@classmethod
|
|
38
|
+
def get_optional_fields(cls) -> typing.Iterable[str]: ...
|
|
39
|
+
@classmethod
|
|
40
|
+
def from_data[**P, T](cls: typing.Callable[P, T], *args: P.args, **kwargs: P.kwargs) -> T: ...
|
|
41
|
+
@classmethod
|
|
42
|
+
def from_dict(cls, obj: dict[str, typing.Any], /) -> typing.Self: ...
|
|
43
|
+
@classmethod
|
|
44
|
+
def from_raw(cls, raw: str | bytes, /) -> typing.Self: ...
|
|
45
|
+
def to_raw(self) -> str: ...
|
|
46
|
+
def to_dict(
|
|
47
|
+
self,
|
|
48
|
+
*,
|
|
49
|
+
exclude_fields: set[str] | None = None,
|
|
50
|
+
) -> dict[str, typing.Any]: ...
|
|
51
|
+
def to_full_dict(
|
|
52
|
+
self,
|
|
53
|
+
*,
|
|
54
|
+
exclude_fields: set[str] | None = None,
|
|
55
|
+
) -> dict[str, typing.Any]: ...
|
|
56
|
+
|
|
57
|
+
__all__ = ("UNSET", "From", "Model", "field", "is_none")
|