wille.utils

utils - Utility methods

Deprecation warning: these utility methods and modules are provided only for convience of Wille development.

For copyright information and licensing, see LICENSE.txt

class wille.utils.DjangoJSONEncoder(skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, encoding='utf-8', default=None, use_decimal=False)

JSONEncoder subclass that knows how to encode date/time and decimal types.

class wille.utils.Reloader

Checks to see if any loaded modules have changed on disk and, if so, reloads them.

Function has been taken from web.py <http://webpy.org> version 0.33 by Anand Chitipothu, made available under Public domain. Modifications have been made for Wille.

class wille.utils.TempCopyFolder(source, debug=False)

Creates a temporary copy from specified folder that is deleted automatically on garbage-collection

wille.utils.fileshare_read_file_safe(shared_path, filename)

Safe way for reading and returning given file Parameters: shared_dir - Directory from which file is served filename - Filename under the given directory

wille.utils.metadata_to_http_headers(metadata)

Send headers based on given metadata

wille.utils.random_string(length)

Generate random string (from letters) of given length

wille.utils.register_python_module(root_dir, module_dir)

Utility function for registering given location as a python module.

Returns: True if new module was added
False if module was already registered and
doesn’t need to be readded

wille.utils.template

template - Light-weight template engine

wille.utils.template.render(template_filename, vars={}, file_encoding='utf-8', template_dir=None)

Simple templatefile renderer, supporting ${xyz} style variables

Returns: rendered template as unicode() object

wille.utils.template.render_str(data, vars=None, vars_encoding='utf-8')
Render string template using given set of variables:

data - Template string vars - Dictionary of variables with they content vars_encoding - Default encoding for plaintext variables

(enforced if template is in unicode format)

Rendering in cases of 0-2 vars:

>>> from template import render_str
>>> render_str('Hello World!')
'Hello World!'
>>> render_str('Hello ${world}!', {'world': 'World'})
'Hello World!'
>>> render_str('${hello} ${world}!', {'hello': 'Hello', 'world': 'World'})
'Hello World!'
>>> render_str(u'1234\u1234\n').encode('utf-8')
'1234\u1234\n'

# (Note that above we have escaped all backslashes to make code work # in doctest)

Table Of Contents

Previous topic

wille.memorystore

This Page