~cypressyew/checkbox/fix-grep-typo

« back to all changes in this revision

Viewing changes to plainbox/plainbox/impl/secure/qualifiers.py

  • Committer: Daniel Manrique
  • Author(s): Zygmunt Krynicki
  • Date: 2015-01-29 17:37:51 UTC
  • mfrom: (3543.4.12 launchpad/xparsers)
  • Revision ID: daniel_manrique-20150129173751-esxhgg4anm50r9an
"automatic merge of lp:~zkrynicki/checkbox/xparsers/ by tarmac [r=sylvain-pineau][bug=][author=zkrynicki]"

Show diffs side-by-side

added added

removed removed

Lines of Context:
583
583
            (1-based) and pattern_list is a list of regular expression strings
584
584
            parsed from the whitelist.
585
585
        """
586
 
        pattern_list = []
587
 
        lineno = 0
588
 
        # Load the file
589
 
        for lineno, line in enumerate(text.splitlines(), 1):
590
 
            # Strip shell-style comments if there are any
591
 
            try:
592
 
                index = line.index("#")
593
 
            except ValueError:
594
 
                pass
595
 
            else:
596
 
                line = line[:index]
597
 
            # Strip whitespace
598
 
            line = line.strip()
599
 
            # Skip empty lines (especially after stripping comments)
600
 
            if line == "":
601
 
                continue
602
 
            # Surround the pattern with ^ and $
603
 
            # so that it wont just match a part of the job name.
604
 
            regexp_pattern = r"^{pattern}$".format(pattern=line)
605
 
            # Accumulate patterns into the list
606
 
            pattern_list.append(regexp_pattern)
607
 
        return pattern_list, lineno
 
586
        from plainbox.impl.xparsers import Re
 
587
        from plainbox.impl.xparsers import Visitor
 
588
        from plainbox.impl.xparsers import WhiteList
 
589
 
 
590
        class WhiteListVisitor(Visitor):
 
591
 
 
592
            def __init__(self):
 
593
                self.pattern_list = []
 
594
                self.lineno = 0
 
595
 
 
596
            def visit_Re_node(self, node: Re):
 
597
                self.pattern_list.append(r"^{}$".format(node.text.strip()))
 
598
                self.lineno = max(node.lineno, self.lineno)
 
599
                return super().generic_visit(node)
 
600
 
 
601
            visit_ReFixed_node = visit_Re_node
 
602
            visit_RePattern_node = visit_Re_node
 
603
            visit_ReErr_node = visit_Re_node
 
604
 
 
605
        visitor = WhiteListVisitor()
 
606
        visitor.visit(WhiteList.parse(text))
 
607
        return visitor.pattern_list, visitor.lineno
608
608
 
609
609
    @classmethod
610
610
    def _load_patterns(cls, pathname):