MiscUtils.NamedValueAccess | index /usr/local/share/webware/MiscUtils/NamedValueAccess.py

`NamedValueAccess.py
NamedValueAccess provides functions for accessing Python objects by keys and
named attributes. A 'key' is a single identifier such as 'foo'. A 'name' could
be a key, or a qualified key, such as 'foo.bar.boo'. Names are generally more
convenient and powerful, while the key-oriented function is more efficient and
provide the atomic functionality that the name-oriented function is built upon.
CREDIT
Chuck Esterbrook <echuck@mindspring.com>
Tavis Rudd <tavis@calrudd.com>`

Classes

``

exceptions.LookupError(exceptions.StandardError)
  NamedValueAccessError
    ValueForKeyError

class NamedValueAccessError(exceptions.LookupError)
`` | `General named value access error.`

Method resolution order:
  NamedValueAccessError
  exceptions.LookupError
  exceptions.StandardError
  exceptions.Exception
  exceptions.BaseException
  __builtin__.object

Data descriptors defined here:

__weakref__
  `list of weak references to the object (if defined)`

Methods inherited from exceptions.LookupError:

__init__(...)
  `x.__init__(...) initializes x; see help(type(x)) for signature`

Data and other attributes inherited from exceptions.LookupError:

__new__ = <built-in method __new__ of type object>
  `T.__new__(S, ...) -> a new object with type S, a subtype of T`

Methods inherited from exceptions.BaseException:

__delattr__(...)
  `x.__delattr__('name') <==> del x.name`

__getattribute__(...)
  `x.__getattribute__('name') <==> x.name`

__getitem__(...)
  `x.__getitem__(y) <==> x[y]`

__getslice__(...)
  `x.__getslice__(i, j) <==> x[i:j]
  Use of negative indices is not supported.`

__reduce__(...)

__repr__(...)
  `x.__repr__() <==> repr(x)`

__setattr__(...)
  `x.__setattr__('name', value) <==> x.name = value`

__setstate__(...)

__str__(...)
  `x.__str__() <==> str(x)`

__unicode__(...)

Data descriptors inherited from exceptions.BaseException:

__dict__

args

message

class ValueForKeyError(NamedValueAccessError)
`` | `No value for key found error.`

Method resolution order:
  ValueForKeyError
  NamedValueAccessError
  exceptions.LookupError
  exceptions.StandardError
  exceptions.Exception
  exceptions.BaseException
  __builtin__.object

Data descriptors inherited from NamedValueAccessError:

__weakref__
  `list of weak references to the object (if defined)`

Methods inherited from exceptions.LookupError:

__init__(...)
  `x.__init__(...) initializes x; see help(type(x)) for signature`

Data and other attributes inherited from exceptions.LookupError:

__new__ = <built-in method __new__ of type object>
  `T.__new__(S, ...) -> a new object with type S, a subtype of T`

Methods inherited from exceptions.BaseException:

__delattr__(...)
  `x.__delattr__('name') <==> del x.name`

__getattribute__(...)
  `x.__getattribute__('name') <==> x.name`

__getitem__(...)
  `x.__getitem__(y) <==> x[y]`

__getslice__(...)
  `x.__getslice__(i, j) <==> x[i:j]
  Use of negative indices is not supported.`

__reduce__(...)

__repr__(...)
  `x.__repr__() <==> repr(x)`

__setattr__(...)
  `x.__setattr__('name', value) <==> x.name = value`

__setstate__(...)

__str__(...)
  `x.__str__() <==> str(x)`

__unicode__(...)

Data descriptors inherited from exceptions.BaseException:

__dict__

args

message

Functions

``

valueForKey(obj, key, default=<class 'MiscUtils.NoDefault'>)
  `Get the value of the object named by the given key.
  This method returns the value with the following precedence:
  1. Methods before non-methods
  2. Attributes before keys (__getitem__)
  3. Public things before private things
  (private being denoted by a preceding underscore)
  Suppose key is 'foo', then this method returns one of these:
  * obj.foo()
  * obj._foo()
  * obj.foo
  * obj._foo
  * obj['foo']
  * default # only if specified
  If all of these fail, a ValueForKeyError is raised.
  NOTES
  * valueForKey() works on dictionaries and dictionary-like objects.
  * See valueForName() which is a more advanced version of this
  function that allows multiple, qualified keys.`

valueForName(obj, name, default=<class 'MiscUtils.NoDefault'>)
  `Get the value of the object that is named.
  The name can use dotted notation to traverse through a network/graph
  of objects. Since this function relies on valueForKey() for each
  individual component of the name, you should be familiar with the
  semantics of that notation.
  Example: valueForName(obj, 'department.manager.salary')`