2023-02-05 18:09:55 +01:00
|
|
|
#
|
|
|
|
# A library that provides a Python interface to the Telegram Bot API
|
|
|
|
# Copyright (C) 2015-2023
|
|
|
|
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Lesser Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Lesser Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Lesser Public License
|
|
|
|
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
|
|
|
import inspect
|
|
|
|
|
|
|
|
keyword_args = [
|
2023-11-05 11:47:50 +01:00
|
|
|
"Keyword Arguments:",
|
2023-09-22 18:19:21 +02:00
|
|
|
(
|
2023-11-05 11:47:50 +01:00
|
|
|
" read_timeout ({read_timeout_type}, optional): Value to pass to "
|
|
|
|
" :paramref:`telegram.request.BaseRequest.post.read_timeout`. Defaults to "
|
|
|
|
" {read_timeout}."
|
2023-09-22 18:19:21 +02:00
|
|
|
),
|
|
|
|
(
|
2023-11-05 11:47:50 +01:00
|
|
|
" write_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to "
|
|
|
|
" :paramref:`telegram.request.BaseRequest.post.write_timeout`. Defaults to "
|
|
|
|
" {write_timeout}."
|
2023-09-22 18:19:21 +02:00
|
|
|
),
|
|
|
|
(
|
2023-11-05 11:47:50 +01:00
|
|
|
" connect_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to "
|
|
|
|
" :paramref:`telegram.request.BaseRequest.post.connect_timeout`. Defaults to "
|
|
|
|
" :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`."
|
2023-09-22 18:19:21 +02:00
|
|
|
),
|
|
|
|
(
|
2023-11-05 11:47:50 +01:00
|
|
|
" pool_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to "
|
|
|
|
" :paramref:`telegram.request.BaseRequest.post.pool_timeout`. Defaults to "
|
|
|
|
" :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`."
|
2023-09-22 18:19:21 +02:00
|
|
|
),
|
|
|
|
(
|
2023-11-05 11:47:50 +01:00
|
|
|
" api_kwargs (:obj:`dict`, optional): Arbitrary keyword arguments"
|
|
|
|
" to be passed to the Telegram API."
|
2023-09-22 18:19:21 +02:00
|
|
|
),
|
2023-02-05 18:09:55 +01:00
|
|
|
"",
|
|
|
|
]
|
|
|
|
write_timeout_sub = [":attr:`~telegram.request.BaseRequest.DEFAULT_NONE`", "``20``"]
|
|
|
|
read_timeout_sub = [
|
2023-09-03 14:13:19 +02:00
|
|
|
":attr:`~telegram.request.BaseRequest.DEFAULT_NONE`",
|
2023-02-05 18:09:55 +01:00
|
|
|
"``2``. :paramref:`timeout` will be added to this value",
|
|
|
|
]
|
|
|
|
read_timeout_type = [":obj:`float` | :obj:`None`", ":obj:`float`"]
|
|
|
|
|
|
|
|
|
|
|
|
def find_insert_pos_for_kwargs(lines: list[str]) -> int:
|
|
|
|
"""Finds the correct position to insert the keyword arguments and returns the index."""
|
|
|
|
for idx, value in reversed(list(enumerate(lines))): # reversed since :returns: is at the end
|
2023-11-05 11:47:50 +01:00
|
|
|
if value.startswith("Returns"):
|
2023-02-05 18:09:55 +01:00
|
|
|
return idx
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
def is_write_timeout_20(obj: object) -> int:
|
|
|
|
"""inspects the default value of write_timeout parameter of the bot method."""
|
|
|
|
sig = inspect.signature(obj)
|
|
|
|
return 1 if (sig.parameters["write_timeout"].default == 20) else 0
|
|
|
|
|
|
|
|
|
|
|
|
def check_timeout_and_api_kwargs_presence(obj: object) -> int:
|
|
|
|
"""Checks if the method has timeout and api_kwargs keyword only parameters."""
|
|
|
|
sig = inspect.signature(obj)
|
|
|
|
params_to_check = (
|
|
|
|
"read_timeout",
|
|
|
|
"write_timeout",
|
|
|
|
"connect_timeout",
|
|
|
|
"pool_timeout",
|
|
|
|
"api_kwargs",
|
|
|
|
)
|
|
|
|
return all(
|
|
|
|
param in sig.parameters and sig.parameters[param].kind == inspect.Parameter.KEYWORD_ONLY
|
|
|
|
for param in params_to_check
|
|
|
|
)
|