ZSI Notes
Revision as of 15:39, 19 February 2008 by PeterHarding (talk | contribs)
alphabetical order of 'self.attribute_typecode_dict'
This should be irrelevant, although order is important for canonicalization for an entirely different matter.
I think you could retain your ordering by replacing the underlying dict with your own dict subclass that maintains a list too.
Topic._attrs = OrderDict()
Something like Collection, although obviously this is a bit old.
from ZSI.wstools.Utility import Collection class Collection(UserDict): """Helper class for maintaining ordered named collections.""" default = lambda self,k: k.name def __init__(self, parent, key=None): UserDict.__init__(self) self.parent = weakref.ref(parent) self.list = [] self._func = key or self.default def __getitem__(self, key): if type(key) is type(1): return self.list[key] return self.data[key] def __setitem__(self, key, item): item.parent = weakref.ref(self) self.list.append(item) self.data[key] = item def keys(self): return map(lambda i: self._func(i), self.list) def items(self): return map(lambda i: (self._func(i), i), self.list) def values(self): return self.list