view env/lib/python3.7/site-packages/galaxy/util/bunch.py @ 2:6af9afd405e9 draft

"planemo upload commit 0a63dd5f4d38a1f6944587f52a8cd79874177fc1"
author shellac
date Thu, 14 May 2020 14:56:58 -0400
parents 26e78fe6e8c4
children
line wrap: on
line source

class Bunch(object):
    """
    http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52308

    Often we want to just collect a bunch of stuff together, naming each item of
    the bunch; a dictionary's OK for that, but a small do-nothing class is even handier, and prettier to use.
    """

    def __init__(self, **kwds):
        self.__dict__.update(kwds)

    def dict(self):
        return self.__dict__

    def get(self, key, default=None):
        return self.__dict__.get(key, default)

    def __iter__(self):
        return iter(self.__dict__)

    def items(self):
        return self.__dict__.items()

    def keys(self):
        return self.__dict__.keys()

    def values(self):
        return self.__dict__.values()

    def __str__(self):
        return '%s' % self.__dict__

    def __bool__(self):
        return bool(self.__dict__)
    __nonzero__ = __bool__

    def __setitem__(self, k, v):
        self.__dict__.__setitem__(k, v)

    def __contains__(self, item):
        return item in self.__dict__