示例#1
0
文件: search.py 项目: conan-io/conan
def filter_packages(query, package_infos):
    if query is None:
        return package_infos
    try:
        if "!" in query:
            raise ConanException("'!' character is not allowed")
        if " not " in query or query.startswith("not "):
            raise ConanException("'not' operator is not allowed")
        result = {}
        postfix = infix_to_postfix(query) if query else []
        for package_id, info in package_infos.items():
            if evaluate_postfix_with_info(postfix, info):
                result[package_id] = info
        return result
    except Exception as exc:
        raise ConanException("Invalid package query: %s. %s" % (query, exc))
示例#2
0
    def test_get_postfix(self):
        r = infix_to_postfix("")
        self.assertEquals(r, [])

        r = infix_to_postfix("a=2")
        self.assertEquals(r, ["a=2"])

        r = infix_to_postfix("a=2 OR b=3")
        self.assertEquals(r, ["a=2", "b=3", "|"])

        r = infix_to_postfix("a= OR b=")
        self.assertEquals(r, ["a=", "b=", "|"])  # Equivalent to ""

        r = infix_to_postfix("(a=2 OR b=3) AND (j=34 AND j=45) OR (a=1)")
        self.assertEquals(r, ["a=2", "b=3", "|", "j=34", "j=45", "&", "a=1", "&", "|"])

        with self.assertRaisesRegexp(Exception, "Invalid expression: 2"):
            r = infix_to_postfix("a= 2 OR b=3")
示例#3
0
 def evaluate(q):
     r = infix_to_postfix(q)
     return evaluate_postfix(r, evaluator)