summaryrefslogtreecommitdiffstats
path: root/Lib/fnmatch.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1991-01-01 18:11:14 (GMT)
committerGuido van Rossum <guido@python.org>1991-01-01 18:11:14 (GMT)
commit762c39e9d28ab901393b88f641fe5fc8447baea8 (patch)
treea4248605e2b35907c4c3010ac23e69432142e160 /Lib/fnmatch.py
parentb5e05e95c3d336ba1b5fde7a6a55e4c92e508da6 (diff)
downloadcpython-762c39e9d28ab901393b88f641fe5fc8447baea8.zip
cpython-762c39e9d28ab901393b88f641fe5fc8447baea8.tar.gz
cpython-762c39e9d28ab901393b88f641fe5fc8447baea8.tar.bz2
Initial revision
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..c7caef6
--- /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