Skip to content

Commit d6b9819

Browse files
committed
Add re.ASCII flag to USERNAME_REGEX if python version >= 3, temp fix for japanese character test problem
1 parent 049f1d2 commit d6b9819

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

ttp/ttp.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,14 @@
2020
from __future__ import unicode_literals
2121

2222
import re
23+
import sys
2324
try:
2425
from urllib.parse import quote # Python3
2526
except ImportError:
2627
from urllib import quote
2728

2829
__version__ = "1.0.3.0"
2930

30-
# Some of this code has been translated from the twitter-text-java library:
31-
# <http://github.com/mzsanford/twitter-text-java>
3231
AT_SIGNS = r'[@\uff20]'
3332
UTF_CHARS = r'a-z0-9_\u00c0-\u00d6\u00d8-\u00f6\u00f8-\u00ff'
3433
SPACES = r'[\u0020\u00A0\u1680\u180E\u2002-\u202F\u205F\u2060\u3000]'
@@ -40,7 +39,11 @@
4039
re.IGNORECASE)
4140

4241
# Users
43-
USERNAME_REGEX = re.compile(r'\B' + AT_SIGNS + LIST_END_CHARS, re.IGNORECASE)
42+
if sys.version_info >= (3, 0):
43+
username_flags = re.ASCII | re.IGNORECASE
44+
else:
45+
username_flags = re.IGNORECASE
46+
USERNAME_REGEX = re.compile(r'\B' + AT_SIGNS + LIST_END_CHARS, username_flags)
4447
REPLY_REGEX = re.compile(r'^(?:' + SPACES + r')*' + AT_SIGNS
4548
+ r'([a-z0-9_]{1,20}).*', re.IGNORECASE)
4649

0 commit comments

Comments
 (0)