From dcdac1f552d2684751ff0f75d20030b12e97407f Mon Sep 17 00:00:00 2001 From: Andrew Leech Date: Fri, 18 Mar 2022 12:41:10 +1100 Subject: [PATCH 1/3] fnmatch: Add ure compatibility. Removes dependency on re-pcre which is only available on unix port. --- python-stdlib/fnmatch/fnmatch.py | 18 +++++++++++++++++- python-stdlib/fnmatch/metadata.txt | 2 +- python-stdlib/fnmatch/setup.py | 2 +- python-stdlib/fnmatch/test_fnmatch.py | 7 ++++--- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/python-stdlib/fnmatch/fnmatch.py b/python-stdlib/fnmatch/fnmatch.py index 93b5d5214..f573d75c6 100644 --- a/python-stdlib/fnmatch/fnmatch.py +++ b/python-stdlib/fnmatch/fnmatch.py @@ -17,6 +17,8 @@ __all__ = ["filter", "fnmatch", "fnmatchcase", "translate"] +COMPAT = re.__name__ == "ure" + def fnmatch(name, pat): """Test whether FILENAME matches PATTERN. @@ -46,6 +48,11 @@ 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 @@ -104,6 +111,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..5eb297d46 100644 --- a/python-stdlib/fnmatch/metadata.txt +++ b/python-stdlib/fnmatch/metadata.txt @@ -1,4 +1,4 @@ srctype = cpython type = module version = 0.5.2 -depends = os, os.path, re-pcre +depends = os, os.path diff --git a/python-stdlib/fnmatch/setup.py b/python-stdlib/fnmatch/setup.py index 415804c01..5a9ac6323 100644 --- a/python-stdlib/fnmatch/setup.py +++ b/python-stdlib/fnmatch/setup.py @@ -21,5 +21,5 @@ license="Python", cmdclass={"sdist": sdist_upip.sdist}, py_modules=["fnmatch"], - install_requires=["micropython-os", "micropython-os.path", "micropython-re-pcre"], + install_requires=["micropython-os", "micropython-os.path"], ) 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() From 7259f0fd6f8759646d044eee2a40a6456734aca6 Mon Sep 17 00:00:00 2001 From: Andrew Leech Date: Tue, 12 Apr 2022 05:49:06 +1000 Subject: [PATCH 2/3] fnmatch: Remove dependency on os.path. --- python-stdlib/fnmatch/fnmatch.py | 24 +++++++++++++++++------- python-stdlib/fnmatch/metadata.txt | 1 - python-stdlib/fnmatch/setup.py | 1 - 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/python-stdlib/fnmatch/fnmatch.py b/python-stdlib/fnmatch/fnmatch.py index f573d75c6..71009afa2 100644 --- a/python-stdlib/fnmatch/fnmatch.py +++ b/python-stdlib/fnmatch/fnmatch.py @@ -9,11 +9,21 @@ 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"] @@ -35,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) @@ -59,10 +69,10 @@ def _compile_pattern(pat): 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 diff --git a/python-stdlib/fnmatch/metadata.txt b/python-stdlib/fnmatch/metadata.txt index 5eb297d46..10b54b832 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 diff --git a/python-stdlib/fnmatch/setup.py b/python-stdlib/fnmatch/setup.py index 5a9ac6323..7ca64ddf8 100644 --- a/python-stdlib/fnmatch/setup.py +++ b/python-stdlib/fnmatch/setup.py @@ -21,5 +21,4 @@ license="Python", cmdclass={"sdist": sdist_upip.sdist}, py_modules=["fnmatch"], - install_requires=["micropython-os", "micropython-os.path"], ) From d64557a2114d4c366242e929af15dd61b6ff7f4b Mon Sep 17 00:00:00 2001 From: Andrew Leech Date: Fri, 18 Mar 2022 12:42:00 +1100 Subject: [PATCH 3/3] fnmatch: Release 0.6.0. --- python-stdlib/fnmatch/metadata.txt | 2 +- python-stdlib/fnmatch/setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/python-stdlib/fnmatch/metadata.txt b/python-stdlib/fnmatch/metadata.txt index 10b54b832..27b8c03f3 100644 --- a/python-stdlib/fnmatch/metadata.txt +++ b/python-stdlib/fnmatch/metadata.txt @@ -1,3 +1,3 @@ srctype = cpython type = module -version = 0.5.2 +version = 0.6.0 diff --git a/python-stdlib/fnmatch/setup.py b/python-stdlib/fnmatch/setup.py index 7ca64ddf8..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", 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