# -*- coding: iso-8859-1 -*-
#-----------------------------------------------------------------------------
# Modeling Framework: an Object-Relational Bridge for python
#
# Copyright (c) 2001-2004 Sbastien Bigaret <sbigaret@users.sourceforge.net>
# All rights reserved.
#
# This file is part of the Modeling Framework.
#
# This code is distributed under a "3-clause BSD"-style license;
# see the LICENSE file for details.
#-----------------------------------------------------------------------------
"""
Qualifier API
* Predefined Operators
* Module functions (building qualifiers, in-memory filtering, etc.)
* Qualifiers: AND, NOT, ...
CVS Information
$Id: Qualifier.py 932 2004-07-20 06:21:57Z sbigaret $
"""
__version__='$Revision: 932 $'[11:-2]
try:
from Interface import Base
except:
class Base:
pass
# Predefined Operators
def QualifierOperatorEqual(value1, value2):
""
def QualifierOperatorNotEqual(value1, value2):
""
def QualifierOperatorGreaterThan(value1, value2):
""
def QualifierOperatorLessThan(value1, value2):
""
def QualifierOperatorGreaterThanOrEqualTo(value1, value2):
""
def QualifierOperatorLessThanOrEqualTo(value1, value2):
""
def QualifierOperatorContains(value1, value2):
""
def QualifierOperatorLike(value1, value2):
""
def QualifierOperatorCaseInsensitiveLike(value1, value2):
""
# Module functions
def allQualifierOperators():
"""
Returns all strings which can be turned into a QualifierOperator by
method 'operatorForString()'
"""
def filteredArrayWithQualifier(objects, qualifier):
"Returns those objects in 'objects' which match the supplied qualifier"
def operatorForString(aString):
"Returns the QualifierOperator corresponding to the supplied string"
def qualifierToMatchAllValues(aDictionary):
"""
Returns an AndQualifier composed with KeyValueQualifier matching the keys
in the dictionary with their values --used operator: OperatorQualifierEqual
"""
def qualifierToMatchAnyValues(aDictionary):
"""
Returns an OrQualifier composed with KeyValueQualifier matching the keys
in the dictionary with their values --used operator: OperatorQualifierEqual
"""
def qualifierWithQualifierFormat(qualifierFormat): #, arguments
"""
Builds a Qualifier from a given expression, such as::
NOT ( name=='truc' AND age>30 AND age < 65 )
"""
# We do not need any parameters 'arguments' here: python already offers a
# powerful mechanism for variable substitution within a string.
# NB: same for qualifierWithBindings
#
# Note2: well, this is only partially true, especially when you consider
# qualifier as a part of a FetchSpecification. It could be nice to be able to
# supply to a FetchSpec. a qualifier without the bindings, and then to use these bindings as 'parameters' for that fetchSpec. Okay, to be continued.
def relationalQualifierOperators():
"""
Returns all operators except those dedicated to string comparisons, 'like'
and 'caseInsensitiveLike'
"""
class QualifierInterface(Base):
"""
"""
def addQualifierKeysToSet(self, qualifierKeysList): # must be overridden
"""Adds the receiver's qualifier keys to the supplied list. This must
be overriden in subclasses"""
def allQualifierKeys(self):
"""
Returns the set (tuple) of keys used in the qualifier. The returned tuple
has no duplicate.
For example, for a qualifier defined like this::
NOT((age<=30 OR age>50) AND book.title caseInsensitiveLike "*hitchhiker*"
the set ('age', 'book.title') is returned.
Subclasses should not override this method: override addQualifierKeysToSet
instead.
"""
def bindingKeys(self):
""
def evaluateWithObject(self, object): # object implements KeyValueCoding
"""
Tests whether the supplied object matches the qualifier
Parameter 'object' should be a subclass of KeyValueCoding
"""
def keyPathForBindingKey(self, aKey):
""
def validateKeysWithRootClassDescription(self, aClassDescription): # abstract
"""
Checks that all qualifierKeys can be found in the supplied class
description, either in attributes or relationships. When a keypath is
involved, like 'book.title', only the first part, i.e. 'book', while
be checked against the class description ; the remaining part is not
checked at all.
Raises ValueError on failure.
"""
|