This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ReadOnlyAttr: | |
""" A class with the attributes that are defined on the instance | |
creation and cannot be modified later. """ | |
# A tuple of attributes that should remain read-only | |
READ_ONLY_ATTR = ('x', 'y') | |
def __init__(self, *args, **kwargs): | |
""" Takes a list of read-only attributes: %s """ | |
for attr in self.READ_ONLY_ATTR: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AttributedDict(dict): | |
""" | |
A class extending the standard dict so that its keys can be accessed | |
as an object attributes (as long as the are strings). | |
Notice: this class is not pickable, so for example an attempt to save | |
its instance in Django session causes an error. | |
""" | |
__getattr__ = dict.__getitem__ |