Package rdkit :: Package VLib :: Module Supply

[hide private]
[frames] | no frames]

# Source Code for Module rdkit.VLib.Supply

     1  #  $Id$
     2  #
     3  #  Copyright (C) 2003 Rational Discovery LLC
     4  #     All Rights Reserved
     5  #
     6  import sys
     7
     8  from rdkit.VLib.Node import VLibNode
     9
    10 -class SupplyNode(VLibNode):
    11    """ base class for nodes which supply things
    12
    13    Assumptions:
    14      1) no parents
    15
    16    Usage Example:
    17      >>> supplier = SupplyNode(contents=[1,2,3])
    18      >>> supplier.next()
    19      1
    20      >>> supplier.next()
    21      2
    22      >>> supplier.next()
    23      3
    24      >>> supplier.next()
    25      Traceback (most recent call last):
    26          ...
    27      StopIteration
    28      >>> supplier.reset()
    29      >>> supplier.next()
    30      1
    31      >>> [x for x in supplier]
    32      [1, 2, 3]
    33
    34
    35    """
    36 -  def __init__(self,contents=None,**kwargs):
    37      VLibNode.__init__(self,**kwargs)
    38      if contents is not None:
    39        self._contents = contents
    40      else:
    41        self._contents = []
    42      self._pos = 0
    43
    44 -  def reset(self):
    45      VLibNode.reset(self)
    46      self._pos = 0
    47 -  def next(self):
    48      if self._pos == len(self._contents):
    49        raise StopIteration
    50
    51      res=self._contents[self._pos]
    52      self._pos += 1
    53      return res
    54 -  def AddParent(self,parent,notify=1):
    55      raise ValueError('SupplyNodes do not have parents')
    56
    57
    58  #------------------------------------
    59  #
    60  #  doctest boilerplate
    61  #
    62 -def _test():
    63    import doctest,sys
    64    return doctest.testmod(sys.modules["__main__"])
    65
    66  if __name__ == '__main__':
    67    import sys
    68    failed,tried = _test()
    69    sys.exit(failed)
    70