Package Modeling :: Module utils
[show private | hide private]
[frames | no frames]

Module Modeling.utils

Some useful functions to be used within the Modeling package, or by tools using this framework.

The module also defines two classes:

$Id: utils.py 980 2006-02-26 18:04:47Z sbigaret $


Function Summary
  cache_simple_methods(anInstance, exclude)
Takes an instance object and caches the result for all simple methods, i.e.
  capitalizeFirstLetter(aName)
Return the same string with the first letter capitalized
  deprecated(methodName, replacement, removed_in_version)
  eliminate_multiple_occurences(sequence, func)
Eliminates multiple occurences of items in 'sequence' and returns the corresponding list.
  finalize_docstrings(klass, aDict)
Takes a class object and tries to update its docstring, as well as its methods' docstrings, using the supplied dictionary.
  getModule(name, path)
Finds and load the module 'name'.
  isaValidName(aName)
Checks
  isListOrTuple(anObject)
Returns true if 'anObject' is a sequence-like object, false otherwise
  lower(aString)
Return the same string w/ all letter lower
  methods_to_cache(aClass, exclude)
Searches and returns within 'aClass' the methods that accepts no arguments except 'self'.
  migration_warnings()
This method is responsible for warning the user when we detect that he/she is relying on a feature (e.g.
  stringToPythonIdentifier(aString)
Transforms a string to a valid python identifier, i.e.
  toBoolean(param)
If param is a string (or unicode) and equals to 0, returns 0 ; otherwise returns 'not not param'.

Function Details

cache_simple_methods(anInstance, exclude=None)

Takes an instance object and caches the result for all simple methods, i.e. methods that takes no arguments except 'self'. The caching is made by substituting the method with a lambda returning the value the original method returned.

This method does nothing under python v2.1 if ZODB is found in the path, because it is incompatible with the extension class, used by classes Entity, Relationship, etc.

Parameters:

anInstance -- the instance to examine

exclude -- a sequence of methods' names not to cache

See also: methods_to_cache()

capitalizeFirstLetter(aName)

Return the same string with the first letter capitalized

eliminate_multiple_occurences(sequence, func=<function <lambda> at 0xb791a10c>)

Eliminates multiple occurences of items in 'sequence' and returns the corresponding list. The returned list is a subset of the supplied sequence, and the original order of items is preserved (if an item is present more than once in 'sequence', only the first occurence is present in the returned list).

Parameters:

sequence -- a sequence (list, tuple). The original sequence is left
untouched.
func -- optional parameter. Defaults to the identity function. You can
supply an other function to eliminate from the sequences all objects but one whose 'func(object)' are equal.

finalize_docstrings(klass, aDict)

Takes a class object and tries to update its docstring, as well as its methods' docstrings, using the supplied dictionary.

This is used, for example, in Entity, where some docstrings contains '%(key)s' statements, to be filled with the same thing ; this makes it possible to update groups of methods / 'see also' paragraphs without having to copy/paste things everywhere.

Parameters:

klass -- the class object whose docstrings should be updated

aDict -- the dictionary to use to update the docstrings.

getModule(name, path=None)

Finds and load the module 'name'. This is used by method 'classForEntity()'. Raises in case it cannot be found

See also: module 'imp', functions 'find_module()' and 'load_module()'

isaValidName(aName)

Checks

isListOrTuple(anObject)

Returns true if 'anObject' is a sequence-like object, false otherwise

In this context, a sequence-like object is a tuple, a list, or an instance of Modeling.FaultHandler.AccessArrayFaultHandler

lower(aString)

Return the same string w/ all letter lower

methods_to_cache(aClass, exclude=None)

Searches and returns within 'aClass' the methods that accepts no arguments except 'self'.

Parameters:

aClass -- the class to examine

exclude -- a sequence of methods' names to exclude from the result set

migration_warnings()

This method is responsible for warning the user when we detect that he/she is relying on a feature (e.g. an environment variable) that has been deprecated/removed and as no effect anymore (or will have no effect anymore in a near future).

stringToPythonIdentifier(aString)

Transforms a string to a valid python identifier, i.e. replaces all spaces with underscores and drops all chars not in (strings.)letters+digits+'_'

toBoolean(param)

If param is a string (or unicode) and equals to 0, returns 0 ; otherwise returns 'not not param'.

Generated by Epydoc 2.1 on Sat Mar 4 13:36:24 2006 http://epydoc.sf.net