Example #1
0
    def testGlob2Regex(self):
        """Tests the Glob2Regex function."""
        for glob_pattern in self._TEST_PATTERNS:
            regex = glob2regex.Glob2Regex(glob_pattern)
            expected_regex = self._Glob2Regex(glob_pattern)
            self.assertEqual(regex, expected_regex)

        with self.assertRaises(ValueError):
            glob2regex.Glob2Regex(None)
Example #2
0
    def _ConvertLocationGlob2Regex(self, location_glob):
        """Converts a location glob into a regular expression.

    Args:
      location_glob (str): location glob pattern.

    Returns:
      str: location regular expression pattern.
    """
        location_regex = glob2regex.Glob2Regex(location_glob)

        # The regular expression from glob2regex contains escaped forward
        # slashes "/", which needs to be undone.
        return location_regex.replace('\\/', '/')
 def _prepare_search_terms(terms, case_sensitive, regex):
     if case_sensitive:
         re_flags = 0
     else:
         re_flags = re.IGNORECASE
     plain_search = []
     regex_search = []
     for term in terms:
         if regex:
             regex_search.append(re.compile(term, re_flags))
         elif '*' in term or '?' in term:
             glob2reg = glob2regex.Glob2Regex(term)
             regex_search.append(re.compile(glob2reg, re_flags))
         else:
             if not case_sensitive:
                 plain_search.append(term.lower())
             else:
                 plain_search.append(term)
     return plain_search, regex_search