Convenience utility functions
Created: | Mar 30, 2011 |
---|---|
Author: | dustin |
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:
Returns True for all other values.
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 |
Parse an ini file into a nested dictionary
Parameters: |
|
---|---|
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)