attrdict.py (5617:04b9d1e7ef2c) | attrdict.py (6278:47e757f289e0) |
---|---|
1# Copyright (c) 2006 The Regents of The University of Michigan 2# All rights reserved. 3# 4# Redistribution and use in source and binary forms, with or without 5# modification, are permitted provided that the following conditions are 6# met: redistributions of source code must retain the above copyright 7# notice, this list of conditions and the following disclaimer; 8# redistributions in binary form must reproduce the above copyright --- 29 unchanged lines hidden (view full) --- 38 def __setattr__(self, attr, value): 39 if attr in dir(self) or attr.startswith('_'): 40 return super(attrdict, self).__setattr__(attr, value) 41 return self.__setitem__(attr, value) 42 43 def __delattr__(self, attr): 44 if attr in self: 45 return self.__delitem__(attr) | 1# Copyright (c) 2006 The Regents of The University of Michigan 2# All rights reserved. 3# 4# Redistribution and use in source and binary forms, with or without 5# modification, are permitted provided that the following conditions are 6# met: redistributions of source code must retain the above copyright 7# notice, this list of conditions and the following disclaimer; 8# redistributions in binary form must reproduce the above copyright --- 29 unchanged lines hidden (view full) --- 38 def __setattr__(self, attr, value): 39 if attr in dir(self) or attr.startswith('_'): 40 return super(attrdict, self).__setattr__(attr, value) 41 return self.__setitem__(attr, value) 42 43 def __delattr__(self, attr): 44 if attr in self: 45 return self.__delitem__(attr) |
46 return super(attrdict, self).__delattr__(attr, value) | 46 return super(attrdict, self).__delattr__(attr) |
47 48class multiattrdict(attrdict): 49 """Wrap attrdict so that nested attribute accesses automatically create 50 nested dictionaries.""" 51 def __getattr__(self, attr): 52 try: 53 return super(multiattrdict, self).__getattr__(attr) 54 except AttributeError: --- 33 unchanged lines hidden --- | 47 48class multiattrdict(attrdict): 49 """Wrap attrdict so that nested attribute accesses automatically create 50 nested dictionaries.""" 51 def __getattr__(self, attr): 52 try: 53 return super(multiattrdict, self).__getattr__(attr) 54 except AttributeError: --- 33 unchanged lines hidden --- |