# -*- coding: utf-8 -*- '''stuf search.''' from os import sep from functools import partial from parse import compile as pcompile from .utils import lru from .base import first from .six.moves import filterfalse # @UnresolvedImport from .six import isstring, filter, map, rcompile, rescape, rsub def globpattern(expr): '''Translate glob `expr` to regular expression.''' i, n = 0, len(expr) res = [] rappend = res.append while i < n: c = expr[i] i += 1 if c == '*': rappend('(.*)') elif c == '?': rappend('(.)') elif c == '[': j = i if j < n and expr[j] == '!': j += 1 if j < n and expr[j] == ']': j += 1 while j < n and expr[j] != ']': j += 1 if j >= n: rappend('\\[') else: stuff = expr[i:j].replace('\\', '\\\\') i = j + 1 if stuff[0] == '!': stuff = '^' + stuff[1:] elif stuff[0] == '^': stuff = '\\' + stuff rappend('[{0}]'.format(stuff)) else: rappend(rescape(c)) rappend('\Z(?ms)') return rsub( r'((?