Difference between revisions of "ZSI Notes"
Jump to navigation
Jump to search
PeterHarding (talk | contribs) (New page: =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 ret...) |
PeterHarding (talk | contribs) |
||
Line 43: | Line 43: | ||
return self.list | return self.list | ||
</pre> | </pre> | ||
[[Category:Python]] | |||
[[Category:ZSI]] |
Revision as of 15:39, 19 February 2008
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