schema.py
changeset 9250 0dcc68dd8458
parent 9205 ea32e964fbf8
parent 9227 762a331db741
child 9253 77e31ede9b04
equal deleted inserted replaced
9218:c027ed79f1ce 9250:0dcc68dd8458
   695     # these are overridden by set_log_methods below
   695     # these are overridden by set_log_methods below
   696     # only defining here to prevent pylint from complaining
   696     # only defining here to prevent pylint from complaining
   697     info = warning = error = critical = exception = debug = lambda msg,*a,**kw: None
   697     info = warning = error = critical = exception = debug = lambda msg,*a,**kw: None
   698     # to be defined in concrete classes
   698     # to be defined in concrete classes
   699     full_rql = None
   699     full_rql = None
       
   700     predefined_variables = None
   700 
   701 
   701     def __init__(self, expression, mainvars, eid):
   702     def __init__(self, expression, mainvars, eid):
   702         """
   703         """
   703         :type mainvars: sequence of RQL variables' names. Can be provided as a 
   704         :type mainvars: sequence of RQL variables' names. Can be provided as a
   704                         comma separated string.
   705                         comma separated string.
   705         :param mainvars: names of the variables being selected.
   706         :param mainvars: names of the variables being selected.
   706 
   707 
   707         """
   708         """
   708         self.eid = eid # eid of the entity representing this rql expression
   709         self.eid = eid # eid of the entity representing this rql expression
   716         try:
   717         try:
   717             self.rqlst = parse(self.full_rql, print_errors=False).children[0]
   718             self.rqlst = parse(self.full_rql, print_errors=False).children[0]
   718         except RQLSyntaxError:
   719         except RQLSyntaxError:
   719             raise RQLSyntaxError(expression)
   720             raise RQLSyntaxError(expression)
   720         for mainvar in mainvars:
   721         for mainvar in mainvars:
   721             if len(self.rqlst.defined_vars[mainvar].references()) <= 2:
   722             # if variable is predefined, an extra reference is inserted
       
   723             # automatically (`VAR eid %(v)s`)
       
   724             if mainvar in self.predefined_variables:
       
   725                 min_refs = 3
       
   726             else:
       
   727                 min_refs = 2
       
   728             if len(self.rqlst.defined_vars[mainvar].references()) < min_refs:
   722                 _LOGGER.warn('You did not use the %s variable in your RQL '
   729                 _LOGGER.warn('You did not use the %s variable in your RQL '
   723                              'expression %s', mainvar, self)
   730                              'expression %s', mainvar, self)
   724         # syntax tree used by read security (inserted in queries when necessary)
   731         # syntax tree used by read security (inserted in queries when necessary)
   725         self.snippet_rqlst = parse(self.minimal_rql, print_errors=False).children[0]
   732         self.snippet_rqlst = parse(self.minimal_rql, print_errors=False).children[0]
   726 
   733 
   865                                     self.expression)
   872                                     self.expression)
   866 
   873 
   867 # rql expressions for use in permission definition #############################
   874 # rql expressions for use in permission definition #############################
   868 
   875 
   869 class ERQLExpression(RQLExpression):
   876 class ERQLExpression(RQLExpression):
       
   877     predefined_variables = 'UX'
       
   878 
   870     def __init__(self, expression, mainvars=None, eid=None):
   879     def __init__(self, expression, mainvars=None, eid=None):
   871         RQLExpression.__init__(self, expression, mainvars or 'X', eid)
   880         RQLExpression.__init__(self, expression, mainvars or 'X', eid)
   872 
   881 
   873     @property
   882     @property
   874     def full_rql(self):
   883     def full_rql(self):
   920         self.mainvars = mainvars
   929         self.mainvars = mainvars
   921         self.vargraph = vargraph(rqlst)
   930         self.vargraph = vargraph(rqlst)
   922 
   931 
   923 
   932 
   924 class RRQLExpression(RQLExpression):
   933 class RRQLExpression(RQLExpression):
       
   934     predefined_variables = 'USO'
       
   935 
   925     def __init__(self, expression, mainvars=None, eid=None):
   936     def __init__(self, expression, mainvars=None, eid=None):
   926         if mainvars is None:
   937         if mainvars is None:
   927             mainvars = guess_rrqlexpr_mainvars(expression)
   938             mainvars = guess_rrqlexpr_mainvars(expression)
   928         RQLExpression.__init__(self, expression, mainvars, eid)
   939         RQLExpression.__init__(self, expression, mainvars, eid)
   929         # graph of links between variable, used by rql rewriter
   940         # graph of links between variable, used by rql rewriter
  1100     is no way to guess it correctly (e.g. if using S,O or U the constraint will
  1111     is no way to guess it correctly (e.g. if using S,O or U the constraint will
  1101     always be satisfied because we've to use a DISTINCT query).
  1112     always be satisfied because we've to use a DISTINCT query).
  1102     """
  1113     """
  1103     # XXX turns mainvars into a required argument in __init__
  1114     # XXX turns mainvars into a required argument in __init__
  1104     distinct_query = True
  1115     distinct_query = True
  1105  
  1116 
  1106     def match_condition(self, session, eidfrom, eidto):
  1117     def match_condition(self, session, eidfrom, eidto):
  1107         return len(self.exec_query(session, eidfrom, eidto)) <= 1
  1118         return len(self.exec_query(session, eidfrom, eidto)) <= 1
  1108 
  1119 
  1109 
  1120 
  1110 # workflow extensions #########################################################
  1121 # workflow extensions #########################################################