16 # You should have received a copy of the GNU Lesser General Public License along |
16 # You should have received a copy of the GNU Lesser General Public License along |
17 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
17 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
18 """Helper classes to execute RQL queries on a set of sources, performing |
18 """Helper classes to execute RQL queries on a set of sources, performing |
19 security checking and data aggregation. |
19 security checking and data aggregation. |
20 """ |
20 """ |
21 from __future__ import print_function |
|
22 |
|
23 from itertools import repeat |
21 from itertools import repeat |
24 |
|
25 from six import text_type, string_types, integer_types |
|
26 from six.moves import range, zip |
|
27 |
22 |
28 from rql import RQLSyntaxError, CoercionError |
23 from rql import RQLSyntaxError, CoercionError |
29 from rql.stmts import Union |
24 from rql.stmts import Union |
30 from rql.nodes import ETYPE_PYOBJ_MAP, etype_from_pyobj, Relation, Exists, Not |
25 from rql.nodes import ETYPE_PYOBJ_MAP, etype_from_pyobj, Relation, Exists, Not |
31 from yams import BASE_TYPES |
26 from yams import BASE_TYPES |
440 repo = cnx.repo |
435 repo = cnx.repo |
441 edited_entities = {} |
436 edited_entities = {} |
442 relations = {} |
437 relations = {} |
443 for subj, rtype, obj in self.relation_defs(): |
438 for subj, rtype, obj in self.relation_defs(): |
444 # if a string is given into args instead of an int, we get it here |
439 # if a string is given into args instead of an int, we get it here |
445 if isinstance(subj, string_types): |
440 if isinstance(subj, str): |
446 subj = int(subj) |
441 subj = int(subj) |
447 elif not isinstance(subj, integer_types): |
442 elif not isinstance(subj, int): |
448 subj = subj.entity.eid |
443 subj = subj.entity.eid |
449 if isinstance(obj, string_types): |
444 if isinstance(obj, str): |
450 obj = int(obj) |
445 obj = int(obj) |
451 elif not isinstance(obj, integer_types): |
446 elif not isinstance(obj, int): |
452 obj = obj.entity.eid |
447 obj = obj.entity.eid |
453 if repo.schema.rschema(rtype).inlined: |
448 if repo.schema.rschema(rtype).inlined: |
454 if subj not in edited_entities: |
449 if subj not in edited_entities: |
455 entity = cnx.entity_from_eid(subj) |
450 entity = cnx.entity_from_eid(subj) |
456 edited = EditedEntity(entity) |
451 edited = EditedEntity(entity) |
621 rqlhelper.backend = repo.config.system_source_config['db-driver'] |
616 rqlhelper.backend = repo.config.system_source_config['db-driver'] |
622 |
617 |
623 def parse(rql, annotate=False, parse=rqlhelper.parse): |
618 def parse(rql, annotate=False, parse=rqlhelper.parse): |
624 """Return a freshly parsed syntax tree for the given RQL.""" |
619 """Return a freshly parsed syntax tree for the given RQL.""" |
625 try: |
620 try: |
626 return parse(text_type(rql), annotate=annotate) |
621 return parse(rql, annotate=annotate) |
627 except UnicodeError: |
622 except UnicodeError: |
628 raise RQLSyntaxError(rql) |
623 raise RQLSyntaxError(rql) |
629 self._parse = parse |
624 self._parse = parse |
630 |
625 |
631 def __len__(self): |
626 def __len__(self): |