<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def validation_tween_factory(handler, registry):
 """Pyramid tween for performing validation. Note this is very simple -- it validates requests, responses, and paths while delegating to the relevant matching view. """

    settings = load_settings(registry)
    route_mapper = registry.queryUtility(IRoutesMapper)

    validation_context = _get_validation_context(registry)

    def validator_tween(request):
        # We don't have access to this yet but let's go ahead and build the
        # matchdict so we can validate it and use it to exclude routes from
        # validation.
        route_info = route_mapper(request)
        swagger_handler, spec = get_swagger_objects(settings, route_info,
                                                    registry)

        if should_exclude_request(settings, request, route_info):
            return handler(request)

        try:
            op_or_validators_map = swagger_handler.op_for_request(
                request, route_info=route_info, spec=spec)
        except PathNotMatchedError as exc:
            if settings.validate_path:
                with validation_context(request):
                    raise PathNotFoundError(str(exc), child=exc)
            else:
                return handler(request)

        def operation(_):
            return op_or_validators_map if isinstance(op_or_validators_map, Operation) else None

        request.set_property(operation)

        if settings.validate_request:
            with validation_context(request, response=None):
                request_data = swagger_handler.handle_request(
                    PyramidSwaggerRequest(request, route_info),
                    op_or_validators_map,
                )

            def swagger_data(_):
                return request_data

            request.set_property(swagger_data)

        response = handler(request)

        if settings.validate_response:
            with validation_context(request, response=response):
                swagger_handler.handle_response(response, op_or_validators_map)

        return response

    return validator_tween