Skip to content

Commit 03fe27f

Browse files
committed
stdlib/fnmatch: Fix compatibility with ure -> re.
Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
1 parent c113611 commit 03fe27f

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

python-stdlib/fnmatch/fnmatch.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ def normcase(s):
2727

2828
__all__ = ["filter", "fnmatch", "fnmatchcase", "translate"]
2929

30-
COMPAT = re.__name__ == "ure"
31-
3230

3331
def fnmatch(name, pat):
3432
"""Test whether FILENAME matches PATTERN.
@@ -58,12 +56,18 @@ def _compile_pattern(pat):
5856
res = bytes(res_str, "ISO-8859-1")
5957
else:
6058
res = translate(pat)
61-
if COMPAT:
59+
60+
try:
61+
ptn = re.compile(res)
62+
except ValueError:
63+
# re1.5 doesn't support all regex features
6264
if res.startswith("(?ms)"):
6365
res = res[5:]
6466
if res.endswith("\\Z"):
6567
res = res[:-2] + "$"
66-
return re.compile(res).match
68+
ptn = re.compile(res)
69+
70+
return ptn.match
6771

6872

6973
def filter(names, pat):

0 commit comments

Comments
 (0)