libtbx.object_oriented_patterns
index
/net/chevy/raid1/nat/src/cctbx_project/libtbx/object_oriented_patterns.py

A library of object-oriented patterns

 
Modules
       
new
weakref

 
Classes
       
__builtin__.object
injector
journal_mixin
lazy_initialization
memoize
memoize_method
null
proxy

 
class injector(__builtin__.object)
    Injection of new methods into an existing class
 
* synopsis *
 
class some_descriptive_text(injector, some_existing_class,
                                      another_existing_class, ...):
 
  def new_method(self, ...): ...
 
  def another_new_method(self, ...): ...
 
obj = some_existing_class(...)
obj.new_method(...)
obj = another_existing_class(...)
obj.new_method(...)
# class 'some_descriptive_text' is an empty shell with no use by itself.
 
* motivation *
 
The traditional way to add methods to an existing class involves typing
three times the same information:
 
def new_method(self, ...): ...
existing_class.new_method = new_method
 
or to defer the naming to after the definition:
 
def foo(self, ...): ...
existing_class.new_method = foo
 
A bit of metaclass trickery results in a cleaner syntax.
 
  Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

Data and other attributes defined here:
__metaclass__ = <class 'libtbx.object_oriented_patterns.__metaclass__'>

 
class journal_mixin(__builtin__.object)
    An easy way to store the history of an attribute as it changes
through the course of a routine.
 
  Methods defined here:
__delattr__(self, name)
__getattr__(self, name)
__setattr__(self, name, value)

Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

Data and other attributes defined here:
__journal__ = []
__journal_suffix__ = '_history'

 
class lazy_initialization(__builtin__.object)
    Defers initialization until the value is accessed (state pattern)
 
  Methods defined here:
__call__(self)
__init__(self, calculation)

Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
class memoize(__builtin__.object)
    Memoize the result returned by a function
 
  Methods defined here:
__call__(self, *args)
__init__(self, func)

Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
class memoize_method(__builtin__.object)
    Memoize the result returned by a bound method.
This is to be used with immutable objects only.
 
  Methods defined here:
__get__(self, obj, type=None)
__init__(self, meth)

Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
class null(__builtin__.object)
     Methods defined here:
__call__(self, *args, **kwds)
__delattr__(self, a)
__delitem__(self, i)
__getattr__(self, a)
__getitem__(self, i)
__init__(self, *args, **kwds)
__nonzero__(self)
__repr__(self)
__setattr__(self, a, v)
__setitem__(self, i, v)

Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
class proxy(__builtin__.object)
     Methods defined here:
__getattr__(self, attr)
__init__(self, subject)

Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
Functions
       
calculate_state(holder)
retrieve_state(holder)

 
Data
        division = _Feature((2, 2, 0, 'alpha', 2), (3, 0, 0, 'alpha', 0), 8192)