attrdict.py (6653:9e27313312e6) attrdict.py (7459:da32c2b05648)
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

--- 44 unchanged lines hidden (view full) ---

53
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:
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

--- 44 unchanged lines hidden (view full) ---

53
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 if attr.startswith('_'):
62 raise
63
61 d = multiattrdict()
62 setattr(self, attr, d)
63 return d
64
65class optiondict(attrdict):
66 """Modify attrdict so that a missing attribute just returns None"""
67 def __getattr__(self, attr):
68 try:

--- 29 unchanged lines hidden ---
64 d = multiattrdict()
65 setattr(self, attr, d)
66 return d
67
68class optiondict(attrdict):
69 """Modify attrdict so that a missing attribute just returns None"""
70 def __getattr__(self, attr):
71 try:

--- 29 unchanged lines hidden ---