Beispiel #1
0
def _reportError(reason, request, defaultEncoder):
    if not interface.ISerializableError.providedBy(reason.value):
        log.err(reason)
        return

    request.encoder = getattr(request, "encoder", defaultEncoder)
    resource = errors.RESTErrorPage(reason.value)
    return resource.render(request)
Beispiel #2
0
    def doLocationTest(self, requestPath: bytes):
        """
        Render a response to a request with path *requestPath*

        @param requestPath: A slash-separated path like C{b'/foo/bar'}.

        @returns: The value of the I{Location} header.
        """
        request = Request(DummyChannel(), True)
        request.method = b"GET"
        request.prepath = requestPath.lstrip(b"/").split(b"/")

        resource = ParentRedirect()
        resource.render(request)

        [location] = request.responseHeaders.getRawHeaders(b"Location")
        return location
Beispiel #3
0
def _reportError(reason, request, defaultEncoder):
    if not interface.ISerializableError.providedBy(reason.value):
        log.err(reason)
        return

    request.encoder = getattr(request, "encoder", defaultEncoder)
    resource = errors.RESTErrorPage(reason.value)
    return resource.render(request)
Beispiel #4
0
    def _makeRequest(self, resource, request):
        """
        Makes a request to a particular resource.
        """
        self.request = request

        result = resource.render(request)
        if result is not server.NOT_DONE_YET:
            request.write(result)
            request.finish()

        return request.notifyFinish()
Beispiel #5
0
    def _makeRequest(self, resource, request):
        """
        Makes a request to a particular resource.
        """
        self.request = request

        result = resource.render(request)
        if result is not server.NOT_DONE_YET:
            request.write(result)
            request.finish()

        return request.notifyFinish()
Beispiel #6
0
def _render(resource, request):
	result = resource.render(request)
	if isinstance(result, str):
		request.write(result)
		request.finish()
		return succeed(None)
	elif result is server.NOT_DONE_YET:
		if request.finished:
			return succeed(None)
		else:
			return request.notifyFinish()
	else:
		raise ValueError("Unexpected return value: %r" % (result,))
    def test_static_preprocessors(self):
        current_file = filepath.FilePath(__file__)

        config = dict(
            routing = dict(
                __config__ = dict(
                    static = dict(
                        path = current_file.dirname(),
                        preprocessors = dict(
                            foo = "request: request.setHeader('foo', 'bar')"
                        )
                    )
                )
            )
        )

        web_site = self.getConfiguredWebSite(config)

        # send a request for this file:
        request = web_provider.DummyRequest([current_file.basename()])
        resource = web_site.factory.getResourceFor(request)
        resource.render(request)

        self.assertEquals(request.responseHeaders.getRawHeaders('foo'), ['bar'])
Beispiel #8
0
    def render(self, resource):
        """
        Render the given resource as a response to this request.

        This implementation only handles a few of the most common behaviors of
        resources.  It can handle a render method that returns a string or
        C{NOT_DONE_YET}.  It doesn't know anything about the semantics of
        request methods (eg HEAD) nor how to set any particular headers.
        Basically, it's largely broken, but sufficient for some tests at least.
        It should B{not} be expanded to do all the same stuff L{Request} does.
        Instead, L{DummyRequest} should be phased out and L{Request} (or some
        other real code factored in a different way) used.
        """
        result = resource.render(self)
        if result is server.NOT_DONE_YET:
            return
        self.write(result)
        self.finish()
Beispiel #9
0
    def render(self, resource):
        """
        Render the given resource as a response to this request.

        This implementation only handles a few of the most common behaviors of
        resources.  It can handle a render method that returns a string or
        C{NOT_DONE_YET}.  It doesn't know anything about the semantics of
        request methods (eg HEAD) nor how to set any particular headers.
        Basically, it's largely broken, but sufficient for some tests at least.
        It should B{not} be expanded to do all the same stuff L{Request} does.
        Instead, L{DummyRequest} should be phased out and L{Request} (or some
        other real code factored in a different way) used.
        """
        result = resource.render(self)
        if result is server.NOT_DONE_YET:
            return
        self.write(result)
        self.finish()
Beispiel #10
0
def _renderResource(resource, request):
    return resource.render(request)
Beispiel #11
0
def _renderResource(resource, request):
    return resource.render(request)