summaryrefslogtreecommitdiffstats
path: root/Lib/fnmatch.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1997-10-22 21:00:49 (GMT)
committerGuido van Rossum <guido@python.org>1997-10-22 21:00:49 (GMT)
commit9694fcab5332f27dc28b195ba1391e5491d2eaef (patch)
tree23dc3d9a7d1cc4b138ac2bffd028a519cba93b30 /Lib/fnmatch.py
parent426916e50e1209d8ecc12678855dc531863a48c5 (diff)
downloadcpython-9694fcab5332f27dc28b195ba1391e5491d2eaef.zip
cpython-9694fcab5332f27dc28b195ba1391e5491d2eaef.tar.gz
cpython-9694fcab5332f27dc28b195ba1391e5491d2eaef.tar.bz2
Convert all remaining *simple* cases of regex usage to re usage.
Diffstat (limited to 'Lib/fnmatch.py')
-rw-r--r--Lib/fnmatch.py15
1 files changed, 6 insertions, 9 deletions
diff --git a/Lib/fnmatch.py b/Lib/fnmatch.py
index 9b31856..ed81594 100644
--- a/Lib/fnmatch.py
+++ b/Lib/fnmatch.py
@@ -10,6 +10,8 @@ The function translate(PATTERN) returns a regular expression
corresponding to PATTERN. (It does not compile it.)
"""
+import re
+
_cache = {}
def fnmatch(name, pat):
@@ -42,11 +44,8 @@ def fnmatchcase(name, pat):
if not _cache.has_key(pat):
res = translate(pat)
- import regex
- save_syntax = regex.set_syntax(0)
- _cache[pat] = regex.compile(res)
- save_syntax = regex.set_syntax(save_syntax)
- return _cache[pat].match(name) == len(name)
+ _cache[pat] = re.compile(res)
+ return _cache[pat].match(name) is not None
def translate(pat):
"""Translate a shell PATTERN to a regular expression.
@@ -85,8 +84,6 @@ def translate(pat):
stuff = stuff[1:] + stuff[0]
stuff = '[' + stuff + ']'
res = res + stuff
- elif c in '\\.+^$':
- res = res + ('\\' + c)
else:
- res = res + c
- return res
+ res = res + re.escape(c)
+ return res + "$"