Source code for wolframclient.utils.datastructures

# -*- coding: utf-8 -*-

from __future__ import absolute_import, print_function, unicode_literals

from collections import OrderedDict


[docs]class Association(OrderedDict): """ A :class:`~collections.OrderedDict` that serializes to an Association""" def __repr__(self): return dict.__repr__(self)
[docs]class Settings(dict): """ Dictionary subclass enabling attribute lookup/assignment of keys/values. For example:: >>> m = Settings({'foo': 'bar'}) >>> m.foo 'bar' >>> m.foo = 'not bar' >>> m['foo'] 'not bar' ``Settings`` objects also provide ``.first()`` which acts like ``.get()`` but accepts multiple keys as arguments, and returns the value of the first hit, e.g.:: >>> m = Settings({'foo': 'bar', 'biz': 'baz'}) >>> m.first('wrong', 'incorrect', 'foo', 'biz') 'bar' """ def __getattr__(self, key): try: return self[key] except KeyError: # to conform with __getattr__ spec raise AttributeError(key) def __setattr__(self, key, value): self[key] = value