rdkit.VLib.Supply

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  from rdkit import six
     7  from rdkit.VLib.Node import VLibNode
     8
     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
    37 -  def __init__(self, contents=None, **kwargs):
    38      VLibNode.__init__(self, **kwargs)
    39      if contents is not None:
    40        self._contents = contents
    41      else:
    42        self._contents = []
    43      self._pos = 0
    44
    45 -  def reset(self):
    46      VLibNode.reset(self)
    47      self._pos = 0
    48
    49 -  def next(self):
    50      if self._pos == len(self._contents):
    51        raise StopIteration
    52
    53      res = self._contents[self._pos]
    54      self._pos += 1
    55      return res
    56
    57 -  def AddParent(self, parent, notify=1):
    58      raise ValueError('SupplyNodes do not have parents')
    59
    60
    61  if six.PY3:
    62    SupplyNode.__next__ = SupplyNode.next
    63
    64
    65  # ------------------------------------
    66  #
    67  #  doctest boilerplate
    68  #
    69 -def _runDoctests(verbose=None):  # pragma: nocover
    70    import sys
    71    import doctest
    72    failed, _ = doctest.testmod(optionflags=doctest.ELLIPSIS, verbose=verbose)
    73    sys.exit(failed)
    74
    75
    76  if __name__ == '__main__':  # pragma: nocover
    77    _runDoctests()
    78