Peach :: generator :: Generator :: Class Generator
[hide private]

Class Generator

source code

Generators generate data. Examples of generators could be a static string or integer, a string repeater, etc. Generators can be "incremented" by calling next() to produce the next varient of data. Generators can be fairly complex, comainting sub-generators to build things like packets.

Generators support the interator protocol and can be used as such.

When building a Generator one should keep in mind that the value from a generator could be asked for more then once per "round". Also it is recommended that you use the default getValue() implementation and override the getRawValue() method instead.


See Also: SimpleGenerator

Instance Methods [hide private]
 
__init__(self)
Base constructor, please call me!
source code
 
identity(self)
Who are we and were do we come from?
source code
Generator
__iter__(self)
Return iterator for Generator object.
source code
 
next(self)
Next value.
source code
string
getValue(self)
Return data, passed through a transformer if set.
source code
string
getRawValue(self)
Return raw value w/o passing through transformer if set.
source code
Group
getGroup(self)
Get group this Generator belongs to.
source code
 
setGroup(self, group)
Set group this Generator belongs to.
source code
Transformer
getTransformer(self)
Get transformer (if set).
source code
Generator
setTransformer(self, trans)
Set trasnformer.
source code
 
reset(self)
Called to reset the generator to its initial state.
source code
 
getName(self)
Get the name of this generator.
source code
 
setName(self, name)
Set the name of this generator.
source code
Method Details [hide private]

__iter__(self)

source code 

Return iterator for Generator object. This is always the Generator object itself.

Returns: Generator
Returns iterator, this is always self.

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).

getValue(self)

source code 

Return data, passed through a transformer if set.

Returns: string
Returns generated data

getRawValue(self)

source code 

Return raw value w/o passing through transformer if set. OVERRIDE

Returns: string
Data before transformations

getGroup(self)

source code 

Get group this Generator belongs to. Groups are used to increment sets of Generators.

Returns: Group
Returns Group this generator belongs to

setGroup(self, group)

source code 

Set group this Generator belongs to. This function will automaticly add the Generator into the Group.

Groups are used to increment sets of Generators.

Parameters:
  • group (Group) - Group this generator belongs to

getTransformer(self)

source code 

Get transformer (if set). Transformers are used to transform data in some way (such as HTML encoding, etc).

Returns: Transformer
Current transformer or None

setTransformer(self, trans)

source code 

Set trasnformer. Transformers are used to transform data in some way (such as HTML encoding, etc).

Parameters:
  • trans (Transformer) - Transformer to run data through
Returns: Generator
self

reset(self)

source code 

Called to reset the generator to its initial state. OVERRIDE

getName(self)

source code 

Get the name of this generator. Usefull for debugging.

setName(self, name)

source code 

Set the name of this generator. Usefull for debugging complex data generators. Stacktraces may end up in a generator creation statement giving limited feedback on which generator in an array might be causing the problem.

Parameters:
  • name (string) - Name of generator