Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
class RelativeFilter(Filter):
def __init__(self, root, pattern):
super(RelativeFilter, self).__init__(pattern)
self.root = root
def match(self, path):
abspath = os.path.realpath(path)
relpath = os.path.relpath(abspath, self.root)
return super(RelativeFilter, self).match(relpath)
def __str__(self):
return "RelativeFilter({} root={})".format(
self.pattern.pattern, self.root)
class AlwaysMatchFilter(Filter):
def __init__(self):
super(AlwaysMatchFilter, self).__init__("")
def match(self, path):
return True
class DirectoryPrefixFilter(Filter):
def __init__(self, directory):
abspath = os.path.realpath(directory)
os_independent_dir = abspath.replace(os.path.sep, '/')
pattern = re.escape(os_independent_dir + '/')
super(DirectoryPrefixFilter, self).__init__(pattern)
def match(self, path):
normpath = os.path.normpath(path)
class Filter(object):
def __init__(self, pattern):
self.pattern = re.compile(pattern)
def match(self, path):
os_independent_path = path.replace(os.path.sep, '/')
return self.pattern.match(os_independent_path)
def __str__(self):
return "{name}({pattern})".format(
name=type(self).__name__, pattern=self.pattern.pattern)
class AbsoluteFilter(Filter):
def match(self, path):
abspath = os.path.realpath(path)
return super(AbsoluteFilter, self).match(abspath)
class RelativeFilter(Filter):
def __init__(self, root, pattern):
super(RelativeFilter, self).__init__(pattern)
self.root = root
def match(self, path):
abspath = os.path.realpath(path)
relpath = os.path.relpath(abspath, self.root)
return super(RelativeFilter, self).match(relpath)
def __str__(self):
return super(RelativeFilter, self).match(relpath)
def __str__(self):
return "RelativeFilter({} root={})".format(
self.pattern.pattern, self.root)
class AlwaysMatchFilter(Filter):
def __init__(self):
super(AlwaysMatchFilter, self).__init__("")
def match(self, path):
return True
class DirectoryPrefixFilter(Filter):
def __init__(self, directory):
abspath = os.path.realpath(directory)
os_independent_dir = abspath.replace(os.path.sep, '/')
pattern = re.escape(os_independent_dir + '/')
super(DirectoryPrefixFilter, self).__init__(pattern)
def match(self, path):
normpath = os.path.normpath(path)
return super(DirectoryPrefixFilter, self).match(normpath)
class Logger(object):
def __init__(self, verbose=False):
self.verbose = verbose
def warn(self, pattern, *args, **kwargs):
def match(self, path):
os_independent_path = path.replace(os.path.sep, '/')
return self.pattern.match(os_independent_path)
def __str__(self):
return "{name}({pattern})".format(
name=type(self).__name__, pattern=self.pattern.pattern)
class AbsoluteFilter(Filter):
def match(self, path):
abspath = os.path.realpath(path)
return super(AbsoluteFilter, self).match(abspath)
class RelativeFilter(Filter):
def __init__(self, root, pattern):
super(RelativeFilter, self).__init__(pattern)
self.root = root
def match(self, path):
abspath = os.path.realpath(path)
relpath = os.path.relpath(abspath, self.root)
return super(RelativeFilter, self).match(relpath)
def __str__(self):
return "RelativeFilter({} root={})".format(
self.pattern.pattern, self.root)
class AlwaysMatchFilter(Filter):
def __init__(self):