casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables
odict.py
Go to the documentation of this file.
00001 from UserDict import UserDict
00002 
00003 class odict(UserDict):
00004     def __init__(self, dict = None):
00005         self._keys = []
00006         if(type(dict)==list):
00007             localdict=odict()
00008             for k in range(len(dict)):
00009                 localdict.update(dict[k])
00010             dict=localdict
00011         UserDict.__init__(self, dict)
00012 
00013     def __delitem__(self, key):
00014         UserDict.__delitem__(self, key)
00015         self._keys.remove(key)
00016 
00017     def __setitem__(self, key, item):
00018         UserDict.__setitem__(self, key, item)
00019         if key not in self._keys: self._keys.append(key)
00020 
00021     def clear(self):
00022         UserDict.clear(self)
00023         self._keys = []
00024 
00025     def copy(self):
00026         dict = UserDict.copy(self)
00027         dict._keys = self._keys[:]
00028         return dict
00029 
00030     def items(self):
00031         return zip(self._keys, self.values())
00032 
00033     def keys(self):
00034         return self._keys
00035 
00036     def popitem(self):
00037         try:
00038             key = self._keys[-1]
00039         except IndexError:
00040             raise KeyError('dictionary is empty')
00041 
00042         val = self[key]
00043         del self[key]
00044 
00045         return (key, val)
00046 
00047     def setdefault(self, key, failobj = None):
00048         UserDict.setdefault(self, key, failobj)
00049         if key not in self._keys: self._keys.append(key)
00050 
00051     def update(self, dict):
00052         UserDict.update(self, dict)
00053         for key in dict.keys():
00054             if key not in self._keys: self._keys.append(key)
00055 
00056     def values(self):
00057         return map(self.get, self._keys)