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


mavlink
Author(s): Lorenz Meier
autogenerated on Thu Jun 6 2019 19:01:57