commit-gnue
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnue] r7800 - trunk/gnue-common/src/datasources


From: reinhard
Subject: [gnue] r7800 - trunk/gnue-common/src/datasources
Date: Mon, 8 Aug 2005 08:14:48 -0500 (CDT)

Author: reinhard
Date: 2005-08-08 08:14:46 -0500 (Mon, 08 Aug 2005)
New Revision: 7800

Modified:
   trunk/gnue-common/src/datasources/GConditions.py
Log:
Cleanup, docstrings, comments.


Modified: trunk/gnue-common/src/datasources/GConditions.py
===================================================================
--- trunk/gnue-common/src/datasources/GConditions.py    2005-08-08 08:56:12 UTC 
(rev 7799)
+++ trunk/gnue-common/src/datasources/GConditions.py    2005-08-08 13:14:46 UTC 
(rev 7800)
@@ -20,6 +20,9 @@
 # - Suite 330, Boston, MA 02111-1307, USA.
 #
 # $Id$
+"""
+Classes for the condition object tree.
+"""
 
 import re
 import sys
@@ -36,16 +39,33 @@
 # Exceptions
 # =============================================================================
 
+# -----------------------------------------------------------------------------
+# Abstract base class
+# -----------------------------------------------------------------------------
+
 class ConditionError (errors.ApplicationError):
+  """
+  Abstract base class for all errors in condition definitions.
+  """
   pass
 
-class ConditionNotSupported (ConditionError):
-  pass
 
+# -----------------------------------------------------------------------------
+# Malformed condition tree
+# -----------------------------------------------------------------------------
+
 class MalformedConditionTreeError (ConditionError):
+  """
+  Abstract base class for all errors in the structure of the condition tree.
+  """
   pass
 
+# -----------------------------------------------------------------------------
+
 class ArgumentCountError (MalformedConditionTreeError):
+  """
+  Number of child elements is incorrect.
+  """
   def __init__ (self, element, wanted):
     msg = u_("Conditionelement '%(element)s' was expected to have '%(wanted)d'"
              "arguments, but only has %(real)d'") \
@@ -54,17 +74,38 @@
              'real'   : len (element._children)}
     MalformedConditionTreeError.__init__ (self, msg)
 
+
+# -----------------------------------------------------------------------------
+# Field value not in lookup dictionary
+# -----------------------------------------------------------------------------
+
 class MissingFieldError (ConditionError):
+  """
+  Cannot find field value on attempt to evaluate a condition.
+  """
+
   def __init__ (self, field):
     msg = u_("The field '%(field)s' has no entry in the given lookup-table") \
           % {'field': field }
     ConditionError.__init__ (self, msg)
 
 
+# -----------------------------------------------------------------------------
+# Errors on unifying of different types
+# -----------------------------------------------------------------------------
+
 class UnificationError (errors.ApplicationError):
+  """
+  Abstract base class for all errors on unifying different data types.
+  """
   pass
 
+# -----------------------------------------------------------------------------
+
 class ConversionRuleError (UnificationError):
+  """
+  Cannot convert both data types into a common compatible type.
+  """
   def __init__ (self, value1, value2):
     msg = u_("No unification rule for combination '%(type1)s' and "
              "'%(type2)s'") \
@@ -72,7 +113,12 @@
              'type2': type (value2).__name__}
     UnificationError.__init__ (self, msg)
 
+# -----------------------------------------------------------------------------
+
 class ConversionError (UnificationError):
+  """
+  Cannot convert a value.
+  """
   def __init__ (self, value1, value2):
     msg = u_("Value '%(value1)s' of type '%(type1)s' cannot be converted "
              "into type '%(type2)s'") \
@@ -92,14 +138,14 @@
   children of a GCondition node are evaluated and combined using an AND
   condition if not otherwise stated.
 
-  @ivar _maxChildren: if not None specifies the maximum number of children
-      allowed for a condition element.
-  @ivar _operator: unicode string defining the operator used for SQL
-      transformation of a condition element.
+  @ivar _maxChildren_: if not None specifies the maximum number of children
+    allowed for a condition element.
+  @ivar _operator_: unicode string defining the operator used for SQL
+    transformation of a condition element.
   """
 
   # ---------------------------------------------------------------------------
-  # Create a new condition tree item
+  # Constructor
   # ---------------------------------------------------------------------------
 
   def __init__(self, parent = None, type = "GCCondition", prefixList = None):
@@ -107,13 +153,13 @@
     @param parent: Parent instance in the GObj tree owning this instance
     @param type: type of this instance (usually 'GCCondition')
     @param prefixList: a condition in prefix notation; if this sequence is not
-        None, a condition tree according to this sequence will be built. This
-        instance is the root element of the newly created condition tree.
+      None, a condition tree according to this sequence will be built. This
+      instance is the root element of the newly created condition tree.
     """
 
     GObjects.GObj.__init__ (self, parent, type = type)
-    self._maxChildren = None
-    self._operator    = u''
+    self._maxChildren_ = None
+    self._operator_    = u""
 
     if prefixList is not None:
       self.buildFromList (prefixList)
@@ -130,12 +176,12 @@
     Ensure that the requested number of children is available.
 
     @raise ArgumentCountError: raised if the number of children does not match
