KeyValueCoding.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 » KeyValueCoding.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.
#-----------------------------------------------------------------------------


"""
KeyValueCoding  API


  CVS information

    $Id: KeyValueCoding.py 932 2004-07-20 06:21:57Z sbigaret $
  
"""

__version__='$Revision: 932 $'[11:-2]

try:
  from Interface import Base
except:
  class Base:
    pass

def valueForKeyPath(object, keypath):
  """
  order: setKey(), _setKey(), key, _key
  Might be overriden to perform additional transformations before
  returning the object
  If parameter 'object' is a list or a tuple (either at the first call or
  during the traversal of the keypath), 'valueForKeyPath' is applied to each
  item of the list.
  """

def takeValueForKeyPath(object, value, keypath):
  """
  order: setKey(), _setKey(), key, _key
  Might be overriden to perform additional transformations before
  returning the object
  If, during traversal of keypath, a sequence is met, the method raises
  'ValueError'.
  """

class KeyValueCodingInterface(Base):
  """
  Mix-in class providing a common API to access or assign values to
  object's properties.

  It defined three kinds of methods:

  - the so-called "public" methods: 'valueForKey()' and 'takeValueForKey()',
    which search for getters/setters before looking at attributes.

  - the so-called "private" methods: 'storedValueForKey()' and
    'takeStoredValueForKey()', which search getters or setters in a different
    way (see their docstrings dor details). These methods are mainly used
    within the framework when the data stream goes from some database to the
    real objects (bottom-up stream)

  - error handling methods: 'handleQueryWithUnboundKey()' and
    'handleAssignementForUnboundKey()'.

  """
  def valueForKey(self, key):
    """
    order: getKey(), key(), _getKey(), _key(), key, _key
    Might be overriden to perform additional transformations before
    returning the object
    """
    
  def takeValueForKey(self, value, key):
    """
    order: setKey(), _setKey(), key, _key
    Might be overriden to perform additional transformations before
    returning the object

    Might call 'handleTakeValueForUnboundKey()'...
    """

  def takeValueForKeyPath(self, value, key):
    "-"
    return takeValueForKeyPath(self, value, key)

  def storedValueForKey(self, key):
    """
    order: _getKey(), _key(), key, _key, getKey(), key()
    Might be overriden to perform additional transformations before
    returning the object
    """

  def takeStoredValueForKey(self, value, key):
    """
    order: _setKey(), _key, key, setKey()
    Might be overriden to perform additional transformations before
    returning the object

    Might call 'handleTakeStoredValueForUnboundKey()'...
    """
    
  def handleQueryWithUnboundKey(self, key):
    """
    Raises AttributeError. Override this method if you want to make any
    appropriate processing when an key is not found ; overriding methods
    should 'raise AttributeError, key' if the custom process of getting the
    value for the specified key fails.
    """
    
  def handleTakeValueForUnboundKey(self, value, key):
    """
    Raises AttributeError. Override this method if you want to make any
    appropriate processing when an key appears not to be settable using
    'takeValueForKey()'; overriding methods should 'raise AttributeError, key'
    if the custom process of setting value for the specified key fails.
    """

  def handleTakeStoredValueForUnboundKey(self, value, key):
    """
    Raises AttributeError. Override this method if you want to make any
    appropriate processing when an key appears not to be settable using
    'takeStoredValueForKey()'; overriding methods should 'raise
    AttributeError, key' if the custom process of setting value for the
    specified key fails.
    """

  # KVC extension
  def takeStoredValuesFromDictionary(self, dictionary):
    """
    Invokes takeStoredValueForKey() for each key, value in the dictionary.

    Example::

      object.takeStoredValueForKey({'attr1': 'value1','attr2': 'value2'})
    
    """
    self.takeStoredValueForKey(dictionary[key], key)
      
  def takeValuesFromDictionary(self, dictionary):
    """
    Invokes takeValueForKey() for each key, value in the dictionary.

    Example::

      object.takeValueForKey({'attr1': 'value1','attr2': 'value2'})
    
    """

  def valuesForKeys(self, keys):
    """
    Returns the list of values assigned to attributes specified in keys. This
    method uses valueForKey()

    Example::

      >>> [o.valuesForKeys(('firstName', 'lastName'))
      ...  for o in ec.fetch('Employee', isDeep=1)]
      [['Jeanne', 'Cleese'], ['John Jr.', 'Cleese'], ['John', 'Cleese']]

    """

  ## DEPRECATED alias
  def setValueForKey(self, value, key):
    "DEPERECATED  -- An alias for 'takeValueForKey()'"

  def setValueForKeyPath(self, value, keypath):
    "DEPERECATED  -- An alias for 'takeValueForKey()'"

  def setStoredValueForKey(self, value, key):
    "DEPERECATED -- An alias for 'takeStoredValueForKey()'"

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.