mirror of
https://github.com/eternnoir/pyTelegramBotAPI.git
synced 2023-08-10 21:12:57 +03:00
more descriptive exceptions
This commit is contained in:
@@ -61,16 +61,16 @@ class TextFilter:
|
|||||||
raise ValueError('None of the check modes was specified')
|
raise ValueError('None of the check modes was specified')
|
||||||
|
|
||||||
self.equals = equals
|
self.equals = equals
|
||||||
self.contains = self._check_iterable(contains)
|
self.contains = self._check_iterable(contains, filter_name='contains')
|
||||||
self.starts_with = self._check_iterable(starts_with)
|
self.starts_with = self._check_iterable(starts_with, filter_name='starts_with')
|
||||||
self.ends_with = self._check_iterable(ends_with)
|
self.ends_with = self._check_iterable(ends_with, filter_name='ends_with')
|
||||||
self.ignore_case = ignore_case
|
self.ignore_case = ignore_case
|
||||||
|
|
||||||
def _check_iterable(self, iterable):
|
def _check_iterable(self, iterable, filter_name):
|
||||||
if not iterable:
|
if not iterable:
|
||||||
pass
|
pass
|
||||||
elif not isinstance(iterable, str) and not isinstance(iterable, list) and not isinstance(iterable, tuple):
|
elif not isinstance(iterable, str) and not isinstance(iterable, list) and not isinstance(iterable, tuple):
|
||||||
raise ValueError
|
raise ValueError(f"Incorrect value of {filter_name!r}")
|
||||||
elif isinstance(iterable, str):
|
elif isinstance(iterable, str):
|
||||||
iterable = [iterable]
|
iterable = [iterable]
|
||||||
elif isinstance(iterable, list) or isinstance(iterable, tuple):
|
elif isinstance(iterable, list) or isinstance(iterable, tuple):
|
||||||
|
|||||||
@@ -61,16 +61,16 @@ class TextFilter:
|
|||||||
raise ValueError('None of the check modes was specified')
|
raise ValueError('None of the check modes was specified')
|
||||||
|
|
||||||
self.equals = equals
|
self.equals = equals
|
||||||
self.contains = self._check_iterable(contains)
|
self.contains = self._check_iterable(contains, filter_name='contains')
|
||||||
self.starts_with = self._check_iterable(starts_with)
|
self.starts_with = self._check_iterable(starts_with, filter_name='starts_with')
|
||||||
self.ends_with = self._check_iterable(ends_with)
|
self.ends_with = self._check_iterable(ends_with, filter_name='ends_with')
|
||||||
self.ignore_case = ignore_case
|
self.ignore_case = ignore_case
|
||||||
|
|
||||||
def _check_iterable(self, iterable):
|
def _check_iterable(self, iterable, filter_name: str):
|
||||||
if not iterable:
|
if not iterable:
|
||||||
pass
|
pass
|
||||||
elif not isinstance(iterable, str) and not isinstance(iterable, list) and not isinstance(iterable, tuple):
|
elif not isinstance(iterable, str) and not isinstance(iterable, list) and not isinstance(iterable, tuple):
|
||||||
raise ValueError
|
raise ValueError(f"Incorrect value of {filter_name!r}")
|
||||||
elif isinstance(iterable, str):
|
elif isinstance(iterable, str):
|
||||||
iterable = [iterable]
|
iterable = [iterable]
|
||||||
elif isinstance(iterable, list) or isinstance(iterable, tuple):
|
elif isinstance(iterable, list) or isinstance(iterable, tuple):
|
||||||
|
|||||||
Reference in New Issue
Block a user