-        _maxChildren.
+      _maxChildren_.
     """
 
-    if self._maxChildren is not None and \
-        len (self._children) != self._maxChildren:
-      raise ArgumentCountError, (self, self._maxChildren)
+    if self._maxChildren_ is not None and \
+        len (self._children) != self._maxChildren_:
+      raise ArgumentCountError, (self, self._maxChildren_)
 
 
   # ---------------------------------------------------------------------------
@@ -149,6 +195,15 @@
 
     @param lookup: dictionary used for lookups of field- and parameter-values.
     @return: True or False
+
+    @raise L{ArgumentCountError}: if the number of child elements somewhere in
+      the tree is incorrect.
+    @raise L{MissingFieldError}: if not all fields appearing in the condition
+      tree are assigned a value in the lookup dictionary.
+    @raise L{ConversionRuleError}: if any operation is given two incompatible
+      arguments.
+    @raise L{ConversionError}: if the type conversion needed to make arguments
+      of an operation comatible fails.
     """
 
     self.validate ()
@@ -168,6 +223,9 @@
     """
     This function calls validate () on all it's children. Descendants might
     override this function to do integrity checks and things like that.
+
+    @raise ArgumentCountError: if the number of child elements somewhere in the
+      tree is incorrect.
     """
 
     self._needChildren ()
@@ -216,13 +274,13 @@
       pDcit  = {'p0': 'barbaz'}
 
     @param paramDict: dictionary with all parameter values. this dictionary
-        will be populated with all placeholders used in the SQL string.
+      will be populated with all placeholders used in the SQL string.
 
     @return: SQL string representing the current condition
     """
 
     f = isinstance (self.getParent (), GConditionElement) and u'(%s)' or u'%s'
-    op = u' %s ' % self._operator
+    op = u' %s ' % self._operator_
     return f % op.join ([c.asSQL (paramDict) for c in self._children])
 
 
@@ -268,28 +326,41 @@
 
 
 # =============================================================================
-# Top level classes 
+# Parent class for all condition elements
 # =============================================================================
 
-class GConditions (GCondition):
-  def __init__(self, parent = None, type = "GCConditions"):
-    GCondition.__init__(self, parent, type = type)
+class GConditionElement (GCondition) :
+  """
+  Abstract base class for all condition elements.
+  """
 
-class GConditionElement (GCondition) :
+  # ---------------------------------------------------------------------------
+  # Constructor
+  # ---------------------------------------------------------------------------
+
   def __init__(self, parent=None, type="GConditionElement"):
     GCondition.__init__ (self, parent, type = type)
 
 
-# -----------------------------------------------------------------------------
+# =============================================================================
 # A Field element in the condition tree
-# -----------------------------------------------------------------------------
+# =============================================================================
 
 class GCField (GConditionElement):
+  """
+  Field value from a database table.
+  """
+
+  # ---------------------------------------------------------------------------
+  # Constructor
+  # ---------------------------------------------------------------------------
+
   def __init__(self, parent, name = None, datatype = "char"):
     GConditionElement.__init__ (self, parent, 'GCCField')
     self.type = datatype
     self.name = name
 
+
   # ---------------------------------------------------------------------------
   # Evaluate a field element
   # ---------------------------------------------------------------------------
@@ -354,11 +425,19 @@
     return self.name
 
 
-# -----------------------------------------------------------------------------
+# =============================================================================
 # A constant definition in a condition tree
-# -----------------------------------------------------------------------------
+# =============================================================================
 
 class GCConst (GConditionElement):
+  """
+  Constant value of a specific type.
+  """
+
+  # ---------------------------------------------------------------------------
+  # Constructor
+  # ---------------------------------------------------------------------------
+
   def __init__ (self, parent, value = None, datatype = "char"):
     GConditionElement.__init__ (self, parent, 'GCCConst')
     self.type   = datatype
@@ -368,6 +447,7 @@
     if self.value is not None:
       self.__typecast ()
 
+
   # ---------------------------------------------------------------------------
   # Evaluate a constant
   # ---------------------------------------------------------------------------
@@ -463,16 +543,26 @@
       self.value = GDateTime.parseISO (self.value)
 
 
-# -----------------------------------------------------------------------------
+# =============================================================================
 # Base class for parameter elements in a condition tree
-# -----------------------------------------------------------------------------
+# =============================================================================
 
 class GCParam (GConditionElement):
+  """
+  Abstract class for parameters. Must be overridden by a descendant to handle
+  actual parameter values.
+  """
+
+  # ---------------------------------------------------------------------------
+  # Constructor
+  # ---------------------------------------------------------------------------
+
   def __init__ (self, parent, name = None, datatype = "char"):
     GConditionElement.__init__ (self, parent, 'GCCParam')
     self.type = datatype
     self.name = name
 
+
   # ---------------------------------------------------------------------------
   # Return the value of a parameter
   # ---------------------------------------------------------------------------
@@ -533,14 +623,23 @@
 
 
 # =============================================================================
-# Base classes for unary and binary operations
+# Base classes for unary operations
 # =============================================================================
 
 class GUnaryConditionElement (GConditionElement):
+  """
+  Abstract base class for all unary condition elements.
+  """
+
+  # ---------------------------------------------------------------------------
+  # Constructor
+  # ---------------------------------------------------------------------------
+
   def __init__ (self, parent = None, elementType = ''):
     GConditionElement.__init__ (self, parent, elementType)
-    self._maxChildren = 1
+    self._maxChildren_ = 1
 
+
   # ---------------------------------------------------------------------------
   # Return a SQL representation of a unary operation
   # ---------------------------------------------------------------------------
@@ -553,7 +652,7 @@
     @return: SQL code (in python-format) for the operation
     """
 
