| 40 | |
| 41 | |
| 42 | def ant_matcher(s, ignorecase): |
| 43 | reflags = re.I if ignorecase else 0 |
| 44 | ret = [] |
| 45 | for x in Utils.to_list(s): |
| 46 | x = x.replace('\\', '/').replace('//', '/') |
| 47 | if x.endswith('/'): |
| 48 | x += '**' |
| 49 | accu = [] |
| 50 | for k in x.split('/'): |
| 51 | if k == '**': |
| 52 | accu.append(k) |
| 53 | else: |
| 54 | k = k.replace('.', '[.]').replace('*', '.*').replace('?', '.').replace('+', '\\+') |
| 55 | k = '^%s$' % k |
| 56 | try: |
| 57 | exp = re.compile(k, flags=reflags) |
| 58 | except Exception as e: |
| 59 | raise Errors.WafError('Invalid pattern: %s' % k, e) |
| 60 | else: |
| 61 | accu.append(exp) |
| 62 | ret.append(accu) |
| 63 | return ret |
| 64 | |
| 65 | |
| 66 | def ant_sub_filter(name, nn): |