Validation.py :  » Database » Modeling-Framework » Modeling-0.9 » Modeling » interfaces » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Database » Modeling Framework 
Modeling Framework » Modeling 0.9 » Modeling » interfaces » Validation.py
# -*- 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"
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.