attrdict and namedtuple moved to lib
--HG-- branch : sandbox
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
<path>/sandbox/gui</path>
|
||||
<path>/sandbox/mpl</path>
|
||||
<path>/sandbox/megui</path>
|
||||
<path>/sandbox/lib</path>
|
||||
</pydev_pathproperty>
|
||||
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.5</pydev_property>
|
||||
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
|
||||
|
||||
20
lib/attrdict.py
Normal file
20
lib/attrdict.py
Normal file
@@ -0,0 +1,20 @@
|
||||
# Copyright (c) 2009 Andreas Balogh
|
||||
# See LICENSE for details.
|
||||
|
||||
class AttrDict(dict):
|
||||
"""A dict whose items can also be accessed as member variables."""
|
||||
def __init__(self, *args, **kwargs):
|
||||
dict.__init__(self, *args, **kwargs)
|
||||
self.__dict__ = self
|
||||
|
||||
def copy(self):
|
||||
ch = AttrDict(self)
|
||||
return ch
|
||||
|
||||
def __repr__(self):
|
||||
return 'AttrDict(' + dict.__repr__(self) + ')'
|
||||
|
||||
@classmethod
|
||||
def fromkeys(cls, seq, value = None):
|
||||
return AttrDict(dict.fromkeys(seq, value))
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
# http://code.activestate.com/recipes/473786/
|
||||
|
||||
class AttrDict(dict):
|
||||
"""A dictionary with attribute-style access. It maps attribute access to
|
||||
the real dictionary. """
|
||||
def __init__(self, init={}):
|
||||
dict.__init__(self, init)
|
||||
|
||||
def __getstate__(self):
|
||||
return self.__dict__.items()
|
||||
|
||||
def __setstate__(self, items):
|
||||
for key, val in items:
|
||||
self.__dict__[key] = val
|
||||
|
||||
def __repr__(self):
|
||||
return "%s(%s)" % (self.__class__.__name__, dict.__repr__(self))
|
||||
|
||||
def __setitem__(self, key, value):
|
||||
return super(AttrDict, self).__setitem__(key, value)
|
||||
|
||||
def __getitem__(self, name):
|
||||
return super(AttrDict, self).__getitem__(name)
|
||||
|
||||
def __delitem__(self, name):
|
||||
return super(AttrDict, self).__delitem__(name)
|
||||
|
||||
__getattr__ = __getitem__
|
||||
__setattr__ = __setitem__
|
||||
|
||||
def copy(self):
|
||||
ch = AttrDict(self)
|
||||
return ch
|
||||
Reference in New Issue
Block a user