Skip to content

Commit 414c991

Browse files
committed
Test unicode flag repr
1 parent bb43b68 commit 414c991

File tree

2 files changed

+27
-7
lines changed
  • graalpython

2 files changed

+27
-7
lines changed

graalpython/com.oracle.graal.python.test/src/tests/unittest_tags/test_re.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*graalpython.lib-python.3.test.test_re.PatternReprTests.test_multiple_flags
77
*graalpython.lib-python.3.test.test_re.PatternReprTests.test_quotes
88
*graalpython.lib-python.3.test.test_re.PatternReprTests.test_single_flag
9+
*graalpython.lib-python.3.test.test_re.PatternReprTests.test_unicode_flag
910
*graalpython.lib-python.3.test.test_re.PatternReprTests.test_unknown_flags
1011
*graalpython.lib-python.3.test.test_re.PatternReprTests.test_without_flags
1112
*graalpython.lib-python.3.test.test_re.ReTests.test_anyall

graalpython/lib-graalpython/_sre.py

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,26 @@ def setup(sre_compiler, error_class, flags_table):
135135
MAGIC = 20171005
136136
MAXREPEAT = 4294967295
137137
MAXGROUPS = 2147483647
138-
FLAG_NAMES = ["re.TEMPLATE", "re.IGNORECASE", "re.LOCALE", "re.MULTILINE",
139-
"re.DOTALL", "re.UNICODE", "re.VERBOSE", "re.DEBUG",
140-
"re.ASCII"]
138+
FLAG_TEMPLATE = 1
139+
FLAG_IGNORECASE = 2
140+
FLAG_LOCALE = 4
141+
FLAG_MULTILINE = 8
142+
FLAG_DOTALL = 16
143+
FLAG_UNICODE = 32
144+
FLAG_VERBOSE = 64
145+
FLAG_DEBUG = 128
146+
FLAG_ASCII = 256
147+
FLAG_NAMES = [
148+
(FLAG_TEMPLATE, "re.TEMPLATE"),
149+
(FLAG_IGNORECASE, "re.IGNORECASE"),
150+
(FLAG_LOCALE, "re.LOCALE"),
151+
(FLAG_MULTILINE, "re.MULTILINE"),
152+
(FLAG_DOTALL, "re.DOTALL"),
153+
(FLAG_UNICODE, "re.UNICODE"),
154+
(FLAG_VERBOSE, "re.VERBOSE"),
155+
(FLAG_DEBUG, "re.DEBUG"),
156+
(FLAG_ASCII, "re.ASCII"),
157+
]
141158

142159

143160
class SRE_Match():
@@ -269,13 +286,15 @@ def __tregex_compile(self, pattern, flags=None):
269286
raise
270287
return self.__compiled_regexes[(pattern, flags)]
271288

272-
273289
def __repr__(self):
274290
flags = self.flags
275291
flag_items = []
276-
for i,name in enumerate(FLAG_NAMES):
277-
if flags & (1 << i):
278-
flags -= (1 << i)
292+
if not self.__binary:
293+
if (flags & (FLAG_LOCALE | FLAG_UNICODE | FLAG_ASCII)) == FLAG_UNICODE:
294+
flags &= ~FLAG_UNICODE
295+
for code, name in FLAG_NAMES:
296+
if flags & code:
297+
flags -= code
279298
flag_items.append(name)
280299
if flags != 0:
281300
flag_items.append("0x%x" % flags)

0 commit comments

Comments
 (0)