list: a data source

Previous: repository: the system ] [ Top:  ] [ Next: entry: an individual list entry ]

The list object would almost appear to be a superfluity given the fact that the repmgr API really treats a list name and key as nearly equivalent coordinates of an entry -- but lists are indeed somewhat privileged, and a useful function for the list object to fulfill is that it can act as an iterator along a list or query. I'm probably going to end up conflating the list and query notions into a single list object -- this is because a list storage in the repository needn't necessarily be the only kind of list we think of as a "list". In short, a list should be thought of as any collection of entries, even if it's not strictly a storage-oriented list defined by the repository.

In fact, a list could even be constructed dynamically and simply contain a bunch of otherwise unrelated entries or something. We'll see what makes the most sense later. This is fun.
 
class list(xml):
   """Implements a repository manager list.
   """
   def __init__ (self, repository, id=None):
      self._repository = repository
      self._listid = id
      self.reset()

   def reset (self):
      self._keys = []
      self._recs = []
      self._lookup = {}
      if self._listid != None:
         self._list = self._repository.defn (self._listid).new_copy()
      else:
         self._list = xml.create ('list')

   def query (self, where=''):
      self.reset()
      self._list.set ('where', where)
      self._keys = repmgr.list (self._repository.repos, self._list._xml)
      self._recs = self._list.elements()
      for r in self._recs:
         self._lookup[r.attrval('id')] = r

   def keys (self):
      return self._keys

   def __str__ (self):
      return self._list.__str__()
   def __repr__ (self):
      return self._list.__repr__()
   def __getitem__ (self, key):
      return self._lookup[key]

   #def setquery
   #def rewind
   #def advance
   #def current
   #def prev
   #def next
Previous: repository: the system ] [ Top:  ] [ Next: entry: an individual list entry ]


This code and documentation are released under the terms of the GNU license. They are additionally copyright (c) 2001, Vivtek. All rights reserved except those explicitly granted under the terms of the GNU license.