<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def audit(**kwargs):
 """ use this decorator to audit an operation """


    def wrap(fn):

        @functools.wraps(fn)
        def advice(parent_object, *args, **kw):
            request = parent_object.request
            wijziging = request.audit_manager.create_revision()

            result = fn(parent_object, *args, **kw)

            if hasattr(request, 'user') and request.user is not None and 'actor' in request.user:
                actor = request.user['actor']
                attributes = request.user['attributes']
                wijziging.updated_by = actor.get('uri', None)
                if actor.get('uri') == actor.get('instantie_actor_uri'):
                    wijziging.updated_by_omschrijving = (
                        attributes.get('displayname')
                        or attributes.get('mail')
                        or actor.get('omschrijving'))
                else:
                    wijziging.updated_by_omschrijving = actor.get(
                        'omschrijving')
            else:
                wijziging.updated_by = 'publiek'
                wijziging.updated_by_omschrijving = 'publiek'

            r_id = request.matchdict.get('id')
            wijziging.resource_object_id = r_id
            if result is not None:
                try:
                    renderer_name = request.registry.settings.get(
                        'audit.pyramid.json.renderer',
                        'jsonrenderer')
                    json_string = renderers.render(renderer_name, result,
                                                   request=request)
                    result_object_json = json.loads(json_string)
                    wijziging.resource_object_json = result_object_json
                    wijziging.resource_object_id = _get_id_from_result(r_id, result_object_json, kwargs)
                except Exception as e:
                    log.error(e)

            wijziging.versie = _get_versie_hash(wijziging)
            wijziging.actie = kwargs.get('actie') if kwargs.get('actie') else _action_from_request(request)

            request.audit_manager.save(wijziging)

            return result

        return advice

    return wrap