hapis API

Module hapis.settings

Contains helper functions useful for processing settings. These should be used during Pyramid application configuration e.g. in an includeme function.

hapis.settings.filter_by_prefix(adict, prefix)

Returns a new dictionary based on adict with keys that start with prefix. Also removes that prefix from keys.

Warning

The function assumes that all keys in adict are strings.

hapis.settings.parse_keyvalue_pairs(config, setting, dotted=True)

If setting is a string, split it on newlines, then split each line on the first occurence of ‘=’ symbol and strip both parts of whitespace. Then create a dictionary out of those pairs. If setting is not a string leave it unchanged.

If the optional argument dotted is True, also try to resolve each value in the resulting dictionary as a dotted Python name. If it is not a string, leave it without attempting to do any name resolution. If it is a relative dotted name, consider it relative to the package argument supplied to config’s constructor.

config should be a configurator for the current pyramid application.

hapis.settings.parse_multiline(config, lines, dotted=True)

If lines is a string, split it on newlines, else leave it unchanged.

If the optional argument dotted is True, also try to resolve each value in the resulting dictionary as a dotted Python name. If it is not a string, leave it without attempting to do any name resolution. If it is a relative dotted name, consider it relative to the package argument supplied to config’s constructor.

config should be a configurator for the current pyramid application.

hapis.settings.split_keys(adict, separator='.', maxsplit=None)

This function is best explained by an example:

d['some.very.long.key'] = 'value'
split_keys(d)['some']['very']['long']['key']  # 'value'

It splits all keys in adict by separator, then for each part of the split key but the last it inserts an inner dictionary into the result.

Warning

The function assumes that all keys in adict are strings.

If maxsplit is passed, then keys would be split at most maxsplit times.

Note

If maxsplit is N then the keys would be split on at most N+1 parts.

Table Of Contents

Previous topic

Glossary