Esempio n. 1
0
 def filter(self):
     try:
         return es_regex_filter(
             self._parsed_regex,
             'content',
             is_case_sensitive=self._term['case_sensitive'])
     except NoTrigrams:
         raise BadTerm('Regexes need at least 3 literal characters in a  '
                       'row for speed.')
Esempio n. 2
0
 def filter(self):
     glob = self._term['arg']
     try:
         return es_regex_filter(
             regex_grammar.parse(glob_to_regex(glob)),
             'path',
             is_case_sensitive=self._term['case_sensitive'])
     except NoTrigrams:
         raise BadTerm('Path globs need at least 3 literal characters in a row '
                       'for speed.')
Esempio n. 3
0
File: core.py Progetto: na-g/dxr
    def _regex_filter(self, path_seg_property_name, no_trigrams_error_text):
        """Return an ES regex filter that matches this filter's glob against the
        path segment at path_seg_property_name.

        """
        glob = self._term['arg']
        try:
            return es_regex_filter(
                regex_grammar.parse(glob_to_regex(glob)),
                path_seg_property_name,
                is_case_sensitive=self._term['case_sensitive'])
        except NoTrigrams:
            raise BadTerm(no_trigrams_error_text)
Esempio n. 4
0
    def __init__(self, term, enabled_plugins):
        """Compile the Python equivalent of the regex so we don't have to lean
        on the regex cache during highlighting.

        Python's regex cache is naive: after it hits 100, it just clears: no
        LRU.

        """
        super(RegexpFilter, self).__init__(term, enabled_plugins)
        try:
            self._parsed_regex = regex_grammar.parse(term['arg'])
        except ParseError:
            raise BadTerm('Invalid regex.')
        self._compiled_regex = (
                re.compile(PythonRegexVisitor().visit(self._parsed_regex),
                           flags=0 if self._term['case_sensitive'] else re.I))