import re

INCLUDE = 1
EXCLUDE = 2

def parse_pattern_file(f):
    res = []
    regex = re.compile('^([+-])\W+(.*)$')
    for line in f:
        line = line.rstrip()
        if f.startswith('#'):
            continue
        else
            r = regex.match(line.rstrip())
            if not r:
                raise ValueError('Line "{}" is not a valid pattern.'.format(
                        line))
            if r.groups[0] == '+':
                res.append((INCLUDE, r.groups[1]))
            elif r.groups[0] == '-':
                res.append((EXCLUDE, r.groups[1]))
            else:
                raise ValueError('Unknown pattern modifier "{}".'.format(
                        r.groups[0]))
    return res

def filename_matches_pattern(filename, pattern):


def filename_matches_patterns(filename, patterns):
    for p in patterns:
        

@@ -775,83 +775,933 @@
 def 
-filename_matches_patterns(filename, patterns):%0A    for p in patterns:%0A        
+pattern_decision(filename, patterns, default_decision=INCLUDE):%0A    res = default_decision%0A    for p in patterns:%0A        if filename_matches_single_pattern(filename, p%5B1%5D):%0A            res = p%5B0%5D%0A    return res%0A%0Adef listdir_onerror(error):%0A    raise error%0A%0Adef assemble_filenames(rootdir, patterns):%0A    res = %5B%5D%0A    for root, dirs, files in os.walk(rootdir, topdown=True,%0A            onerror=listdir_onerror, followlinks=False)%0A        for f in files:%0A            filename = os.path.join(root, f)%0A            # The %22root%22 returned by os.walk includes rootdir. We strip out this%0A            # part so that the filename starts with os.sep.%0A            filename = %0A            decision = pattern_decision(filename, patterns)%0A            if decision == INCLUDE:%0A                res.append(filename)%0A            elif decision != EXCLUDE:%0A                raise ValueError('Unknown file decision %7B%7D.'.format(decision))%0A    return res
 %0A

work on pattern matching: assemble_filenames