def pfilter(f, patterns=None, use_regex=False):
 if (patterns is None):
  return True
 if use_regex:
  for p in patterns:
   r = re.compile(p)
   if r.match(f):
    return True
 else:
  for p in patterns:
   if fnmatch.fnmatch(f, p):
    return True
 return False

def pfilter ( f , patterns = None , use_regex = False ) : if ( patterns is None ) : return True if use_regex : for p in patterns : r = re . compile ( p ) if r . match ( f ) : return True else : for p in patterns : if fnmatch . fnmatch ( f , p ) : return True return False
filter using glob patterns .