Package turbogears :: Module util

Module util

source code

The TurboGears utility module.

Classes
  Bunch
Simple but handy collector of a bunch of named stuff.
  DictObj
  DictWrapper
  setlike
Set preserving item order.
Functions
 
deprecated(message=None)
Decorator which can be used to mark functions as deprecated.
source code
 
Enum(*names)
True immutable symbolic enumeration with qualified value access.
source code
 
load_project_config(configfile=None)
Try to update the project settings from the config file specified.
source code
 
get_package_name()
Try to find out the package name of the current directory.
source code
 
get_model() source code
 
ensure_sequence(obj)
Construct a sequence from object.
source code
 
to_kw(func, args, kw, start=0)
Convert all applicable arguments to keyword arguments.
source code
 
from_kw(func, args, kw, start=0)
Extract named positional arguments from keyword arguments.
source code
 
adapt_call(func, args, kw, start=0)
Remove excess arguments.
source code
 
call_on_stack(func_name, kw, start=0)
Check if a call to function matching pattern is on stack.
source code
 
remove_keys(dict_, seq)
Gracefully remove keys from dict.
source code
 
has_arg(func, argname)
Check whether function has argument.
source code
 
arg_index(func, argname)
Find index of argument as declared for given function.
source code
 
inject_arg(func, argname, argval, args, kw, start=0)
Insert argument into call.
source code
 
inject_args(func, injections, args, kw, start=0)
Insert arguments into call.
source code
 
add_tg_args(func, args)
Add hint for special arguments that shall not be removed.
source code
 
bind_args(**add)
Call with arguments set to a predefined value.
source code
 
recursive_update(to_dict, from_dict)
Recursively update all dicts in to_dict with values from from_dict.
source code
 
combine_contexts(frames=None, depth=None)
Combine contexts (globals, locals) of frames.
source code
 
request_available()
Check if cherrypy.request is available.
source code
 
flatten_sequence(seq)
Flatten sequence.
source code
 
load_class(dottedpath)
Load a class from a module in dotted-path notation.
source code
 
parse_http_accept_header(accept)
Parse an HTTP Accept header (RFC 2616) into a sorted list.
source code
 
simplify_http_accept_header(accept)
Parse an HTTP Accept header (RFC 2616) into a preferred value.
source code
 
to_unicode(value)
Convert encoded string to unicode string.
source code
 
to_utf8(value)
Convert a unicode string to utf-8 encoded plain string.
source code
 
quote_cookie(value)
Escape chars in value that should not be put directly in a cookie.
source code
 
unquote_cookie(value)
Unescape chars in a cookie value, the reverse of quote_cookie(value).
source code
 
get_template_encoding_default(engine_name=None)
Return default encoding for template files (Kid, Genshi, etc.).
source code
 
find_precision(value)
Find precision of some arbitrary value.
source code
 
copy_if_mutable(value, feedback=False) source code
Function Details

deprecated(message=None)

source code 

Decorator which can be used to mark functions as deprecated.

It will result in a warning being emmitted when the function is used.

Inspired by http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/391367

Enum(*names)

source code 

True immutable symbolic enumeration with qualified value access.

Written by Zoran Isailovski: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/413486

load_project_config(configfile=None)

source code 

Try to update the project settings from the config file specified.

If configfile is None, uses get_project_config to locate one.

load_class(dottedpath)

source code 

Load a class from a module in dotted-path notation.

E.g.: load_class("package.module.class").

Based on recipe 16.3 from Python Cookbook, 2ed., by Alex Martelli, Anna Martelli Ravenscroft, and David Ascher (O'Reilly Media, 2005)

parse_http_accept_header(accept)

source code 

Parse an HTTP Accept header (RFC 2616) into a sorted list.

The quality factors in the header determine the sort order. The values can include possible media-range parameters. This function can also be used for the Accept-Charset, Accept-Encoding and Accept-Language headers.

simplify_http_accept_header(accept)

source code 

Parse an HTTP Accept header (RFC 2616) into a preferred value.

The quality factors in the header determine the preference. Possible media-range parameters are allowed, but will be ignored. This function can also be used for the Accept-Charset, Accept-Encoding and Accept-Language headers.

This is similar to parse_http_accept_header(accept)[0], but faster.

to_unicode(value)

source code 

Convert encoded string to unicode string.

Uses get_template_encoding_default() to guess source string encoding. Handles turbogears.i18n.lazystring correctly.

to_utf8(value)

source code 

Convert a unicode string to utf-8 encoded plain string.

Handles turbogears.i18n.lazystring correctly.

Does nothing to already encoded string.

find_precision(value)

source code 

Find precision of some arbitrary value.

The main intention for this function is to use it together with turbogears.i18n.format.format_decimal() where one has to inform the precision wanted. So, use it like this:

format_decimal(some_number, find_precision(some_number))