An Utility module contains objects which is used by h10n internally. End users don’t need to use this module directly.
An Exception Context is utility object to store context in the exception arguments. The Exception Context is used via keep_context() decorator.
Extends existent context of exception or add new one
An utility base class for named objects, which is used in the exception context. See ExceptionContext doc-strings.
>>> no = NamedObject()
>>> no
<NamedObject: __empty__>
>>> no.name = 'test'
>>> no
<NamedObject: test>
Namespace is an utility object, which mimics to JavaScript object. The Namespace provides methods to manipulate attributes using subscription interface:
>>> ns = Namespace()
>>> ns.a = 1
>>> ns['a']
1
>>> ns['a'] = 2
>>> ns.a
2
>>> ns['b.c'] = 3
>>> ns.b.c
3
>>> ns.b
<h10n.util.Namespace object at ...>
Extends namespace by attributes from dictionary or another namespace. Dot-separated keys in the dictionary becomes to nested namespace.
>>> ns = Namespace().extend({'a.b': 1, 'c': 2})
>>> ns.a.b
1
>>> ns.c
2
>>> ns.a
<h10n.util.Namespace object at ...>
>>> ns_2 = Namespace().extend({'c': 3, 'd': 4, 'a.e': 5})
>>> ns.extend(ns_2)
<h10n.util.Namespace object at ...>
>>> ns.c
3
>>> ns.d
4
>>> ns.a.e
5
Freeze current attributes of namespace to prevent overriding via extend.
>>> ns = Namespace().extend({'a': 1})
>>> ns.freeze()
>>> ns.extend({'a': 2}).a
1
Includes context into exception raised from decorated method.
>>> class Test(NamedObject):
... def __init__(self, name):
... self.name = name
... @keep_context
... def test(self):
... raise Exception('Test exception')
>>> Test('foo').test()
Traceback (most recent call last):
...
Exception: ('Test exception', <ExceptionContext: [<Test: foo>]>)