From e45a7f6c185f65b7179e71ad1a3b7e25fd1c3441 Mon Sep 17 00:00:00 2001 From: Andrew Leech Date: Thu, 6 Jul 2023 13:53:43 +1000 Subject: [PATCH] fnmatch: Fix compatibility with ure -> re. With the recent MicroPython change to remove the u prefix by default on builtins (micropython/micropython#11740) the format checker in fnmatch which was detecting ure no longer works. This commit updates the module to filter the regex automatically as needed. Signed-off-by: Andrew Leech --- python-stdlib/fnmatch/fnmatch.py | 12 ++++++++---- python-stdlib/fnmatch/manifest.py | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/python-stdlib/fnmatch/fnmatch.py b/python-stdlib/fnmatch/fnmatch.py index 71009af..2b42c3b 100644 --- a/python-stdlib/fnmatch/fnmatch.py +++ b/python-stdlib/fnmatch/fnmatch.py @@ -27,8 +27,6 @@ except ImportError: __all__ = ["filter", "fnmatch", "fnmatchcase", "translate"] -COMPAT = re.__name__ == "ure" - def fnmatch(name, pat): """Test whether FILENAME matches PATTERN. @@ -58,12 +56,18 @@ def _compile_pattern(pat): res = bytes(res_str, "ISO-8859-1") else: res = translate(pat) - if COMPAT: + + try: + ptn = re.compile(res) + except ValueError: + # re1.5 doesn't support all regex features if res.startswith("(?ms)"): res = res[5:] if res.endswith("\\Z"): res = res[:-2] + "$" - return re.compile(res).match + ptn = re.compile(res) + + return ptn.match def filter(names, pat): diff --git a/python-stdlib/fnmatch/manifest.py b/python-stdlib/fnmatch/manifest.py index 8f19bb8..f4318b3 100644 --- a/python-stdlib/fnmatch/manifest.py +++ b/python-stdlib/fnmatch/manifest.py @@ -1,3 +1,3 @@ -metadata(version="0.6.0") +metadata(version="0.6.1") module("fnmatch.py")