#NEWLINE# def __arbitrary_generator( self , gen , value_func = None ) : #NEWLINE# #INDENT# 'Constructs arbitrary generator based on given object.\n\n        It can be a function that returns a single value,\n        a generator function (that uses ``yield``) or a generator class\n        (with ``__iter__`` and ``next`` methods).\n        ' #NEWLINE# if ( value_func is None ) : #NEWLINE# #INDENT# value_func = ( lambda v : v ) #NEWLINE# #UNINDENT# if ( inspect . isgeneratorfunction ( gen ) or inspect . isclass ( gen ) ) : #NEWLINE# #INDENT# @ functools . wraps ( gen ) #NEWLINE# def wrapper( * args , **kwargs ) : #NEWLINE# #INDENT# ( args , kwargs ) = self . __coerce_to_arbitraries ( args , kwargs ) #NEWLINE# for obj in gen ( * args , ** kwargs ) : #NEWLINE# #INDENT# ( yield value_func ( obj ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# @ functools . wraps ( gen ) #NEWLINE# def wrapper( * args , **kwargs ) : #NEWLINE# #INDENT# ( args , kwargs ) = self . __coerce_to_arbitraries ( args , kwargs ) #NEWLINE# while True : #NEWLINE# #INDENT# ( yield value_func ( gen ( * args , ** kwargs ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return value_func