Peach :: Generators :: dictionary :: GeneratorList2 :: Class GeneratorList2
[hide private]

Class GeneratorList2

source code


Iterates through a specified list of generators (different group control). When the end of the list is reached a generator.GeneratorCompleted exceoption is raised.

This generator differs from GeneratorList by allowing one group to drive the rounds, but associating different sub groups to each generator. When the master group is incremented the group for the current generator is also incremented. This allows more complex control of how generators create data.

NOTE: We only increment to next generator in list when the GeneratorCompleted exception has been thrown from current generator. This allows one todo kewl things like have 2 static generators, then a dictionary, then a repeater.

Example:

>>> groupA = Group()
>>> groupBA = Group()
>>> groupBB = Group()
>>> groupB = GroupForeachDo(groupBA, groupBB)
>>>
>>> gen = GeneratorList2(None, [groupA, groupB], [
...     Repeater(groupA, Static('A'), 1, 1, 3),
...     Block([
...             List(groupBA, [':', '\', '/']),
...             Repeater(groupBB, Static('B'), 1, 1, 3)
...             ])
...     ])
>>>
>>> print gen.getValue()
A
>>> gen.next()
>>> gen.getValue()
AA
>>> gen.next()
>>> gen.getValue()
AAA
>>> gen.next()
>>> gen.getValue()
:B
>>> gen.next()
>>> gen.getValue()
:BB
>>> gen.next()
>>> gen.getValue()
:BBB
>>> gen.next()
>>> gen.getValue()
\B
>>> gen.next()
>>> gen.getValue()
\BB
>>> gen.next()
>>> gen.getValue()
\BBB
>>> gen.next()
>>> gen.getValue()
/B
>>> gen.next()
>>> gen.getValue()
/BB
>>> gen.next()
>>> gen.getValue()
/BBB

See Also: GeneratorList

Instance Methods [hide private]
 
__init__(self, group, groupList=None, list=None, name=None)
Base constructor, please call me!
source code
 
next(self)
Next value.
source code
 
setGroups(self, list)
Set list of Groups.
source code
 
reset(self)
Called to reset the generator to its initial state.
source code

Inherited from GeneratorList: getList, getRawValue, setList

Inherited from generator.Generator: __iter__, getGroup, getName, getTransformer, getValue, identity, setGroup, setName, setTransformer

Static Methods [hide private]
 
unittest() source code
Method Details [hide private]

__init__(self, group, groupList=None, list=None, name=None)
(Constructor)

source code 

Base constructor, please call me!

Parameters:
  • group (Group) - Group this Generator belongs to
  • groupList (list) - List of Groups to use on generators
  • list (list) - List of Generators to iterate through
  • name (String) - [optional] Name for this Generator. Used for debugging.
Overrides: generator.Generator.__init__

next(self)

source code 

Next value. OVERRIDE

From Python docs on next():

The intention of the protocol is that once an iterator's next() method raises StopIteration, it will continue to do so on subsequent calls. Implementations that do not obey this property are deemed broken. (This constraint was added in Python 2.3; in Python 2.2, various iterators are broken according to this rule.)

For Generators, please use the GeneratorCompleted exception instead of StopIteration (its a subclass).

Overrides: generator.Generator.next
(inherited documentation)

setGroups(self, list)

source code 

Set list of Groups.

Parameters:
  • list (list) - List of Groups

reset(self)

source code 

Called to reset the generator to its initial state. OVERRIDE

Overrides: generator.Generator.reset
(inherited documentation)

unittest()
Static Method

source code 
Overrides: GeneratorList.unittest