deliverance.util – miscellaneous functions



Converters for boolean and HTML


Converts a string to a boolean

This converts the values “true”, “t”, “yes”, “y”, “on”, and “1” into true, and “false”, “f”, “no”, “n”, “off” and “0” into false. Non-string values are left alone. Other strings are errors.


HTML quotes the string


Converts filenames to file: URLs and back again


Convert a path to a file: URL. The path will be made absolute.


Convert a file: URL to a path.


‘imports’ a string – converts a string to a Python object, importing any necessary modules and evaluating the expression. Everything before the : in an import expression is the module path; everything after is an expression to be evaluated in the namespace of that module.

Alternately, if no : is present, then import the modules and get the attributes as necessary. Arbitrary expressions are not allowed in that case.


Import a module, or import an object from a module.

A module name like can be used, where is the module, and baz() is an expression evaluated in the context of that module. Note this is not safe on arbitrary strings because of the eval.


Import a module, or import an object from a module.

A name like can be a module or a module with an object baz in it, or a module foo with an object bar with an attribute baz.


Import a module.


Imports a module, but catches import errors. Only catches errors when that module doesn’t exist; if that module itself has an import error it will still get raised. Returns None if the module doesn’t exist.


Implements NestedDict

class deliverance.util.nesteddict.NestedDict(*dicts)

A dictionary that dispatches to one of its sub-dictionaries, returning whatever the value is for the first dictionary with the key.


A simple implementation of URI templates. Note: this is incomplete!

This only implements simple {var} substitution, not any of the other operations in the URI template (unfinished) spec.

deliverance.util.uritemplate.uri_template_substitute(uri_template, vars)

Does URI template substitution

This only substitutes simple {var}, none of the fancier substitution techniques.


Normalize URLs


Normalizes the quoting of URLs, quoting any characters that should be quoted (but not double-quoting already quoted characters)