def test_ordered_globs(self): """test that the first match in a list is the one found""" patterns = [ u'*.foo', u'bar.*'] globster = _OrderedGlobster(patterns) self.assertEqual(u'*.foo', globster.match('bar.foo')) self.assertEqual(None, globster.match('foo.bar')) globster = _OrderedGlobster(reversed(patterns)) self.assertEqual(u'bar.*', globster.match('bar.foo')) self.assertEqual(None, globster.match('foo.bar'))
def __init__(self, inifile): """Construct a _RulesSearcher based on an ini file. The content will be decoded as utf-8. :param inifile: the name of the file or a sequence of lines. """ self._cfg = configobj.ConfigObj(inifile, encoding='utf-8') sections = self._cfg.keys() patterns = [] self.pattern_to_section = {} for s in sections: if s.startswith(FILE_PREFS_PREFIX): file_patterns = cmdline.split(s[FILE_PREFS_PREFIX_LEN:]) patterns.extend(file_patterns) for fp in file_patterns: self.pattern_to_section[fp] = s if len(patterns) < len(sections): unknowns = [s for s in sections if not s.startswith(FILE_PREFS_PREFIX)] raise errors.UnknownRules(unknowns) elif patterns: self._globster = globbing._OrderedGlobster(patterns) else: self._globster = None
def __init__(self, inifile): """Construct a _RulesSearcher based on an ini file. The content will be decoded as utf-8. :param inifile: the name of the file or a sequence of lines. """ self._cfg = configobj.ConfigObj(inifile, encoding='utf-8') sections = self._cfg.keys() patterns = [] self.pattern_to_section = {} for s in sections: if s.startswith(FILE_PREFS_PREFIX): file_patterns = cmdline.split(s[FILE_PREFS_PREFIX_LEN:]) patterns.extend(file_patterns) for fp in file_patterns: self.pattern_to_section[fp] = s if len(patterns) < len(sections): unknowns = [ s for s in sections if not s.startswith(FILE_PREFS_PREFIX) ] raise errors.UnknownRules(unknowns) elif patterns: self._globster = globbing._OrderedGlobster(patterns) else: self._globster = None
def __init__(self, inifile): """Construct a _RulesSearcher based on an ini file. The content will be decoded as utf-8. :param inifile: the name of the file or a sequence of lines. """ options = {'encoding': 'utf-8'} self._cfg = configobj.ConfigObj(inifile, options=options) sections = self._cfg.keys() patterns = [s[FILE_PREFS_PREFIX_LEN:] for s in sections if s.startswith(FILE_PREFS_PREFIX)] if len(patterns) < len(sections): unknowns = [s for s in sections if not s.startswith(FILE_PREFS_PREFIX)] raise errors.UnknownRules(unknowns) elif patterns: self._globster = globbing._OrderedGlobster(patterns) else: self._globster = None
def __init__(self, inifile): """Construct a _RulesSearcher based on an ini file. The content will be decoded as utf-8. :param inifile: the name of the file or a sequence of lines. """ options = {'encoding': 'utf-8'} self._cfg = configobj.ConfigObj(inifile, options=options) sections = self._cfg.keys() patterns = [ s[FILE_PREFS_PREFIX_LEN:] for s in sections if s.startswith(FILE_PREFS_PREFIX) ] if len(patterns) < len(sections): unknowns = [ s for s in sections if not s.startswith(FILE_PREFS_PREFIX) ] raise errors.UnknownRules(unknowns) elif patterns: self._globster = globbing._OrderedGlobster(patterns) else: self._globster = None