def Uuid(to_uuid=True):
@wraps(Uuid)<EOL>def built(value):<EOL><INDENT>invalid = Error("<STR_LIT>")<EOL>if isinstance(value, uuid.UUID):<EOL><INDENT>return value<EOL><DEDENT>elif not isinstance(value, six.string_types):<EOL><INDENT>raise invalid<EOL><DEDENT>try:<EOL><INDENT>as_uuid = uuid.UUID(value)<EOL><DEDENT>except (ValueError, AttributeError) as e:<EOL><INDENT>raise invalid<EOL><DEDENT>if to_uuid:<EOL><INDENT>return as_uuid<EOL><DEDENT>return value<EOL><DEDENT>return built<EOL>
Creates a UUID validator. Will raise an error for non-string types and
non-UUID values.

The given value will be converted to an instance of ``uuid.UUID`` unless
``to_uuid`` is ``False``.