#NEWLINE# def to_arbitrary( obj ) : #NEWLINE# #INDENT# "Ensures that given object is a generator of arbitrary values.\n\n    Rather than permitting only actual generators, this allows\n    us to pass generator functions or even types, provided\n    there is a known arbitrary generator for them.\n\n    :param obj: Object to be coerced into arbitrary generator,\n                if it's possible and the object is not already one\n\n    Raises :exc:`TypeError` if ``obj`` is a type and no default\n    generator for this type has been found.\n\n    Raises :exc:`ValueError` if ``obj`` cannot be reasonably\n    coerced into a generator of arbitrary values.\n    " #NEWLINE# if inspect . isgenerator ( obj ) : #NEWLINE# #INDENT# return obj #NEWLINE# #UNINDENT# if inspect . isgeneratorfunction ( obj ) : #NEWLINE# #INDENT# return obj ( ) #NEWLINE# #UNINDENT# if isinstance ( obj , type ) : #NEWLINE# #INDENT# arbit_gens = arbitrary . registry . get ( obj ) #NEWLINE# if ( not arbit_gens ) : #NEWLINE# #INDENT# raise TypeError ( ( "no arbitrary values' generator found for type: %s" % obj ) ) #NEWLINE# #UNINDENT# return to_arbitrary ( arbit_gens [ 0 ] ) #NEWLINE# #UNINDENT# raise ValueError ( ( 'invalid generator of arbitrary values: %r (of type %s)' % ( obj , type ( obj ) . __name__ ) ) )