Пример #1
0
    def _compile(self):
        errMsg = "Error: RegexTopMatcher.Compile(): "

        expr = self._expr

        if '$' != expr[-1]:
            expr = expr + "<.*>*"
        else:
            expr = expr[0:-1]

        if '^' != expr[0]:
            self._secondaryMatcher = NdnRegexPatternListMatcher(
                "<.*>*" + expr, self._secondaryBackrefManager)
        else:
            expr = expr[1:]

        self._primaryMatcher = NdnRegexPatternListMatcher(
            expr, self._primaryBackrefManager)
    def _compile(self):
        if len(self._expr) < 2:
            raise NdnRegexMatcherBase.Error("Unrecognized format: " + self._expr)

        lastIndex = len(self._expr) - 1
        if '(' == self._expr[0] and ')' == self._expr[lastIndex]:
            matcher = NdnRegexPatternListMatcher(
              self._expr[1:lastIndex], self._backrefManager)
            self._matchers.append(matcher)
        else:
            raise NdnRegexMatcherBase.Error("Unrecognized format: " + self._expr)
Пример #3
0
 def test_backref_matcher_advanced2(self):
     backRef = NdnRegexBackrefManager()
     cm = NdnRegexPatternListMatcher("(<a>(<b>))<c>", backRef)
     res = cm.match(Name("/a/b/c"), 0, 3)
     self.assertEqual(True, res)
     self.assertEqual(3, len(cm.getMatchResult()))
     self.assertEqual("a", cm.getMatchResult()[0].toEscapedString())
     self.assertEqual("b", cm.getMatchResult()[1].toEscapedString())
     self.assertEqual("c", cm.getMatchResult()[2].toEscapedString())
     self.assertEqual(2, backRef.size())
     self.assertEqual("a",
       backRef.getBackref(0).getMatchResult()[0].toEscapedString())
     self.assertEqual("b",
       backRef.getBackref(0).getMatchResult()[1].toEscapedString())
     self.assertEqual("b",
       backRef.getBackref(1).getMatchResult()[0].toEscapedString())
Пример #4
0
    def test_pattern_list_matcher(self):
        backRef = NdnRegexBackrefManager()
        cm = NdnRegexPatternListMatcher("<a>[<a><b>]", backRef)
        res = cm.match(Name("/a/b/c"), 0, 2)
        self.assertEqual(True, res)
        self.assertEqual(2, len(cm.getMatchResult()))
        self.assertEqual("a", cm.getMatchResult()[0].toEscapedString())
        self.assertEqual("b", cm.getMatchResult()[1].toEscapedString())

        backRef = NdnRegexBackrefManager()
        cm = NdnRegexPatternListMatcher("<>*<a>", backRef)
        res = cm.match(Name("/a/b/c"), 0, 1)
        self.assertEqual(True, res)
        self.assertEqual(1, len(cm.getMatchResult()))
        self.assertEqual("a", cm.getMatchResult()[0].toEscapedString())

        backRef = NdnRegexBackrefManager()
        cm = NdnRegexPatternListMatcher("<>*<a>", backRef)
        res = cm.match(Name("/a/b/c"), 0, 2)
        self.assertEqual(False, res)
        self.assertEqual(0, len(cm.getMatchResult()))

        backRef = NdnRegexBackrefManager()
        cm = NdnRegexPatternListMatcher("<>*<a><>*", backRef)
        res = cm.match(Name("/a/b/c"), 0, 3)
        self.assertEqual(True, res)
        self.assertEqual(3, len(cm.getMatchResult()))
        self.assertEqual("a", cm.getMatchResult()[0].toEscapedString())
        self.assertEqual("b", cm.getMatchResult()[1].toEscapedString())
        self.assertEqual("c", cm.getMatchResult()[2].toEscapedString())