1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
from fnmatch import fnmatch
class GlobbingFilter(object):
"""Filter module names using a set of globs.
Objects are matched against the exclude list first, then the include list.
Anything that passes through without matching either, is excluded.
"""
def __init__(self, include=None, exclude=None):
if include is None and exclude is None:
include = ['*']
exclude = []
elif include is None:
include = ['*']
elif exclude is None:
exclude = []
self.include = include
self.exclude = exclude
def __call__(self, full_name=None):
for pattern in self.exclude:
if fnmatch(full_name, pattern):
return False
for pattern in self.include:
if fnmatch(full_name, pattern):
return True
return False
|