Package turbogears :: Module util
[hide private]

Module util

source code

The TurboGears utility module.

Classes [hide private]
  Bunch
Simple but handy collector of a bunch of named stuff.
  DictObj
  DictWrapper
  setlike
Set preserving item order.
Functions [hide private]
 
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
 
get_project_meta(name)
Get egg-info file with that name in the current project.
source code
 
get_project_config()
Try to select appropriate project configuration file.
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_project_name() 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
 
inject_call(func, injections, *args, **kw)
Insert arguments and call.
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) 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
 
fixentities(htmltext)
Replace HTML character entities with numerical references.
source code
Variables [hide private]
  _safe_for_cookie = '\x00\x01\x02\x03\x04\x05\x06\x07\x08\x0e\x...
Function Details [hide private]

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)

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))

fixentities(htmltext)

source code 

Replace HTML character entities with numerical references.

Note: This won't handle CDATA sections properly.


Variables Details [hide private]

_safe_for_cookie

Value:
'\x00\x01\x02\x03\x04\x05\x06\x07\x08\x0e\x0f\x10\x11\x12\x13\x14\x15\\
x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f!"#%&\'()*+:<=>?@[\\]^`{|}~\x7f\
\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x\
91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\
\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\x\
b4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5\
\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\x\
d7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\
...