equal
deleted
inserted
replaced
123 def _globre(pat): |
123 def _globre(pat): |
124 "convert a glob pattern into a regexp" |
124 "convert a glob pattern into a regexp" |
125 i, n = 0, len(pat) |
125 i, n = 0, len(pat) |
126 res = '' |
126 res = '' |
127 group = 0 |
127 group = 0 |
|
128 escape = re.escape |
128 def peek(): return i < n and pat[i] |
129 def peek(): return i < n and pat[i] |
129 while i < n: |
130 while i < n: |
130 c = pat[i] |
131 c = pat[i] |
131 i = i+1 |
132 i = i+1 |
132 if c == '*': |
133 if c not in '*?[{},\\': |
|
134 res += escape(c) |
|
135 elif c == '*': |
133 if peek() == '*': |
136 if peek() == '*': |
134 i += 1 |
137 i += 1 |
135 res += '.*' |
138 res += '.*' |
136 else: |
139 else: |
137 res += '[^/]*' |
140 res += '[^/]*' |
163 res += '|' |
166 res += '|' |
164 elif c == '\\': |
167 elif c == '\\': |
165 p = peek() |
168 p = peek() |
166 if p: |
169 if p: |
167 i += 1 |
170 i += 1 |
168 res += re.escape(p) |
171 res += escape(p) |
169 else: |
172 else: |
170 res += re.escape(c) |
173 res += escape(c) |
171 else: |
174 else: |
172 res += re.escape(c) |
175 res += escape(c) |
173 return res |
176 return res |
174 |
177 |
175 def _regex(kind, name, tail): |
178 def _regex(kind, name, tail): |
176 '''convert a pattern into a regular expression''' |
179 '''convert a pattern into a regular expression''' |
177 if not name: |
180 if not name: |