From 46d9fda0080bb818a37e63e1156949a11f8f80e8 Mon Sep 17 00:00:00 2001 From: Fred Drake Date: Wed, 21 Mar 2001 18:05:48 +0000 Subject: Donovan Baarda : Patch to make "\" in a character group work properly. This closes SF bug #409651. --- Lib/fnmatch.py | 14 +++++--------- 1 file 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 + "$" -- cgit v0.12