attrdict.py (6278:47e757f289e0) | attrdict.py (6652:f24b06320444) |
---|---|
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 --- 31 unchanged lines hidden (view full) --- 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) 47 | 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 --- 31 unchanged lines hidden (view full) --- 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) 47 |
48 def __getstate__(self): 49 return dict(self) 50 51 def __setstate__(self, state): 52 self.update(state) 53 |
|
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: 55 d = optiondict() --- 32 unchanged lines hidden --- | 54class multiattrdict(attrdict): 55 """Wrap attrdict so that nested attribute accesses automatically create 56 nested dictionaries.""" 57 def __getattr__(self, attr): 58 try: 59 return super(multiattrdict, self).__getattr__(attr) 60 except AttributeError: 61 d = optiondict() --- 32 unchanged lines hidden --- |