Like #os.walk(), but filters the files and directories that are excluded by
  the specified *patterns*.

  # Arguments
  patterns (IgnoreList, IgnoreListCollection): Can also be any object that
    implements the #IgnoreList.match() interface.
  dirname (str): The directory to walk.

def walk(patterns, dirname):
  """
  Like #os.walk(), but filters the files and directories that are excluded by
  the specified *patterns*.

  # Arguments
  patterns (IgnoreList, IgnoreListCollection): Can also be any object that
    implements the #IgnoreList.match() interface.
  dirname (str): The directory to walk.
  """

  join = os.path.join
  for root, dirs, files in os.walk(dirname, topdown=True):
    dirs[:] = [d for d in dirs if patterns.match(join(root, d), True) != MATCH_IGNORE]
    files[:] = [f for f in files if patterns.match(join(root, f), False) != MATCH_IGNORE]
    yield root, dirs, files