kopia lustrzana https://github.com/micropython/micropython-lib
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 <andrew.leech@planetinnovation.com.au>pull/698/head
rodzic
6103823b1b
commit
e45a7f6c18
|
@ -27,8 +27,6 @@ except ImportError:
|
||||||
|
|
||||||
__all__ = ["filter", "fnmatch", "fnmatchcase", "translate"]
|
__all__ = ["filter", "fnmatch", "fnmatchcase", "translate"]
|
||||||
|
|
||||||
COMPAT = re.__name__ == "ure"
|
|
||||||
|
|
||||||
|
|
||||||
def fnmatch(name, pat):
|
def fnmatch(name, pat):
|
||||||
"""Test whether FILENAME matches PATTERN.
|
"""Test whether FILENAME matches PATTERN.
|
||||||
|
@ -58,12 +56,18 @@ def _compile_pattern(pat):
|
||||||
res = bytes(res_str, "ISO-8859-1")
|
res = bytes(res_str, "ISO-8859-1")
|
||||||
else:
|
else:
|
||||||
res = translate(pat)
|
res = translate(pat)
|
||||||
if COMPAT:
|
|
||||||
|
try:
|
||||||
|
ptn = re.compile(res)
|
||||||
|
except ValueError:
|
||||||
|
# re1.5 doesn't support all regex features
|
||||||
if res.startswith("(?ms)"):
|
if res.startswith("(?ms)"):
|
||||||
res = res[5:]
|
res = res[5:]
|
||||||
if res.endswith("\\Z"):
|
if res.endswith("\\Z"):
|
||||||
res = res[:-2] + "$"
|
res = res[:-2] + "$"
|
||||||
return re.compile(res).match
|
ptn = re.compile(res)
|
||||||
|
|
||||||
|
return ptn.match
|
||||||
|
|
||||||
|
|
||||||
def filter(names, pat):
|
def filter(names, pat):
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
metadata(version="0.6.0")
|
metadata(version="0.6.1")
|
||||||
|
|
||||||
module("fnmatch.py")
|
module("fnmatch.py")
|
||||||
|
|
Ładowanie…
Reference in New Issue