Total Complexity | 6 |
Total Lines | 48 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | # -*- coding:utf-8 -*- |
||
2 | 1 | """ |
|
3 | This module contains all checks for Keyboa Button class parameters |
||
4 | """ |
||
5 | # pylint: disable = C0116 |
||
6 | |||
7 | 1 | from keyboa.constants import ( |
|
8 | InlineKeyboardButton, |
||
9 | InlineButtonData, |
||
10 | callback_data_types, |
||
11 | MAXIMUM_CBD_LENGTH, |
||
12 | ) |
||
13 | |||
14 | |||
15 | 1 | class ButtonCheck: |
|
16 | """ |
||
17 | This class contains all checks for Keyboa Button class parameters |
||
18 | """ |
||
19 | |||
20 | 1 | @staticmethod |
|
21 | 1 | def is_button_data_proper_type(button_data) -> None: |
|
22 | 1 | if not isinstance(button_data, (tuple, dict, str, int)): |
|
23 | 1 | type_error_message = ( |
|
24 | "Cannot create %s from %s. Please use %s instead.\n" |
||
25 | "Probably you specified 'auto_alignment' or 'items_in_line' " |
||
26 | "parameter for StructuredSequence." |
||
27 | % (InlineKeyboardButton, type(button_data), InlineButtonData) |
||
28 | ) |
||
29 | 1 | raise TypeError(type_error_message) |
|
30 | |||
31 | 1 | @staticmethod |
|
32 | 1 | def is_callback_proper_type(callback) -> None: |
|
33 | 1 | if not isinstance(callback, callback_data_types): |
|
34 | 1 | type_error_message = "Callback cannot be %s. Only %s allowed." % ( |
|
35 | type(callback), |
||
36 | callback_data_types, |
||
37 | ) |
||
38 | 1 | raise TypeError(type_error_message) |
|
39 | |||
40 | 1 | @staticmethod |
|
41 | 1 | def is_callback_data_in_limits(callback_data) -> None: |
|
42 | 1 | if len(callback_data.encode()) > MAXIMUM_CBD_LENGTH: |
|
43 | 1 | size_error_message = ( |
|
44 | "The callback data cannot be more than " |
||
45 | "64 bytes for one button. Your size is %s" % len(callback_data.encode()) |
||
46 | ) |
||
47 | raise ValueError(size_error_message) |
||
48 |