1 # copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
1 # copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
3 # |
3 # |
4 # This file is part of CubicWeb. |
4 # This file is part of CubicWeb. |
5 # |
5 # |
6 # CubicWeb is free software: you can redistribute it and/or modify it under the |
6 # CubicWeb is free software: you can redistribute it and/or modify it under the |
60 rqlhelper.annotate(rqlst) |
60 rqlhelper.annotate(rqlst) |
61 @staticmethod |
61 @staticmethod |
62 def simplify(mainrqlst, needcopy=False): |
62 def simplify(mainrqlst, needcopy=False): |
63 rqlhelper.simplify(rqlst, needcopy) |
63 rqlhelper.simplify(rqlst, needcopy) |
64 rewriter = RQLRewriter(mock_object(vreg=FakeVReg, user=(mock_object(eid=1)))) |
64 rewriter = RQLRewriter(mock_object(vreg=FakeVReg, user=(mock_object(eid=1)))) |
65 for v, snippets in snippets_map.items(): |
65 snippets = [] |
66 snippets_map[v] = [isinstance(snippet, basestring) |
66 for v, exprs in snippets_map.items(): |
67 and mock_object(snippet_rqlst=parse('Any X WHERE '+snippet).children[0], |
67 rqlexprs = [isinstance(snippet, basestring) |
68 expression='Any X WHERE '+snippet) |
68 and mock_object(snippet_rqlst=parse('Any X WHERE '+snippet).children[0], |
69 or snippet |
69 expression='Any X WHERE '+snippet) |
70 for snippet in snippets] |
70 or snippet |
|
71 for snippet in exprs] |
|
72 snippets.append((dict([v]), rqlexprs)) |
71 rqlhelper.compute_solutions(rqlst.children[0], {'eid': eid_func_map}, kwargs=kwargs) |
73 rqlhelper.compute_solutions(rqlst.children[0], {'eid': eid_func_map}, kwargs=kwargs) |
72 solutions = rqlst.children[0].solutions |
74 solutions = rqlst.children[0].solutions |
73 rewriter.rewrite(rqlst.children[0], snippets_map.items(), solutions, kwargs, |
75 rewriter.rewrite(rqlst.children[0], snippets, solutions, kwargs, |
74 existingvars) |
76 existingvars) |
75 test_vrefs(rqlst.children[0]) |
77 test_vrefs(rqlst.children[0]) |
76 return rewriter.rewritten |
78 return rewriter.rewritten |
77 |
79 |
78 def test_vrefs(node): |
80 def test_vrefs(node): |