diff --git a/telegram/ext/regexhandler.py b/telegram/ext/regexhandler.py index ec4da53f4..c3a7f976b 100644 --- a/telegram/ext/regexhandler.py +++ b/telegram/ext/regexhandler.py @@ -21,6 +21,8 @@ import re +from future.utils import string_types + from .handler import Handler from telegram import Update @@ -52,7 +54,7 @@ class RegexHandler(Handler): pass_groupdict=False, pass_update_queue=False): super(RegexHandler, self).__init__(callback, pass_update_queue) - if isinstance(pattern, str): + if isinstance(pattern, string_types): pattern = re.compile(pattern) self.pattern = pattern diff --git a/telegram/ext/stringregexhandler.py b/telegram/ext/stringregexhandler.py index c064ff8cb..6ea748fd2 100644 --- a/telegram/ext/stringregexhandler.py +++ b/telegram/ext/stringregexhandler.py @@ -21,6 +21,8 @@ import re +from future.utils import string_types + from .handler import Handler @@ -51,7 +53,7 @@ class StringRegexHandler(Handler): pass_groupdict=False, pass_update_queue=False): super(StringRegexHandler, self).__init__(callback, pass_update_queue) - if isinstance(pattern, str): + if isinstance(pattern, string_types): pattern = re.compile(pattern) self.pattern = pattern @@ -59,11 +61,8 @@ class StringRegexHandler(Handler): self.pass_groupdict = pass_groupdict def checkUpdate(self, update): - if isinstance(update, str): - match = re.match(self.pattern, update) - return bool(match) - else: - return False + return isinstance(update, string_types) and bool( + re.match(self.pattern, update)) def handleUpdate(self, update, dispatcher): optional_args = self.collectOptionalArgs(dispatcher)