(pattern, anchor=1, prefix=None, is_regex=0)
return re.compile(pattern_re)
Translate a shell-like wildcard pattern to a compiled regular
    expression.  Return the compiled regex.  If 'is_regex' true,
    then 'pattern' is directly compiled to a regex (if it's a string)
    or just returned as-is (assumes it's a regex object).
Translate a shell-like wildcard pattern to a compiled regular
    expression.  Return the compiled regex.  If 'is_regex' true,
    then 'pattern' is directly compiled to a regex (if it's a string)
    or just returned as-is (assumes it's a regex object).
Translate a shell - like wildcard pattern to a compiled regular expression . Return the compiled regex . If is_regex true then pattern is directly compiled to a regex ( if it s a string ) or just returned as - is ( assumes it s a regex object ) .
def translate_pattern(pattern, anchor=1, prefix=None, is_regex=0):
    """Translate a shell-like wildcard pattern to a compiled regular
    expression.  Return the compiled regex.  If 'is_regex' true,
    then 'pattern' is directly compiled to a regex (if it's a string)
    or just returned as-is (assumes it's a regex object).
    """
    if is_regex:
        if isinstance(pattern, str):
            return re.compile(pattern)
        else:
            return pattern

    # ditch start and end characters
    start, _, end = glob_to_re('_').partition('_')

    if pattern:
        pattern_re = glob_to_re(pattern)
        assert pattern_re.startswith(start) and pattern_re.endswith(end)
    else:
        pattern_re = ''

    if prefix is not None:
        prefix_re = glob_to_re(prefix)
        assert prefix_re.startswith(start) and prefix_re.endswith(end)
        prefix_re = prefix_re[len(start): len(prefix_re) - len(end)]
        sep = os.sep
        if os.sep == '\\':
            sep = r'\\'
        pattern_re = pattern_re[len(start): len(pattern_re) - len(end)]
        pattern_re = r'%s\A%s%s.*%s%s' % (start, prefix_re, sep, pattern_re, end)
    else:                               # no prefix -- respect anchor flag
        if anchor:
            pattern_re = r'%s\A%s' % (start, pattern_re[len(start):])

    return re.compile(pattern_re)
def translate_pattern ( pattern , anchor = 1 , prefix = None , is_regex = 0 ) : if is_regex : if isinstance ( pattern , str ) : return re . compile ( pattern ) else : return pattern # ditch start and end characters start , _ , end = glob_to_re ( '_' ) . partition ( '_' ) if pattern : pattern_re = glob_to_re ( pattern ) assert pattern_re . startswith ( start ) and pattern_re . endswith ( end ) else : pattern_re = '' if prefix is not None : prefix_re = glob_to_re ( prefix ) assert prefix_re . startswith ( start ) and prefix_re . endswith ( end ) prefix_re = prefix_re [ len ( start ) : len ( prefix_re ) - len ( end ) ] sep = os . sep if os . sep == '\\' : sep = r'\\' pattern_re = pattern_re [ len ( start ) : len ( pattern_re ) - len ( end ) ] pattern_re = r'%s\A%s%s.*%s%s' % ( start , prefix_re , sep , pattern_re , end ) else : # no prefix -- respect anchor flag if anchor : pattern_re = r'%s\A%s' % ( start , pattern_re [ len ( start ) : ] ) return re . compile ( pattern_re )