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
 if pattern:
  pattern_re = glob_to_re(pattern)
 else:
  pattern_re = ''
 if (prefix is not None):
  empty_pattern = glob_to_re('')
  prefix_re = glob_to_re(prefix)[:(- len(empty_pattern))]
  sep = os.sep
  if (os.sep == '\\'):
   sep = '\\\\'
  pattern_re = ('^' + sep.join((prefix_re, ('.*' + pattern_re))))
 elif anchor:
  pattern_re = ('^' + pattern_re)
 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 if pattern : pattern_re = glob_to_re ( pattern ) else : pattern_re = '' if ( prefix is not None ) : empty_pattern = glob_to_re ( '' ) prefix_re = glob_to_re ( prefix ) [ : ( - len ( empty_pattern ) ) ] sep = os . sep if ( os . sep == '\\' ) : sep = '\\\\' pattern_re = ( '^' + sep . join ( ( prefix_re , ( '.*' + pattern_re ) ) ) ) elif anchor : pattern_re = ( '^' + pattern_re ) return re . compile ( pattern_re )
translate a shell-like wildcard pattern to a compiled regular expression .