-    return self._operator % self._children [0].asSQL (paramDict)
+    return self._operator_ % self._children [0].asSQL (paramDict)
 
 
 # =============================================================================
@@ -561,11 +660,20 @@
 # =============================================================================
 
 class GBinaryConditionElement (GConditionElement):
+  """
+  Abstract base class for all binary condition elements.
+  """
+
+  # ---------------------------------------------------------------------------
+  # Constructor
+  # ---------------------------------------------------------------------------
+
   def __init__ (self, parent = None, elementType = ''):
     GConditionElement.__init__ (self, parent, elementType)
-    self._maxChildren = 2
+    self._maxChildren_ = 2
     self.values       = []
 
+
   # ---------------------------------------------------------------------------
   # Evaluating a binary element means evaluation of both children
   # ---------------------------------------------------------------------------
@@ -575,6 +683,9 @@
     This function evaluates both children of a binary element storing their
     values in the property 'values'. Descendants can use these values for
     further evaluations.
+
+    @raise ArgumentCountError: if the number of child elements somewhere in the
+      tree is incorrect.
     """
 
     self._needChildren ()
@@ -590,9 +701,12 @@
 # -----------------------------------------------------------------------------
 
 class GCand (GConditionElement):
+  """
+  Logical AND.
+  """
   def __init__ (self, parent = None):
     GConditionElement.__init__ (self, parent, 'GCand')
-    self._operator = 'AND'
+    self._operator_ = u"AND"
 
 
 # -----------------------------------------------------------------------------
@@ -600,13 +714,14 @@
 # -----------------------------------------------------------------------------
 
 class GCor (GConditionElement):
+  """
+  Logical OR.
+  """
   def __init__ (self, parent = None):
     GConditionElement.__init__ (self, parent, 'GCor')
-    self._operator = 'OR'
+    self._operator_ = u"OR"
 
   # ---------------------------------------------------------------------------
-  # Evaluate an OR tree
-  # ---------------------------------------------------------------------------
 
   def evaluate (self, lookup):
     """
@@ -626,13 +741,14 @@
 # -----------------------------------------------------------------------------
 
 class GCnot (GUnaryConditionElement):
+  """
+  Logical NOT.
+  """
   def __init__ (self, parent = None):
     GUnaryConditionElement.__init__ (self, parent, 'GCnot')
-    self._operator = 'NOT %s'
+    self._operator_ = u"NOT %s"
 
   # ---------------------------------------------------------------------------
-  # logically Invert the childs result
-  # ---------------------------------------------------------------------------
 
   def evaluate (self, lookup):
     """
@@ -643,7 +759,6 @@
     return not self._children [0].evaluate (lookup)
 
 
-
 # =============================================================================
 # Numeric operations
 # =============================================================================
@@ -653,13 +768,15 @@
 # ---------------------------------------------------------------------------
 
 class GCadd (GConditionElement):
+  """
+  Numeric addition.
+  """
   def __init__ (self, parent = None):
     GConditionElement.__init__ (self, parent, 'GCadd')
-    self._operator = '+'
+    self._operator_ = u"+"
 
   # ---------------------------------------------------------------------------
-  # Evaluate the addition element
-  # ---------------------------------------------------------------------------
+
   def evaluate (self, lookup):
     """
     This function creates the sum of all it's children. A unify is used to
@@ -677,13 +794,14 @@
 # -----------------------------------------------------------------------------
 
 class GCsub (GConditionElement):
+  """
+  Numeric subtraction.
+  """
   def __init__ (self, parent = None):
     GConditionElement.__init__ (self, parent, 'GCsub')
-    self._operator = '-'
+    self._operator_ = u"-"
 
   # ---------------------------------------------------------------------------
-  # Evaluate the subtraction element
-  # ---------------------------------------------------------------------------
 
   def evaluate (self, lookup):
     result = None
@@ -703,13 +821,14 @@
 # -----------------------------------------------------------------------------
 
 class GCmul (GConditionElement):
+  """
+  Numeric multiplication.
+  """
   def __init__ (self, parent = None):
     GConditionElement.__init__ (self, parent, 'GCmul')
-    self._operator = '*'
+    self._operator_ = u"*"
 
   # ---------------------------------------------------------------------------
-  # Evaluate the multiplication
-  # ---------------------------------------------------------------------------
 
   def evaluate (self, lookup):
     result = None
@@ -729,14 +848,14 @@
 # -----------------------------------------------------------------------------
 
 class GCdiv (GConditionElement):
+  """
+  Numeric division.
+  """
   def __init__ (self, parent = None):
     GConditionElement.__init__ (self, parent, 'GCdiv')
-    self._operator = '/'
+    self._operator_ = u"/"
 
-
   # ---------------------------------------------------------------------------
-  # Evaluate the division element
-  # ---------------------------------------------------------------------------
 
   def evaluate (self, lookup):
     result = None
@@ -756,19 +875,19 @@
 # -----------------------------------------------------------------------------
 
 class GCnegate (GUnaryConditionElement):
+  """
+  Numeric negation.
+  """
   def __init__ (self, parent = None):
     GUnaryConditionElement.__init__ (self, parent, 'GCnegate')
-    self._operator = u"-%s"
+    self._operator_ = u"-%s"
 
   # ---------------------------------------------------------------------------
-  # Evaluation of the numeric negation
-  # ---------------------------------------------------------------------------
 
   def evaluate (self, lookup):
     """
     This function does a numeric negation on the child's evaluation result.
     """
-
     self._needChildren ()
     return -unify ([self._children [0].evaluate (lookup), 0]) [0]
     
@@ -782,22 +901,20 @@
 # -----------------------------------------------------------------------------
 
 class GCeq (GBinaryConditionElement):
+  """
+  Test for equality.
+  """
   def __init__ (self, parent = None):
     GBinaryConditionElement.__init__ (self, parent, 'GCeq')
-    self._operator = u"="
+    self._operator_ = u"="
 
   # ---------------------------------------------------------------------------
-  # evaluate EQ relation
-  # ---------------------------------------------------------------------------
 
   def evaluate (self, lookup):
     GBinaryConditionElement.evaluate (self, lookup)
     return self.values [0] == self.values [1]
 
-
   # ---------------------------------------------------------------------------
-  # Return a SQL representation of an equal relation
-  # ---------------------------------------------------------------------------
 
   def asSQL (self, paramDict):
     """
@@ -811,7 +928,7 @@
 
     if isinstance (self._children [1], GCConst) and \
         self._children [1].value is None:
-      self._operator = u"IS"
+      self._operator_ = u"IS"
 
     return GBinaryConditionElement.asSQL (self, paramDict)
 
@@ -821,22 +938,20 @@
 # -----------------------------------------------------------------------------
 
 class GCne (GBinaryConditionElement):
+  """
+  Test for inequality.
+  """
   def __init__ (self, parent = None):
     GBinaryConditionElement.__init__ (self, parent, 'GCne')
-    self._operator = u"!="
+    self._operator_ = u"!="
 
   # ---------------------------------------------------------------------------
-  # evaluate NE relation
-  # ---------------------------------------------------------------------------
 
   def evaluate (self, lookup):
     GBinaryConditionElement.evaluate (self, lookup)
     return self.values [0] != self.values [1]
 
-
   # ---------------------------------------------------------------------------
-  # Return a SQL representation of an inequal relation
-  # ---------------------------------------------------------------------------
 
   def asSQL (self, paramDict):
     """
@@ -850,7 +965,7 @@
 
     if isinstance (self._children [1], GCConst) and \
         self._children [1].value is None:
-      self._operator = u"IS NOT"
+      self._operator_ = u"IS NOT"
 
     return GBinaryConditionElement.asSQL (self, paramDict)
 
@@ -860,13 +975,14 @@
 # -----------------------------------------------------------------------------
 
 class GCgt (GBinaryConditionElement):
+  """
+  Test for greater than.
+  """
   def __init__ (self, parent = None):
     GBinaryConditionElement.__init__ (self, parent, 'GCgt')
-    self._operator = u">"
+    self._operator_ = u">"
 
   # ---------------------------------------------------------------------------
-  # evaluate GT relation
-  # ---------------------------------------------------------------------------
 
   def evaluate (self, lookup):
     GBinaryConditionElement.evaluate (self, lookup)
@@ -878,13 +994,14 @@
 # -----------------------------------------------------------------------------
 
 class GCge (GBinaryConditionElement):
+  """
+  Test for greater or equal.
+  """
   def __init__ (self, parent = None):
     GBinaryConditionElement.__init__ (self, parent, 'GCge')
-    self._operator = u">="
+    self._operator_ = u">="
 
   # ---------------------------------------------------------------------------
-  # evaluate GE relation
-  # ---------------------------------------------------------------------------
 
   def evaluate (self, lookup):
     GBinaryConditionElement.evaluate (self, lookup)
@@ -896,13 +1013,14 @@
 # -----------------------------------------------------------------------------
 
 class GClt (GBinaryConditionElement):
+  """
+  Test for lower than.
+  """
   def __init__ (self, parent = None):
     GBinaryConditionElement.__init__ (self, parent, 'GClt')
-    self._operator = u"<"
+    self._operator_ = u"<"
 
   # ---------------------------------------------------------------------------
-  # evaluate LT relation
-  # ---------------------------------------------------------------------------
 
   def evaluate (self, lookup):
     GBinaryConditionElement.evaluate (self, lookup)
@@ -914,13 +1032,14 @@
 # -----------------------------------------------------------------------------
 
 class GCle (GBinaryConditionElement):
+  """
+  Test for lower or equal.
+  """
   def __init__ (self, parent = None):
     GBinaryConditionElement.__init__ (self, parent, 'GCle')
-    self._operator = u"<="
+    self._operator_ = u"<="
 
   # ---------------------------------------------------------------------------
-  # evaluate LE relation
-  # ---------------------------------------------------------------------------
 
   def evaluate (self, lookup):
     GBinaryConditionElement.evaluate (self, lookup)
@@ -932,13 +1051,14 @@
 # -----------------------------------------------------------------------------
 
 class GClike (GBinaryConditionElement):
+  """
+  Test for SQL LIKE.
+  """
   def __init__ (self, parent = None):
     GBinaryConditionElement.__init__ (self, parent, 'GClike')
-    self._operator = u"LIKE"
+    self._operator_ = u"LIKE"
 
   # ---------------------------------------------------------------------------
-  # Evaluate a like condition
-  # ---------------------------------------------------------------------------
 
   def evaluate (self, lookup):
     GBinaryConditionElement.evaluate (self, lookup)
@@ -958,13 +1078,14 @@
 # -----------------------------------------------------------------------------
 
 class GCnotlike (GBinaryConditionElement):
+  """
+  Test for SQL NOT LIKE.
+  """
   def __init__ (self, parent = None):
     GBinaryConditionElement.__init__ (self, parent, 'GCnotlike')
-    self._operator = u"NOT LIKE"
+    self._operator_ = u"NOT LIKE"
 
   # ---------------------------------------------------------------------------
-  # Evaluate an inverted like condition
-  # ---------------------------------------------------------------------------
 
   def evaluate (self, lookup):
     GBinaryConditionElement.evaluate (self, lookup)
@@ -979,24 +1100,22 @@
 # -----------------------------------------------------------------------------
 
 class GCbetween (GConditionElement):
+  """
+  Test for SQL BETWEEN.
+  """
   def __init__ (self, parent = None):
     GConditionElement.__init__ (self, parent, 'GCbetween')
-    self._maxChildren = 3
-    self._operator = u"BETWEEN"
+    self._maxChildren_ = 3
+    self._operator_ = u"BETWEEN"
 
   # ---------------------------------------------------------------------------
-  # evaluate beetween relation
-  # ---------------------------------------------------------------------------
 
   def evaluate (self, lookup):
     self._needChildren ()
     values = unify ([v.evaluate (lookup) for v in self._children])
     return values [1] <= values [0] <= values [2]
 
-
   # ---------------------------------------------------------------------------
-  # Return a SQL representation of a condition element
-  # ---------------------------------------------------------------------------
 
   def asSQL (self, paramDict):
     """
@@ -1016,24 +1135,22 @@
 # -----------------------------------------------------------------------------
 
 class GCnotbetween (GConditionElement):
+  """
+  Test for SQL NOT BETWEEN.
+  """
   def __init__ (self, parent = None):
     GConditionElement.__init__ (self, parent, 'GCnotbetween')
-    self._maxChildren = 3
-    self._operator = u"NOT BETWEEN"
+    self._maxChildren_ = 3
+    self._operator_ = u"NOT BETWEEN"
 
   # ---------------------------------------------------------------------------
-  # evaluate an inverted beetween relation
-  # ---------------------------------------------------------------------------
 
   def evaluate (self, lookup):
     self._needChildren ()
     values = unify ([v.evaluate (lookup) for v in self._children])
     return not (values [1] <= values [0] <= values [2])
 
-
   # ---------------------------------------------------------------------------
-  # Return a SQL representation of a condition element
-  # ---------------------------------------------------------------------------
 
   def asSQL (self, paramDict):
     """
@@ -1053,13 +1170,14 @@
 # -----------------------------------------------------------------------------
 
 class GCnull (GUnaryConditionElement):
+  """
+  Test for SQL IS NULL
+  """
   def __init__ (self, parent = None):
     GUnaryConditionElement.__init__ (self, parent, 'GCnull')
-    self._operator = u"(%s IS NULL)"
+    self._operator_ = u"(%s IS NULL)"
 
   # ---------------------------------------------------------------------------
-  # evaluate if a child is NULL
-  # ---------------------------------------------------------------------------
 
   def evaluate (self, lookup):
     self._needChildren ()
@@ -1071,30 +1189,33 @@
 # -----------------------------------------------------------------------------
 
 class GCnotnull (GUnaryConditionElement):
+  """
+  Test for SQL IS NOT NULL
+  """
   def __init__ (self, parent = None):
     GUnaryConditionElement.__init__ (self, parent, 'GCnotnull')
-    self._operator = u"(%s IS NOT NULL)"
+    self._operator_ = u"(%s IS NOT NULL)"
 
   # ---------------------------------------------------------------------------
-  # evaluate if a child is not NULL
-  # ---------------------------------------------------------------------------
 
   def evaluate (self, lookup):
     self._needChildren ()
     return self._children [0].evaluate (lookup) is not None
 
+
 # -----------------------------------------------------------------------------
 # upper  
 # -----------------------------------------------------------------------------
 
 class GCupper (GUnaryConditionElement):
+  """
+  String conversion to uppercase.
+  """
   def __init__ (self, parent = None):
     GUnaryConditionElement.__init__ (self, parent, 'GCupper')
-    self._operator = u"UPPER (%s)"
+    self._operator_ = u"UPPER (%s)"
 
   # ---------------------------------------------------------------------------
-  # evaluate
-  # ---------------------------------------------------------------------------
 
   def evaluate (self, lookup):
     self._needChildren ()
@@ -1106,33 +1227,33 @@
 # -----------------------------------------------------------------------------
 
 class GClower (GUnaryConditionElement):
+  """
+  String conversion to lowercase.
+  """
   def __init__ (self, parent = None):
     GUnaryConditionElement.__init__ (self, parent, 'GClower')
-    self._operator = u"LOWER (%s)"
+    self._operator_ = u"LOWER (%s)"
 
-
   # ---------------------------------------------------------------------------
-  # evaluate
-  # ---------------------------------------------------------------------------
 
   def evaluate (self, lookup):
     self._needChildren ()
     return (self._children [0].evaluate (lookup)).lower ()
 
 
-
 # -----------------------------------------------------------------------------
 # exist
 # -----------------------------------------------------------------------------
 
 class GCexist (GConditionElement):
+  """
+  Test if a record fulfilling a given condition exists in another table.
+  """
   def __init__ (self, parent = None):
     GConditionElement.__init__ (self, parent, 'GCexist')
     self.callback = None
 
   # ---------------------------------------------------------------------------
-  # Evaluate an exist-condition
-  # ---------------------------------------------------------------------------
 
   def evaluate (self, lookup):
 
@@ -1141,10 +1262,7 @@
 
     return self.callback (self, lookup)
 
-
   # ---------------------------------------------------------------------------
-  # Convert an element into prefix notation
-  # ---------------------------------------------------------------------------
 
   def prefixNotation (self):
     """
@@ -1158,10 +1276,7 @@
 
     return result
 
-
   # ---------------------------------------------------------------------------
-  # SQL representation
-  # ---------------------------------------------------------------------------
 
   def asSQL (self, paramDict):
     """
@@ -1180,175 +1295,155 @@
 
 def getXMLelements (updates = {}):
   xmlElements = {
-      'conditions':       {
-         'BaseClass': GCondition,
-         'ParentTags':  ('conditions','and','or','not','negate'),
-         'Deprecated': 'Use the <condition> tag instead.',
-         },
-      'condition':       {
-         'BaseClass': GCondition,
-         'ParentTags':  ('conditions','and','or','not','negate','exist') },
-      'cfield':       {
-         'BaseClass': GCField,
+      'conditions': {
+         'BaseClass'  : GCondition,
+         'ParentTags' : ('conditions','and','or','not','negate'),
+         'Deprecated' : 'Use the <condition> tag instead.'},
+      'condition': {
+         'BaseClass'  : GCondition,
+         'ParentTags' : ('conditions','and','or','not','negate','exist')},
+      'cfield': {
+         'BaseClass'  : GCField,
          'Description': 'Defines a database table\'s field in a condition.',
-         'Attributes': {
-            'name':     {
-               'Required': True,
-               'Typecast': GTypecast.name } },
-         'ParentTags':  ('eq','ne','lt','le','gt','ge','add','sub','mul',
+         'Attributes' : {'name': {'Required': True,
+                                  'Typecast': GTypecast.name }},
+         'ParentTags' : ('eq','ne','lt','le','gt','ge','add','sub','mul',
                          'div','like','notlike','between','notbetween',
-                         'upper', 'lower', 'null', 'notnull') },
-      'cparam':       {
-         'BaseClass': GCParam,
+                         'upper', 'lower', 'null', 'notnull')},
+      'cconst': {
+         'BaseClass'  : GCConst,
+         'Description': 'Defines a constant value in a condition.',
+         'Attributes' : {'value': {'Required': True,
+                                   'Typecast': GTypecast.text},
+                         'type' : {'Typecast': GTypecast.text }},
+         'ParentTags' : ('eq','ne','lt','le','gt','ge','add','sub','mul',
+                         'div','like','notlike','between','notbetween')},
+      'cparam': {
+         'BaseClass'  : GCParam,
          'Description': 'Defines a parameter value in a condition.',
-         'Attributes': {
-            'name':        {
-               'Required': True,
-               'Unique':   True,
-               'Typecast': GTypecast.name } },
-         'ParentTags':  ('eq','ne','lt','le','gt','ge','add','sub','mul',
-                         'div','like','notlike','between','notbetween') },
-      'cconst':       {
-         'BaseClass': GCConst,
-         'Description': 'Defines a constant value in a condition.',
-         'Attributes': {
-            'value':     {
-               'Required': True,
-               'Typecast': GTypecast.text },
-            'type':     {
-               'Typecast': GTypecast.text } },
-         'ParentTags':  ('eq','ne','lt','le','gt','ge','add','sub','mul',
-                         'div','like','notlike','between','notbetween') },
-      'add':       {
-         'BaseClass': GCadd,
+         'Attributes' : {'name': {'Required': True,
+                                  'Unique':   True,
+                                  'Typecast': GTypecast.name }},
+         'ParentTags' : ('eq','ne','lt','le','gt','ge','add','sub','mul',
+                         'div','like','notlike','between','notbetween')},
+      'and': {
+         'BaseClass'  : GCand,
+         'Description': 'Implements logical AND relation.',
+         'ParentTags' : ('condition','and','or','not','negate')},
+      'or': {
+         'BaseClass'  : GCor,
+         'Description': 'Implements logical OR relation.',
+         'ParentTags' : ('condition','and','or','not','negate')},
+      'not': {
+         'BaseClass'  : GCnot,
+         'Description': 'Implements logical NOT relation.',
+         'ParentTags' : ('condition','and','or','not','negate')},
+      'add': {
+         'BaseClass'  : GCadd,
          'Description': 'Implements addition.',
-         'ParentTags':  ('eq','ne','lt','le','gt','ge','add','sub','mul',
-                         'div','like','notlike','between','notbetween') },
-      'sub':       {
-         'BaseClass': GCsub,
+         'ParentTags' : ('eq','ne','lt','le','gt','ge','add','sub','mul',
+                         'div','like','notlike','between','notbetween')},
+      'sub': {
+         'BaseClass'  : GCsub,
          'Description': 'Implements subtraction.',
-         'ParentTags':  ('eq','ne','lt','le','gt','ge','add','sub','mul',
-                         'div','like','notlike','between','notbetween') },
-      'mul':       {
-         'BaseClass': GCmul,
+         'ParentTags' : ('eq','ne','lt','le','gt','ge','add','sub','mul',
+                         'div','like','notlike','between','notbetween')},
+      'mul': {
+         'BaseClass'  : GCmul,
          'Description': 'Implements multiplication.',
-         'ParentTags':  ('eq','ne','lt','le','gt','ge','add','sub','mul',
-                         'div','like','notlike','between','notbetween') },
-      'div':       {
-         'BaseClass': GCdiv,
+         'ParentTags' : ('eq','ne','lt','le','gt','ge','add','sub','mul',
+                         'div','like','notlike','between','notbetween')},
+      'div': {
+         'BaseClass'  : GCdiv,
          'Description': 'Implements division.',
-         'ParentTags':  ('eq','ne','lt','le','gt','ge','add','sub','mul',
-                         'div','like','notlike','between','notbetween') },
-      'and':       {
-         'BaseClass': GCand,
-         'Description': 'Implements logical AND relation.',
-         'ParentTags':  ('condition','and','or','not','negate') },
-      'or':       {
-         'BaseClass': GCor,
-         'Description': 'Implements logical OR relation.',
-         'ParentTags':  ('condition','and','or','not','negate') },
-      'not':       {
-         'BaseClass': GCnot,
-         'Description': 'Implements logical NOT relation.',
-         'ParentTags':  ('condition','and','or','not','negate') },
-      'negate':       {
-         'BaseClass': GCnegate,
+         'ParentTags' : ('eq','ne','lt','le','gt','ge','add','sub','mul',
+                         'div','like','notlike','between','notbetween')},
+      'negate': {
+         'BaseClass'  : GCnegate,
          'Description': 'Implements numerical negation.',
-         'ParentTags':  ('condition','and','or','not','negate') },
-      'eq':       {
-         'BaseClass': GCeq,
+         'ParentTags' : ('condition','and','or','not','negate')},
+      'eq': {
+         'BaseClass'  : GCeq,
          'Description': 'Implements a {field} = {value} condition.',
-         'ParentTags':  ('condition','and','or','not','negate') },
-      'ne':       {
-         'BaseClass': GCne,
+         'ParentTags' : ('condition','and','or','not','negate')},
+      'ne': {
+         'BaseClass'  : GCne,
          'Description': 'Implements a {field} <> {value} condition.',
-         'ParentTags':  ('condition','and','or','not','negate') },
-      'gt':       {
-         'BaseClass': GCgt,
+         'ParentTags' : ('condition','and','or','not','negate')},
+      'gt': {
+         'BaseClass'  : GCgt,
          'Description': 'Implements a {field} > {value} condition.',
-         'ParentTags':  ('condition','and','or','not','negate') },
-      'ge':       {
-         'BaseClass': GCge,
+         'ParentTags' : ('condition','and','or','not','negate')},
+      'ge': {
+         'BaseClass'  : GCge,
          'Description': 'Implements a {field} >= {value} condition.',
-         'ParentTags':  ('condition','and','or','not','negate') },
-      'lt':       {
-         'BaseClass': GClt,
+         'ParentTags' : ('condition','and','or','not','negate')},
+      'lt': {
+         'BaseClass'  : GClt,
          'Description': 'Implements a {field} < {value} condition.',
-         'ParentTags':  ('condition','and','or','not','negate') },
-      'le':       {
-         'BaseClass': GCle,
+         'ParentTags' : ('condition','and','or','not','negate')},
+      'le': {
+         'BaseClass'  : GCle,
          'Description': 'Implements a {field} <= {value} condition.',
-         'ParentTags':  ('condition','and','or','not','negate') },
-      'like':       {
-         'BaseClass': GClike,
+         'ParentTags' :  ('condition','and','or','not','negate')},
+      'like': {
+         'BaseClass'  : GClike,
          'Description': 'Implements a {field} LIKE {value} condition.',
-         'ParentTags':  ('condition','and','or','not','negate') },
-      'notlike':       {
-         'BaseClass': GCnotlike,
+         'ParentTags' : ('condition','and','or','not','negate')},
+      'notlike': {
+         'BaseClass'  : GCnotlike,
          'Description': 'Implements a {field} NOT LIKE {value} condition.',
-         'ParentTags':  ('condition','and','or','not','negate') },
-      'between':       {
-         'BaseClass': GCbetween,
+         'ParentTags' : ('condition','and','or','not','negate')},
+      'between': {
+         'BaseClass'  : GCbetween,
          'Description': 'Implements a {field} BETWEEN {value1} {value2} '
                         'condition.',
-         'ParentTags':  ('condition','and','or','not','negate') },
-      'notbetween':       {
-         'BaseClass': GCnotbetween,
+         'ParentTags' : ('condition','and','or','not','negate')},
+      'notbetween': {
+         'BaseClass'  : GCnotbetween,
          'Description': 'Implements a {field} NOT BETWEEN {value1} {value2} '
                         'condition.',
-         'ParentTags':  ('condition','and','or','not','negate') },
-      'null':      {
-         'BaseClass': GCnull,
+         'ParentTags' : ('condition','and','or','not','negate')},
+      'null': {
+         'BaseClass'  : GCnull,
          'Description': 'Implements a {field} IS NULL condition.',
-         'ParentTags': ('condition','and','or','not') },
-      'notnull':      {
-         'BaseClass': GCnotnull,
+         'ParentTags' : ('condition','and','or','not')},
+      'notnull': {
+         'BaseClass'  : GCnotnull,
          'Description': 'Implements a {field} IS NOT NULL condition.',
-         'ParentTags': ('condition','and','or','not') },
-      'upper':       {
-         'BaseClass': GCupper,
+         'ParentTags' : ('condition','and','or','not')},
+      'upper': {
+         'BaseClass'  : GCupper,
          'Description': 'Implements upper({value}).',
-         'ParentTags':  ('eq','ne','lt','le','gt','ge',
-                         'like','notlike','between','notbetween') },
-      'lower':       {
-         'BaseClass': GClower,
+         'ParentTags' : ('eq','ne','lt','le','gt','ge',
+                         'like','notlike','between','notbetween')},
+      'lower': {
+         'BaseClass'  : GClower,
          'Description': 'Implements lower({value}).',
-         'ParentTags':  ('eq','ne','lt','le','gt','ge',
-                         'like','notlike','between','notbetween') },
+         'ParentTags' : ('eq','ne','lt','le','gt','ge',
+                         'like','notlike','between','notbetween')},
       'exist': {
-         'BaseClass': GCexist,
+         'BaseClass'  : GCexist,
          'Description': 'Implements an exist condition.',
-         'Attributes': {
-            'table': {
-               'Required': True,
-               'Description': 'TODO',
-               'Typecast': GTypecast.name },
-            'masterlink': {
-               'Required': True,
-               'Description': 'TODO',
-               'Typecast': GTypecast.text},
-            'detaillink': {
-               'Required': True,
-               'Description': 'TODO',
-               'Typecast': GTypecast.text}},
-         'ParentTags':  ('eq','ne','lt','le','gt','ge',
-                         'like','notlike','between','notbetween') },
-      }
+         'Attributes' : {'table'     : {'Required': True,
+                                        'Typecast': GTypecast.name},
+                         'masterlink': {'Required': True,
+                                        'Typecast': GTypecast.text},
+                         'detaillink': {'Required': True,
+                                        'Typecast': GTypecast.text}},
+         'ParentTags' : ('eq','ne','lt','le','gt','ge',
+                         'like','notlike','between','notbetween')}}
 
-  for alteration in updates.keys():
-    xmlElements[alteration].update(updates[alteration])
+  for alteration in updates.keys ():
+    xmlElements [alteration].update (updates [alteration])
 
   return xmlElements
 
 
+# =============================================================================
+# Convenience methods
+# =============================================================================
 
-###############################################################################
-###############################################################################
-####                        Convenience Methods                              ##
-###############################################################################
-###############################################################################
-
-
 # -----------------------------------------------------------------------------
 # Create a condition tree either from a prefix list or a dictionary
 # -----------------------------------------------------------------------------
@@ -1400,9 +1495,9 @@
   return GCondition (prefixList = prefixList)
 
 
-# =============================================================================
+# -----------------------------------------------------------------------------
 # Create a condition tree from a dictionary
-# =============================================================================
+# -----------------------------------------------------------------------------
 
 def buildConditionFromDict (dictionary, comparison = GCeq, logic = GCand):
   """
@@ -1429,9 +1524,9 @@
   return GCondition (prefixList = pList)
 
 
-# =============================================================================
+# -----------------------------------------------------------------------------
 # Combine two conditions with an AND clause
-# =============================================================================
+# -----------------------------------------------------------------------------
 
 def combineConditions (cond1, cond2):
   """
@@ -1471,9 +1566,9 @@
   return buildCondition (ncond)
 
 
-# =============================================================================
+# -----------------------------------------------------------------------------
 # Unify all elements in values to the same type
-# =============================================================================
+# -----------------------------------------------------------------------------
 
 def unify (values):
   """
@@ -1483,22 +1578,17 @@
   @return: sequence of converted items having all the same datatype.
   """
 
+  checktype (values, list)
+
   result = []
   __unify (values, result)
 
   return result
 
+# -----------------------------------------------------------------------------
 
-# -----------------------------------------------------------------------------
-# Actual working method for unification
-# -----------------------------------------------------------------------------
 def __unify (values, result):
-  """
-  This function does the dirty work of 'unify ()'.
-  """
 
-  checktype (values, list)
-
   if not len (values):
     return
 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]