fnmatch: Remove dependency on os.path.

pull/490/head
Andrew Leech 2022-04-12 05:49:06 +10:00
rodzic dcdac1f552
commit 7259f0fd6f
3 zmienionych plików z 17 dodań i 9 usunięć

Wyświetl plik

@ -9,11 +9,21 @@ expression. They cache the compiled regular expressions for speed.
The function translate(PATTERN) returns a regular expression The function translate(PATTERN) returns a regular expression
corresponding to PATTERN. (It does not compile it.) corresponding to PATTERN. (It does not compile it.)
""" """
import os
import os.path
import re 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"] __all__ = ["filter", "fnmatch", "fnmatchcase", "translate"]
@ -35,8 +45,8 @@ def fnmatch(name, pat):
if the operating system requires it. if the operating system requires it.
If you don't want this, use fnmatchcase(FILENAME, PATTERN). If you don't want this, use fnmatchcase(FILENAME, PATTERN).
""" """
name = os.path.normcase(name) name = normcase(name)
pat = os.path.normcase(pat) pat = normcase(pat)
return fnmatchcase(name, pat) return fnmatchcase(name, pat)
@ -59,10 +69,10 @@ def _compile_pattern(pat):
def filter(names, pat): def filter(names, pat):
"""Return the subset of the list NAMES that match PAT.""" """Return the subset of the list NAMES that match PAT."""
result = [] result = []
pat = os.path.normcase(pat) pat = normcase(pat)
match = _compile_pattern(pat) match = _compile_pattern(pat)
for name in names: for name in names:
if match(os.path.normcase(name)): if match(normcase(name)):
result.append(name) result.append(name)
return result return result

Wyświetl plik

@ -1,4 +1,3 @@
srctype = cpython srctype = cpython
type = module type = module
version = 0.5.2 version = 0.5.2
depends = os, os.path

Wyświetl plik

@ -21,5 +21,4 @@ setup(
license="Python", license="Python",
cmdclass={"sdist": sdist_upip.sdist}, cmdclass={"sdist": sdist_upip.sdist},
py_modules=["fnmatch"], py_modules=["fnmatch"],
install_requires=["micropython-os", "micropython-os.path"],
) )