human
Complete this python program:
def api_validate(response_type=None, add_api_type_doc=False):
assistant
#Here is the Python code you requested.

    """Factory for making validators for API calls, since API calls come
    in two flavors: responsive and unresponsive.  The machinary
    associated with both is similar, and the error handling identical,
    so this function abstracts away the kw validation and creation of
    a Json-y responder object.
    """
    def wrap(response_function):
        def _api_validate(*simple_vals, **param_vals):
            def val(fn):
                @wraps(fn)
                def newfn(self, *a, **env):
                    renderstyle = request.params.get('renderstyle')
                    if renderstyle:
                        c.render_style = api_type(renderstyle)
                    elif (not c.extension):
                        c.render_style = api_type(response_type)
                    if ((response_type == 'html') and (not (request.params.get('api_type') == 'json'))):
                        responder = JQueryResponse()
                    else:
                        responder = JsonResponse()
                    response.content_type = responder.content_type
                    try:
                        kw = _make_validated_kw(fn, simple_vals, param_vals, env)
                        return response_function(self, fn, responder, simple_vals, param_vals, *a, **kw)
                    except UserRequiredException:
                        responder.send_failure(errors.USER_REQUIRED)
                        return self.api_wrapper(responder.make_response())
                    except VerifiedUserRequiredException:
                        responder.send_failure(errors.VERIFIED_USER_REQUIRED)
                        return self.api_wrapper(responder.make_response())
                extra_param_vals = {}
                if add_api_type_doc:
                    extra_param_vals = {'api_type': 'the    string    `json`'}
                set_api_docs(newfn, simple_vals, param_vals, extra_param_vals)
                newfn.handles_csrf = _validators_handle_csrf(simple_vals, param_vals)
                return newfn
            return val
        return _api_validate
    return wrap