X Tutup
Skip to content

Commit 05a90dc

Browse files
committed
regexhandler/stringregexhandler: python2 utf8 support
1 parent 835c4d0 commit 05a90dc

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

telegram/ext/regexhandler.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
import re
2323

24+
from future.utils import string_types
25+
2426
from .handler import Handler
2527
from telegram import Update
2628

@@ -52,7 +54,7 @@ def __init__(self, pattern, callback, pass_groups=False,
5254
pass_groupdict=False, pass_update_queue=False):
5355
super(RegexHandler, self).__init__(callback, pass_update_queue)
5456

55-
if isinstance(pattern, str):
57+
if isinstance(pattern, string_types):
5658
pattern = re.compile(pattern)
5759

5860
self.pattern = pattern

telegram/ext/stringregexhandler.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
import re
2323

24+
from future.utils import string_types
25+
2426
from .handler import Handler
2527

2628

@@ -51,19 +53,16 @@ def __init__(self, pattern, callback, pass_groups=False,
5153
pass_groupdict=False, pass_update_queue=False):
5254
super(StringRegexHandler, self).__init__(callback, pass_update_queue)
5355

54-
if isinstance(pattern, str):
56+
if isinstance(pattern, string_types):
5557
pattern = re.compile(pattern)
5658

5759
self.pattern = pattern
5860
self.pass_groups = pass_groups
5961
self.pass_groupdict = pass_groupdict
6062

6163
def checkUpdate(self, update):
62-
if isinstance(update, str):
63-
match = re.match(self.pattern, update)
64-
return bool(match)
65-
else:
66-
return False
64+
return isinstance(update, string_types) and bool(
65+
re.match(self.pattern, update))
6766

6867
def handleUpdate(self, update, dispatcher):
6968
optional_args = self.collectOptionalArgs(dispatcher)

0 commit comments

Comments
 (0)
X Tutup