Merge branch 'master' into patch-4

This commit is contained in:
Mr. Dog 2020-08-04 19:49:55 +05:00 committed by GitHub
commit ce6a21cd09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 17 deletions

View File

@ -18,7 +18,7 @@ console_output_handler = logging.StreamHandler(sys.stderr)
console_output_handler.setFormatter(formatter)
logger.addHandler(console_output_handler)
logger.setLevel(logging.WARNING)
logger.setLevel(logging.ERROR)
from telebot import apihelper, types, util
from telebot.handler_backends import MemoryHandlerBackend, FileHandlerBackend

View File

@ -11,7 +11,6 @@ from requests.exceptions import HTTPError, ConnectionError, Timeout
try:
from requests.packages.urllib3 import fields
format_header_param = fields.format_header_param
except ImportError:
format_header_param = None
@ -131,7 +130,6 @@ def _check_result(method_name, result):
raise ApiHTTPException(method_name, result)
else:
raise ApiInvalidJSONException(method_name, result)
else:
if not result_json['ok']:
raise ApiTelegramException(method_name, result, result_json)

View File

@ -11,8 +11,11 @@ import six
from telebot import util
DISABLE_KEYLEN_ERROR = False
logger = logging.getLogger('TeleBot')
class JsonSerializable(object):
"""
Subclasses of this class are guaranteed to be able to be converted to JSON format.
@ -808,10 +811,14 @@ class ReplyKeyboardRemove(JsonSerializable):
class ReplyKeyboardMarkup(JsonSerializable):
max_row_keys = 12
def __init__(self, resize_keyboard=None, one_time_keyboard=None, selective=None, row_width=3):
if row_width>12:
logger.warning('Telegram does not support reply keyboard row width over 12')
row_width=12
if row_width > self.max_row_keys:
# Todo: Will be replaced with Exception in future releases
if not DISABLE_KEYLEN_ERROR:
logger.error('Telegram does not support reply keyboard row width over %d.' % self.max_row_keys)
row_width = self.max_row_keys
self.resize_keyboard = resize_keyboard
self.one_time_keyboard = one_time_keyboard
@ -830,12 +837,15 @@ class ReplyKeyboardMarkup(JsonSerializable):
:param row_width: width of row
:return: self, to allow function chaining.
"""
row_width = row_width or self.row_width
if row_width is None:
row_width = self.row_width
if row_width>12:
logger.warning('Telegram does not support reply keyboard row width over 12')
row_width=12
if row_width > self.max_row_keys:
# Todo: Will be replaced with Exception in future releases
if not DISABLE_KEYLEN_ERROR:
logger.error('Telegram does not support reply keyboard row width over %d.' % self.max_row_keys)
row_width = self.max_row_keys
for row in util.chunks(args, row_width):
button_array = []
@ -907,6 +917,8 @@ class KeyboardButtonPollType(Dictionaryable):
class InlineKeyboardMarkup(Dictionaryable, JsonSerializable):
max_row_keys = 12
def __init__(self, row_width=3):
"""
This object represents an inline keyboard that appears
@ -914,9 +926,10 @@ class InlineKeyboardMarkup(Dictionaryable, JsonSerializable):
:return:
"""
if row_width>8:
logger.warning('Telegram does not support inline keyboard row width over 8')
row_width=8
if row_width > self.max_row_keys:
# Todo: Will be replaced with Exception in future releases
logger.error('Telegram does not support inline keyboard row width over %d.' % self.max_row_keys)
row_width = self.max_row_keys
self.row_width = row_width
self.keyboard = []
@ -936,11 +949,13 @@ class InlineKeyboardMarkup(Dictionaryable, JsonSerializable):
:param row_width: width of row
:return: self, to allow function chaining.
"""
row_width = row_width or self.row_width
if row_width is None:
row_width = self.row_width
if row_width>8:
logger.warning('Telegram does not support inline keyboard row width over 8')
row_width=8
if row_width > self.max_row_keys:
# Todo: Will be replaced with Exception in future releases
logger.error('Telegram does not support inline keyboard row width over %d.' % self.max_row_keys)
row_width = self.max_row_keys
for row in util.chunks(args, row_width):
button_array = [button.to_dict() for button in row]