aboutsummaryrefslogtreecommitdiff
path: root/lib/fnmatch.py
diff options
context:
space:
mode:
authorSkip Montanaro <[email protected]>2021-02-16 14:40:46 -0600
committerSkip Montanaro <[email protected]>2021-02-16 14:40:46 -0600
commita19a216bc60160c162e616145ef091dd18ce4e61 (patch)
treefa4bdff21f9b04a125c84a2bfab8a1c738359e15 /lib/fnmatch.py
downloadpython-0.9.1-patched-QoL-a19a216bc60160c162e616145ef091dd18ce4e61.tar.xz
python-0.9.1-patched-QoL-a19a216bc60160c162e616145ef091dd18ce4e61.zip
Python 0.9.1 as posted in alt.sources
Diffstat (limited to 'lib/fnmatch.py')
-rw-r--r--lib/fnmatch.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/fnmatch.py b/lib/fnmatch.py
new file mode 100644
index 0000000..8f9e318
--- /dev/null
+++ b/lib/fnmatch.py
@@ -0,0 +1,35 @@
+# module 'fnmatch' -- filename matching with shell patterns
+
+# XXX [] patterns are not supported (but recognized)
+
+def fnmatch(name, pat):
+ if '*' in pat or '?' in pat or '[' in pat:
+ return fnmatch1(name, pat)
+ return name = pat
+
+def fnmatch1(name, pat):
+ for i in range(len(pat)):
+ c = pat[i]
+ if c = '*':
+ restpat = pat[i+1:]
+ if '*' in restpat or '?' in restpat or '[' in restpat:
+ for i in range(i, len(name)):
+ if fnmatch1(name[i:], restpat):
+ return 1
+ return 0
+ else:
+ return name[len(name)-len(restpat):] = restpat
+ elif c = '?':
+ if len(name) <= i : return 0
+ elif c = '[':
+ return 0 # XXX
+ else:
+ if name[i:i+1] <> c:
+ return 0
+ return 1
+
+def fnmatchlist(names, pat):
+ res = []
+ for name in names:
+ if fnmatch(name, pat): res.append(name)
+ return res