summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFred Drake <fdrake@acm.org>2001-03-21 18:05:48 (GMT)
committerFred Drake <fdrake@acm.org>2001-03-21 18:05:48 (GMT)
commit46d9fda0080bb818a37e63e1156949a11f8f80e8 (patch)
tree33c5a53081e93c5c88cb3392a96b214ecc7895d9
parent22710823fb554a796dc96c44885d7a9389426824 (diff)
downloadcpython-46d9fda0080bb818a37e63e1156949a11f8f80e8.zip
cpython-46d9fda0080bb818a37e63e1156949a11f8f80e8.tar.gz
cpython-46d9fda0080bb818a37e63e1156949a11f8f80e8.tar.bz2
Donovan Baarda <abo@users.sourceforge.net>:
Patch to make "\" in a character group work properly. This closes SF bug #409651.
-rw-r--r--Lib/fnmatch.py14
1 files changed, 5 insertions, 9 deletions
diff --git a/Lib/fnmatch.py b/Lib/fnmatch.py
index c40f500..182a9ef 100644
--- a/Lib/fnmatch.py
+++ b/Lib/fnmatch.py
@@ -75,17 +75,13 @@ def translate(pat):
if j >= n:
res = res + '\\['
else:
- stuff = pat[i:j]
+ stuff = pat[i:j].replace('\\','\\\\')
i = j+1
if stuff[0] == '!':
- stuff = '[^' + stuff[1:] + ']'
- elif stuff == '^'*len(stuff):
- stuff = '\\^'
- else:
- while stuff[0] == '^':
- stuff = stuff[1:] + stuff[0]
- stuff = '[' + stuff + ']'
- res = res + stuff
+ stuff = '^' + stuff[1:]
+ elif stuff[0] == '^':
+ stuff = '\\' + stuff
+ res = '%s[%s]' % (res, stuff)
else:
res = res + re.escape(c)
return res + "$"