How to use the lucidity.error.FormatError function in Lucidity

To help you get started, we’ve selected a few Lucidity examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github 4degrees / lucidity / test / unit / test_template.py View on Github external
def test_format_failure(pattern, data):
    '''Format incomplete data against pattern.'''
    template = Template('test', pattern)
    with pytest.raises(FormatError):
        template.format(data)
github 4degrees / lucidity / source / lucidity / template.py View on Github external
def _format(match):
            '''Return value from data for *match*.'''
            placeholder = match.group(1)
            parts = placeholder.split('.')

            try:
                value = data
                for part in parts:
                    value = value[part]

            except (TypeError, KeyError):
                raise lucidity.error.FormatError(
                    'Could not format data {0!r} due to missing key {1!r}.'
                    .format(data, placeholder)
                )

            else:
                return value