mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2024-12-23 06:50:29 +01:00
regexhandler/stringregexhandler: python2 utf8 support
This commit is contained in:
parent
835c4d04c1
commit
05a90dc3bc
2 changed files with 8 additions and 7 deletions
|
@ -21,6 +21,8 @@
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
from future.utils import string_types
|
||||||
|
|
||||||
from .handler import Handler
|
from .handler import Handler
|
||||||
from telegram import Update
|
from telegram import Update
|
||||||
|
|
||||||
|
@ -52,7 +54,7 @@ class RegexHandler(Handler):
|
||||||
pass_groupdict=False, pass_update_queue=False):
|
pass_groupdict=False, pass_update_queue=False):
|
||||||
super(RegexHandler, self).__init__(callback, pass_update_queue)
|
super(RegexHandler, self).__init__(callback, pass_update_queue)
|
||||||
|
|
||||||
if isinstance(pattern, str):
|
if isinstance(pattern, string_types):
|
||||||
pattern = re.compile(pattern)
|
pattern = re.compile(pattern)
|
||||||
|
|
||||||
self.pattern = pattern
|
self.pattern = pattern
|
||||||
|
|
|
@ -21,6 +21,8 @@
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
from future.utils import string_types
|
||||||
|
|
||||||
from .handler import Handler
|
from .handler import Handler
|
||||||
|
|
||||||
|
|
||||||
|
@ -51,7 +53,7 @@ class StringRegexHandler(Handler):
|
||||||
pass_groupdict=False, pass_update_queue=False):
|
pass_groupdict=False, pass_update_queue=False):
|
||||||
super(StringRegexHandler, self).__init__(callback, pass_update_queue)
|
super(StringRegexHandler, self).__init__(callback, pass_update_queue)
|
||||||
|
|
||||||
if isinstance(pattern, str):
|
if isinstance(pattern, string_types):
|
||||||
pattern = re.compile(pattern)
|
pattern = re.compile(pattern)
|
||||||
|
|
||||||
self.pattern = pattern
|
self.pattern = pattern
|
||||||
|
@ -59,11 +61,8 @@ class StringRegexHandler(Handler):
|
||||||
self.pass_groupdict = pass_groupdict
|
self.pass_groupdict = pass_groupdict
|
||||||
|
|
||||||
def checkUpdate(self, update):
|
def checkUpdate(self, update):
|
||||||
if isinstance(update, str):
|
return isinstance(update, string_types) and bool(
|
||||||
match = re.match(self.pattern, update)
|
re.match(self.pattern, update))
|
||||||
return bool(match)
|
|
||||||
else:
|
|
||||||
return False
|
|
||||||
|
|
||||||
def handleUpdate(self, update, dispatcher):
|
def handleUpdate(self, update, dispatcher):
|
||||||
optional_args = self.collectOptionalArgs(dispatcher)
|
optional_args = self.collectOptionalArgs(dispatcher)
|
||||||
|
|
Loading…
Reference in a new issue