ZSI Notes

From PeformIQ Upgrade
Revision as of 14:38, 19 February 2008 by 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...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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