diff --git a/__init__.py b/__init__.py index a08fe38dcb4c9afc5c4bf2fb5cf5e13880d0bec3_X19pbml0X18ucHk=..355006b88d3a28eb13cb5c8e8a8911126e8f1bfd_X19pbml0X18ucHk= 100644 --- a/__init__.py +++ b/__init__.py @@ -14,7 +14,7 @@ #REQUIRED_TYPES = ['String', 'Float', 'Int', 'Boolean', 'Date'] -class RQLHelper: +class RQLHelper(object): """Helper class for RQL handling give access to methods for : diff --git a/analyze.py b/analyze.py index a08fe38dcb4c9afc5c4bf2fb5cf5e13880d0bec3_YW5hbHl6ZS5weQ==..355006b88d3a28eb13cb5c8e8a8911126e8f1bfd_YW5hbHl6ZS5weQ== 100644 --- a/analyze.py +++ b/analyze.py @@ -15,7 +15,7 @@ from pprint import pprint -class ETypeResolver: +class ETypeResolver(object): """resolve variables types according to the schema CSP modelisation : @@ -340,6 +340,7 @@ raise UnifyError def deepcopy(s): + # XXX seen and memo do not appear to be useful r = {} memo = {} for k, v in s.items(): @@ -410,7 +411,7 @@ -class UnifyingETypeResolver: +class UnifyingETypeResolver(object): """resolve variables types according to the schema CSP modelisation : @@ -436,7 +437,7 @@ self._types = [eschema.type for eschema in self.schema.entities() if not eschema.is_final()] - def visit(self, node, uid_func_mapping=None, kwargs=None, debug=False): + def visit(self, node, uid_func_mapping=None, kwargs=None): # print "QUERY", node if uid_func_mapping: self.uid_func_mapping=uid_func_mapping @@ -494,7 +495,6 @@ def visit_relation(self, relation ): r_type = relation.r_type -# print "Relation", r_type lhs, rhs = relation.get_parts() expr_sols = rhs.accept(self) if r_type == 'is' and not isinstance(relation.parent, nodes.Not): @@ -514,6 +514,5 @@ r_schema = self.schema.relation_schema(r_type) -# print "Schema", r_schema l = [] typ = [None] @@ -518,7 +517,6 @@ l = [] typ = [None] - vlhs = [{'type' : typ, lhs.name : typ }] for from_type, to_types in r_schema.association_types(): for to_type in to_types: # a little base type pre-unification to_type = BASE_TYPES_MAP.get(to_type,to_type) @@ -521,11 +519,10 @@ for from_type, to_types in r_schema.association_types(): for to_type in to_types: # a little base type pre-unification to_type = BASE_TYPES_MAP.get(to_type,to_type) - s = { - 'type' : [to_type], - lhs.name : [from_type], - } + s = {'type' : [to_type], + lhs.name : [from_type], + } l.append(s) sols = unify_sols( l, expr_sols ) for s in sols: @@ -540,8 +537,8 @@ def visit_function(self, function): # XXX : todo function typing - return [{ 'type':[None]}] + return [{'type':[None]}] def visit_variableref(self, variableref): var = variableref.name typ = [None] @@ -544,8 +541,8 @@ def visit_variableref(self, variableref): var = variableref.name typ = [None] - sols = [{ 'type' : typ, var : typ }] + sols = [{'type': typ, var: typ}] return sols def visit_constant(self, constant): diff --git a/compare.py b/compare.py index a08fe38dcb4c9afc5c4bf2fb5cf5e13880d0bec3_Y29tcGFyZS5weQ==..355006b88d3a28eb13cb5c8e8a8911126e8f1bfd_Y29tcGFyZS5weQ== 100644 --- a/compare.py +++ b/compare.py @@ -46,7 +46,7 @@ class SkipChildren(Exception): """signal indicating to ignore the current child""" -class RQLCanonizer: +class RQLCanonizer(object): """build a dictionnary which represents a RQL syntax tree """ @@ -171,7 +171,9 @@ def visit_constant(self, constante, canon): """do nothing for this node type""" - - + + def visit_union(self, *args): + raise NotImplementedError('union comparison not implemented') + def make_lhs_reminder(lhs, canon): @@ -176,7 +178,7 @@ def make_lhs_reminder(lhs, canon): - """return a reminder for a relation's left hand side (i.e a VariableRef - object) + """return a reminder for a relation's left hand side + (i.e a VariableRef object) """ try: lhs = canon['all_variables'][lhs.variable][0] @@ -185,8 +187,8 @@ return ('=', lhs) def make_rhs_reminder(rhs, canon): - """return a reminder for a relation's right hand side (i.e a Comparison - object) + """return a reminder for a relation's right hand side + (i.e a Comparison object) """ child = rhs.children[0] try: diff --git a/fol.py b/fol.py index a08fe38dcb4c9afc5c4bf2fb5cf5e13880d0bec3_Zm9sLnB5..355006b88d3a28eb13cb5c8e8a8911126e8f1bfd_Zm9sLnB5 100644 --- a/fol.py +++ b/fol.py @@ -1,4 +1,5 @@ - +# -*- coding: utf-8 -*- +# Copyrigth 2000-2008 Logilab S.A. - Paris, France - http://www.logilab.fr <contact@logilab.fr> """ x in (A,B,C,D) @@ -20,7 +21,9 @@ """ -def intersect_sol( s1, s2 ): +import bisect + +def intersect_sol(s1, s2): sol = s1.copy() sol.update(s2) @@ -29,10 +32,10 @@ return {} return sol -def empty_sol( s ): +def empty_sol(s): for set in s.values(): if not set: return False class SolBase(object): @@ -33,10 +36,14 @@ for set in s.values(): if not set: return False class SolBase(object): - def and_sols(self, sols1, sols2 ): + + def __init__(self): + raise NotImplementedError('override in derived classes') + + def and_sols(self, sols1, sols2): sols = [] for s1 in sols1: for s2 in sols2: @@ -45,7 +52,7 @@ sols.append( s ) return sols - def or_sols(self, sols1, sols2 ): + def or_sols(self, sols1, sols2): sols = sols1[:] for s in sols2: if s not in sols: @@ -53,7 +60,7 @@ return sols - def __and__(self, x ): + def __and__(self, x): return SolAnd(self,x) def __or__(self, x): @@ -62,6 +69,6 @@ def __invert__(self): return SolNot(self) - def __call__(self,domains): + def __call__(self, domains): return self.sols(domains) @@ -66,6 +73,5 @@ return self.sols(domains) - def variables(self, upd=None): """Returns a dict whose keys are variables used by this formula. if upd is provided it is used @@ -74,6 +80,7 @@ raise NotImplementedError class SolNot(SolBase): - def __init__(self,s): + + def __init__(self, s): self.sol = s @@ -78,5 +85,5 @@ self.sol = s - def sols(self,domains): + def sols(self, domains): return self.sol.not_sols(domains) @@ -81,9 +88,8 @@ return self.sol.not_sols(domains) - def __str__(self): return "not ("+str(self.sol)+")" def variables(self, upd=None): return self.sol.variables(upd) @@ -84,9 +90,8 @@ def __str__(self): return "not ("+str(self.sol)+")" def variables(self, upd=None): return self.sol.variables(upd) -import bisect class SolAnd(SolBase): @@ -91,6 +96,7 @@ class SolAnd(SolBase): - def __init__(self, s1, s2 ): + + def __init__(self, s1, s2): self.sol = [] self.cost= [] # optimize (a and b) and c into and(a,b,c) @@ -106,9 +112,9 @@ else: self.insert(s2) - def insert(self,sol): + def insert(self, sol): N = len(sol.variables()) idx = bisect.bisect_left(self.cost,N) self.cost.insert(idx, N) self.sol.insert(idx, sol) @@ -110,8 +116,8 @@ N = len(sol.variables()) idx = bisect.bisect_left(self.cost,N) self.cost.insert(idx, N) self.sol.insert(idx, sol) - def sols(self,domains): + def sols(self, domains): sols = self.sol[0](domains) for s in self.sol[1:]: @@ -116,7 +122,7 @@ sols = self.sol[0](domains) for s in self.sol[1:]: -# domains = restrain(domains,sols) + # domains = restrain(domains,sols) S = s(domains) sols = self.and_sols( sols, S ) return sols @@ -119,8 +125,8 @@ S = s(domains) sols = self.and_sols( sols, S ) return sols - def not_sols(self,domains): + def not_sols(self, domains): sols1 = self.s1.not_sols(domains) sols2 = self.s2.not_sols(domains) return self.or_sols(sols1,sols2) @@ -137,7 +143,8 @@ return upd class SolOr(SolBase): - def __init__(self, s1, s2 ): + + def __init__(self, s1, s2): self.s1 = s1 self.s2 = s2 @@ -141,8 +148,8 @@ self.s1 = s1 self.s2 = s2 - def sols(self,domains): + def sols(self, domains): sols1 = self.s1.sols(domains) sols2 = self.s2.sols(domains) return self.or_sols( sols1, sols2 ) @@ -145,8 +152,8 @@ sols1 = self.s1.sols(domains) sols2 = self.s2.sols(domains) return self.or_sols( sols1, sols2 ) - def not_sols(self,domains): + def not_sols(self, domains): sols1 = self.s1.not_sols(domains) sols2 = self.s2.not_sols(domains) return self.and_sols(sols1,sols2) @@ -163,6 +170,7 @@ class SolRelation(SolBase): """Boolean relation between variables""" + def __init__(self, *variables): self._variables = list(variables) @@ -176,7 +184,8 @@ class SolVar(SolRelation): """Simple unary relation True if var in set""" - def __init__(self,V,s): + + def __init__(self, V, s): self.var = V self.set = s @@ -186,6 +195,6 @@ upd[self.var] = 0 return upd - def sols(self,domains): + def sols(self, domains): return [ { self.var : v } for v in self.set if v in domains[self.var] ] @@ -190,6 +199,6 @@ return [ { self.var : v } for v in self.set if v in domains[self.var] ] - def not_sols(self,domains): + def not_sols(self, domains): return [ { self.var : v } for v in domains[self.var] if v not in self.set ] def __str__(self): @@ -200,7 +209,8 @@ class SolEq(SolRelation): """Simple equality between variables""" - def sols(self,domains): + + def sols(self, domains): d = {} # intersect domains for var in self._variables: @@ -218,7 +228,7 @@ result.append( r ) return result - def not_sols(self,domains): + def not_sols(self, domains): raise NotImplementedError def __str__(self): @@ -228,9 +238,9 @@ if isinstance(v, SolVar): self._variables.append(v) elif isinstance(v, SolEq): - self._variables+=v._variables + self._variables += v._variables else: raise RuntimeError("Invalid model") return self if __name__ == "__main__": @@ -232,8 +242,9 @@ else: raise RuntimeError("Invalid model") return self if __name__ == "__main__": + # XXX turn this into a test or remove D = { 'x' : range(5), 'y' : range(6), diff --git a/undo.py b/undo.py index a08fe38dcb4c9afc5c4bf2fb5cf5e13880d0bec3_dW5kby5weQ==..355006b88d3a28eb13cb5c8e8a8911126e8f1bfd_dW5kby5weQ== 100644 --- a/undo.py +++ b/undo.py @@ -10,7 +10,7 @@ from rql.nodes import VariableRef, Variable, BinaryNode from rql.stmts import Select -class SelectionManager: +class SelectionManager(object): """manage the operation stacks""" def __init__(self, selection): @@ -46,7 +46,7 @@ """flush the current operations""" self.op_list = [] -class NodeOperation: +class NodeOperation(object): """abstract class for node manipulation operations""" def __init__(self, node): self.node = node @@ -100,7 +100,7 @@ """undo the operation on the selection""" selection.remove_node(self.node) -class ReplaceNodeOperation: +class ReplaceNodeOperation(object): """defines how to undo 'replace node'""" def __init__(self, old_node, new_node): self.old_node = old_node @@ -192,7 +192,7 @@ # misc operations ############################################################# -class ChangeValueOperation: +class ChangeValueOperation(object): def __init__(self, previous_value, node=None): self.value = previous_value self.node = node diff --git a/utils.py b/utils.py index a08fe38dcb4c9afc5c4bf2fb5cf5e13880d0bec3_dXRpbHMucHk=..355006b88d3a28eb13cb5c8e8a8911126e8f1bfd_dXRpbHMucHk= 100644 --- a/utils.py +++ b/utils.py @@ -6,9 +6,6 @@ """ __docformat__ = "restructuredtext en" -from rql._exceptions import BadRQLQuery - - UPPERCASE = u'ABCDEFGHIJKLMNOPQRSTUVWXYZ' def decompose_b26(index, table=UPPERCASE): """return a letter (base-26) decomposition of index""" @@ -118,7 +115,7 @@ cls.accept = eval(_accept % (cls.__name__.lower())) cls.leave = eval(_leave % (cls.__name__.lower())) -class RQLVisitorHandler: +class RQLVisitorHandler(object): """handler providing a dummy implementation of all callbacks necessary to visit a RQL syntax tree """