diff --git a/python-stdlib/fnmatch/fnmatch.py b/python-stdlib/fnmatch/fnmatch.py index 93b5d5214..71009afa2 100644 --- a/python-stdlib/fnmatch/fnmatch.py +++ b/python-stdlib/fnmatch/fnmatch.py @@ -9,14 +9,26 @@ The function translate(PATTERN) returns a regular expression corresponding to PATTERN. (It does not compile it.) """ -import os -import os.path import re -# import functools +try: + from os.path import normcase +except ImportError: + + def normcase(s): + """ + From os.path.normcase + Normalize the case of a pathname. On Windows, convert all characters + in the pathname to lowercase, and also convert forward slashes to + backward slashes. On other operating systems, return the path unchanged. + """ + return s + __all__ = ["filter", "fnmatch", "fnmatchcase", "translate"] +COMPAT = re.__name__ == "ure" + def fnmatch(name, pat): """Test whether FILENAME matches PATTERN. @@ -33,8 +45,8 @@ def fnmatch(name, pat): if the operating system requires it. If you don't want this, use fnmatchcase(FILENAME, PATTERN). """ - name = os.path.normcase(name) - pat = os.path.normcase(pat) + name = normcase(name) + pat = normcase(pat) return fnmatchcase(name, pat) @@ -46,16 +58,21 @@ def _compile_pattern(pat): res = bytes(res_str, "ISO-8859-1") else: res = translate(pat) + if COMPAT: + if res.startswith("(?ms)"): + res = res[5:] + if res.endswith("\\Z"): + res = res[:-2] + "$" return re.compile(res).match def filter(names, pat): """Return the subset of the list NAMES that match PAT.""" result = [] - pat = os.path.normcase(pat) + pat = normcase(pat) match = _compile_pattern(pat) for name in names: - if match(os.path.normcase(name)): + if match(normcase(name)): result.append(name) return result @@ -104,6 +121,15 @@ def translate(pat): stuff = "\\" + stuff res = "%s[%s]" % (res, stuff) else: - res = res + re.escape(c) + try: + res = res + re.escape(c) + except AttributeError: + # Using ure rather than re-pcre + res = res + re_escape(c) # Original patterns is undefined, see http://bugs.python.org/issue21464 return "(?ms)" + res + "\Z" + + +def re_escape(pattern): + # Replacement minimal re.escape for ure compatibility + return re.sub(r"([\^\$\.\|\?\*\+\(\)\[\\])", r"\\\1", pattern) diff --git a/python-stdlib/fnmatch/metadata.txt b/python-stdlib/fnmatch/metadata.txt index faa832140..27b8c03f3 100644 --- a/python-stdlib/fnmatch/metadata.txt +++ b/python-stdlib/fnmatch/metadata.txt @@ -1,4 +1,3 @@ srctype = cpython type = module -version = 0.5.2 -depends = os, os.path, re-pcre +version = 0.6.0 diff --git a/python-stdlib/fnmatch/setup.py b/python-stdlib/fnmatch/setup.py index 415804c01..06331a9cb 100644 --- a/python-stdlib/fnmatch/setup.py +++ b/python-stdlib/fnmatch/setup.py @@ -10,7 +10,7 @@ setup( name="micropython-fnmatch", - version="0.5.2", + version="0.6.0", description="CPython fnmatch module ported to MicroPython", long_description="This is a module ported from CPython standard library to be compatible with\nMicroPython interpreter. Usually, this means applying small patches for\nfeatures not supported (yet, or at all) in MicroPython. Sometimes, heavier\nchanges are required. Note that CPython modules are written with availability\nof vast resources in mind, and may not work for MicroPython ports with\nlimited heap. If you are affected by such a case, please help reimplement\nthe module from scratch.", url="https://github.com/micropython/micropython-lib", @@ -21,5 +21,4 @@ license="Python", cmdclass={"sdist": sdist_upip.sdist}, py_modules=["fnmatch"], - install_requires=["micropython-os", "micropython-os.path", "micropython-re-pcre"], ) diff --git a/python-stdlib/fnmatch/test_fnmatch.py b/python-stdlib/fnmatch/test_fnmatch.py index 1ddf8a607..4eaeec63b 100644 --- a/python-stdlib/fnmatch/test_fnmatch.py +++ b/python-stdlib/fnmatch/test_fnmatch.py @@ -10,7 +10,8 @@ class FnmatchTestCase(unittest.TestCase): def check_match(self, filename, pattern, should_match=1, fn=fnmatch): if should_match: self.assertTrue( - fn(filename, pattern), "expected %r to match pattern %r" % (filename, pattern) + fn(filename, pattern), + "expected %r to match pattern %r" % (filename, pattern), ) else: self.assertTrue( @@ -80,9 +81,9 @@ def test_filter(self): self.assertEqual(filter(["a", "b"], "a"), ["a"]) -def test_main(): +def main(): support.run_unittest(FnmatchTestCase, TranslateTestCase, FilterTestCase) if __name__ == "__main__": - test_main() + main() pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy