# -*- 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.
#-----------------------------------------------------------------------------
"""
Validation API
CVS information
$Id: Validation.py 932 2004-07-20 06:21:57Z sbigaret $
"""
__version__='$Revision: 932 $'[11:-2]
try:
from Interface import Base
except:
class Base:
pass
# module constants
REQUIRED="Key is required but value is void"
TYPE_MISMATCH="Wrong type"
CUSTOM_KEY_VALIDATION="Custom validation of key failed"
CUSTOM_OBJECT_VALIDATION="Custom validation of object as a whole failed"
LOWER_BOUND="Lower bound of key's multiplicity constraint not fulfilled"
UPPER_BOUND="Upper bound of key's multiplicity constraint not fulfilled"
OBJECT_WIDE="Validation of object %s as a whole failed"
DELETE_DENY_KEY="Key has rule 'DELETE_DENY' but object still holds object(s)"
OBJECT_WIDE_KEY='OBJECT_WIDE_VALIDATION'
MODEL_ERROR="SERIOUS: A related object is NOT under model control"
class ValidationExceptionInterface(Base):
"""
Raised by validation methods 'validateValue()' on 'Entity', 'Attributes' and
'Relationships' when they fail
Inherits from: 'Exception'.
"""
def __init__(self, aKey=None, anErrorType=''):
"Initializes the exception, possibly with supplied errorType and key"
def aggregateError(self, anErrorType, aKey):
"""
Adds the supplied error type in the exception's dictionary, using the
provided key
"""
addErrorForKey=aggregateError
def aggregateErrors(self, listOfErrorTypes, aKey):
"""
Adds the supplied errors types in the exception's dictionary, using the
provided key
"""
addErrorsForKey=aggregateErrors
def aggregateException(self, aValidationError):
"""
Concatenates the supplied Validation.ValidationException to the current
one. For convenience, parameter can be either a
Validation.ValidationException object, or a dictionary as provided by
Validation.ValidationException errorsDict.
"""
def errorKeys(self):
"Returns keys for exception's dictionary"
def errorsDict(self):
"Returns the error dictionary"
def keysForErrorType(self, anErrorType):
"Returns the keys for which that error was aggregated"
def __str__(self):
"Returns a string representation of the exception"
def __call__(self):
"Returns the receiver's dictionary"
def finalize(self):
"""
Finalize a validation process. If the exception has a non-empty errorsDict
it raises, otherwise simply return
"""
def args(self):
"-"
class ValidationInterface(Base):
"""
Mix-in class for validation
Implemented by: XXX
"""
def validateForDelete(self):
"""
Only checks for now that no relationship tagged with 'DENY' still holds
objects
"""
def validateForInsert(self):
"Simply calls validateForSave for now"
def validateForUpdate(self):
"Simply calls validateForSave for now"
def validateForSave(self):
"""
Validates the whole object
+ calls subclass' validate<attribute/relationshipName>() method if
available.
"""
def validateObject(self):
"Kept for backward compatibility ; should simply call 'validateForSave()'"
def validateValueForKey(self, aValue, aKey):
"Validate the value hold by 'aKey' attribute/relationship in the object"
|