milla.util¶
Convenience utility functions
Created: | Mar 30, 2011 |
---|---|
Author: | dustin |
- milla.util.asbool(val)¶
Test a value for truth
Returns False values evaluating as false, such as the integer 0 or None, and for the following strings, irrespective of letter case:
- false
- no
- f
- n
- off
- 0
Returns True for all other values.
- milla.util.http_date(date)¶
Format a datetime object as a string in RFC 1123 format
This function returns a string representing the date according to RFC 1123. The string returned will always be in English, as required by the specification.
Parameters: date – A datetime.datetime object Returns: RFC 1123-formatted string
- milla.util.read_config(filename, defaults=None)¶
Parse an ini file into a nested dictionary
Parameters: - filename (string) – Path to the ini file to read
- defaults (dict) – (Optional) A mapping of default values that can be used for interpolation when reading the configuration file
Returns: A dictionary whose keys correspond to the section and option, joined with a dot character (.)
For example, consider the following ini file:
[xmen] storm = Ororo Monroe cyclops = Scott Summers [avengers] hulk = Bruce Banner iron_man = Tony Stark
The resulting dictionary would look like this:
{ 'xmen.storm': 'Ororo Monroe', 'xmen.cyclops': 'Scott Summers', 'avengers.hulk': 'Bruce Banner', 'avengers.iron_man': 'Tony Stark', }
Thus, the option values for any section can be obtained as follows:
config['xmen.storm']
This dictionary can be used to configure an Application instance by using the update method:
config = milla.util.read_config('superheros.ini') app = milla.Application(router) app.config.update(config)