addon-sdk/source/python-lib/cuddlefish/bunch.py

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 # This Source Code Form is subject to the terms of the Mozilla Public
     2 # License, v. 2.0. If a copy of the MPL was not distributed with this
     3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
     5 # Taken from Paver's paver.options module.
     7 class Bunch(dict):
     8     """A dictionary that provides attribute-style access."""
    10     def __repr__(self):
    11         keys = self.keys()
    12         keys.sort()
    13         args = ', '.join(['%s=%r' % (key, self[key]) for key in keys])
    14         return '%s(%s)' % (self.__class__.__name__, args)
    16     def __getitem__(self, key):
    17         item = dict.__getitem__(self, key)
    18         if callable(item):
    19             return item()
    20         return item
    22     def __getattr__(self, name):
    23         try:
    24             return self[name]
    25         except KeyError:
    26             raise AttributeError(name)
    28     __setattr__ = dict.__setitem__
    30     def __delattr__(self, name):
    31         try:
    32             del self[name]
    33         except KeyError:
    34             raise AttributeError(name)

mercurial