Package orm2 :: Package util
[hide private]
[frames] | no frames]

Package util

source code

This module defines a number of miscellaneous helper functions and classes.

Submodules [hide private]

Classes [hide private]
  stupid_dict
This class implements the mapping (dict) interface.
  module_property
Property class the will return the module object of the module the owning class was loaded from.

Functions [hide private]
  python_import(name, globals, locals, fromlist)
Import a module.
  _my_import(name, g, l, from_list)
  import_with_new_modules(module_name, replacement_modules={})
This is a nifty function that allows your modules to inherit from each other maintaining upward compatibility with regard as (for instance) orm2 based data models.

Variables [hide private]
  _replacement_modules = {}

Function Details [hide private]

python_import(name, globals, locals, fromlist)

 
Import a module. The globals are only used to determine the context; they are not modified. The locals are currently unused. The fromlist should be a list of names to emulate ``from name import ...'', or an empty list to emulate ``import name''. When importing a module from a package, note that __import__('A.B', ...) returns package A when fromlist is empty, but its submodule B when fromlist is not empty.
Returns:
module

_my_import(name, g, l, from_list)

source code 
None

import_with_new_modules(module_name, replacement_modules={})

source code 

This is a nifty function that allows your modules to inherit from each other maintaining upward compatibility with regard as (for instance) orm2 based data models.

Example:
>>> import model2
>>> controllers1 = import_with_new_modules('mytest.sub.controllers1',
{'model1': model2})
>>> email = controllers1.make_email()
>>> print email.__module__
model2
The controllers1.py module was written for a datamodel stored in the model1.py module in the same package. So it imports it. Now, the function calls above will import controllers1 with model2 as its datamodel. Of course the new module must be a super set of the old for this to work. (In this example the email class has been extended by an attribute.)
Parameters:
  • module_name - The name of the module to import (including package name(s))
  • replacement_modules - A dictionary mapping module names (<b>as they are imported by the module references by module_name</b>) and the module object it is supposed to be replaces with.

Variables Details [hide private]

_replacement_modules

None
Value:
{}