summaryrefslogtreecommitdiff
path: root/Lib/fnmatch.py
diff options
context:
space:
mode:
authorFred Drake <fdrake@acm.org>2001-03-21 18:05:48 +0000
committerFred Drake <fdrake@acm.org>2001-03-21 18:05:48 +0000
commitbceb6948920e9442b8ed33e9ee46ea73317d9794 (patch)
tree1b0a290dfea5a722bfe10960a938c5002851654f /Lib/fnmatch.py
parent51fbbe3e069f4654006d110e878c3d6d980c1cb0 (diff)
downloadcpython-bceb6948920e9442b8ed33e9ee46ea73317d9794.tar.gz
Donovan Baarda <abo@users.sourceforge.net>:
Patch to make "\" in a character group work properly. This closes SF bug #409651.
Diffstat (limited to 'Lib/fnmatch.py')
-rw-r--r--Lib/fnmatch.py14
1 files changed, 5 insertions, 9 deletions
diff --git a/Lib/fnmatch.py b/Lib/fnmatch.py
index c40f50035d..182a9ef923 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 + "$"