Source code for clik.util

# -*- coding: utf-8 -*-
"""
The ever-present utilities module.

:author: Joe Joyce <joe@decafjoe.com>
:copyright: Copyright (c) Joe Joyce and contributors, 2009-2019.
:license: BSD
"""


[docs]class AttributeDict(dict): """ Simple :class:`dict` wrapper that allows key access via attribute. Example:: d = AttributeDict(foo='bar', baz='qux') d['foo'] # 'bar' d.foo # 'bar' d['baz'] # 'qux' d.baz # 'qux' d.foo = 'bup' d['foo'] # 'bup' d.foo # 'bup' del d.foo d.foo # KeyError """
[docs] def __getattr__(self, name): """Get via attribute name.""" return self[name]
[docs] def __setattr__(self, name, value): """Set via attribute name.""" self[name] = value
[docs] def __delattr__(self, name): """Delete via attribute name.""" del self[name]