Пример #1
0
 def eb(failure):
     log.err(failure, "An error occurred while rendering the response.")
     if request.site.displayTracebacks:
         return flatten(request, _failElement(failure), request.write)
     else:
         request.write(
             ('<div style="font-size:800%;'
              'background-color:#FFF;'
              'color:#F00'
              '">An error occurred while rendering the response.</div>'))
Пример #2
0
 def eb(failure):
     log.err(failure, "An error occurred while rendering the response.")
     if request.site.displayTracebacks:
         return flatten(request, _failElement(failure), request.write)
     else:
         request.write(
             ('<div style="font-size:800%;'
              'background-color:#FFF;'
              'color:#F00'
              '">An error occurred while rendering the response.</div>'))
Пример #3
0
 def eb(failure):
     _moduleLog.failure("An error occurred while rendering the response.",
                        failure=failure)
     if request.site.displayTracebacks:
         return flatten(request, _failElement(failure),
                        request.write).encode('utf8')
     else:
         request.write(
             (b'<div style="font-size:800%;'
              b'background-color:#FFF;'
              b'color:#F00'
              b'">An error occurred while rendering the response.</div>'))
Пример #4
0
def renderElement(
    request: IRequest,
    element: IRenderable,
    doctype: Optional[bytes] = b"<!DOCTYPE html>",
    _failElement: Optional[Callable[[Failure], "Element"]] = None,
) -> object:
    """
    Render an element or other L{IRenderable}.

    @param request: The L{IRequest} being rendered to.
    @param element: An L{IRenderable} which will be rendered.
    @param doctype: A L{bytes} which will be written as the first line of
        the request, or L{None} to disable writing of a doctype.  The argument
        should not include a trailing newline and will default to the HTML5
        doctype C{'<!DOCTYPE html>'}.

    @returns: NOT_DONE_YET

    @since: 12.1
    """
    if doctype is not None:
        request.write(doctype)
        request.write(b"\n")

    if _failElement is None:
        _failElement = twisted.web.util.FailureElement

    d = flatten(request, element, request.write)

    def eb(failure: Failure) -> Optional[Deferred[None]]:
        _moduleLog.failure("An error occurred while rendering the response.",
                           failure=failure)
        site: Optional["twisted.web.server.Site"] = getattr(
            request, "site", None)
        if site is not None and site.displayTracebacks:
            assert _failElement is not None
            return flatten(request, _failElement(failure), request.write)
        else:
            request.write(
                b'<div style="font-size:800%;'
                b"background-color:#FFF;"
                b"color:#F00"
                b'">An error occurred while rendering the response.</div>')
            return None

    def finish(result: object, *, request: IRequest = request) -> object:
        request.finish()
        return result

    d.addErrback(eb)
    d.addBoth(finish)
    return NOT_DONE_YET
Пример #5
0
 def eb(failure: Failure) -> Optional[Deferred[None]]:
     _moduleLog.failure("An error occurred while rendering the response.",
                        failure=failure)
     site = getattr(request, "site", None)
     if site is not None and site.displayTracebacks:
         assert _failElement is not None
         return flatten(request, _failElement(failure), request.write)
     else:
         request.write(
             b'<div style="font-size:800%;'
             b"background-color:#FFF;"
             b"color:#F00"
             b'">An error occurred while rendering the response.</div>')
         return None
Пример #6
0
def renderElement(request,
                  element,
                  doctype=b'<!DOCTYPE html>',
                  _failElement=None):
    """
    Render an element or other C{IRenderable}.

    @param request: The C{Request} being rendered to.
    @param element: An C{IRenderable} which will be rendered.
    @param doctype: A C{bytes} which will be written as the first line of
        the request, or L{None} to disable writing of a doctype.  The C{string}
        should not include a trailing newline and will default to the HTML5
        doctype C{'<!DOCTYPE html>'}.

    @returns: NOT_DONE_YET

    @since: 12.1
    """
    if doctype is not None:
        request.write(doctype)
        request.write(b'\n')

    if _failElement is None:
        _failElement = twisted.web.util.FailureElement

    d = flatten(request, element, request.write)

    def eb(failure):
        _moduleLog.failure("An error occurred while rendering the response.",
                           failure=failure)
        if request.site.displayTracebacks:
            return flatten(request, _failElement(failure),
                           request.write).encode('utf8')
        else:
            request.write(
                (b'<div style="font-size:800%;'
                 b'background-color:#FFF;'
                 b'color:#F00'
                 b'">An error occurred while rendering the response.</div>'))

    d.addErrback(eb)
    d.addBoth(lambda _: request.finish())
    return NOT_DONE_YET
Пример #7
0
def renderElement(request, element, doctype=b"<!DOCTYPE html>", _failElement=None):
    """
    Render an element or other C{IRenderable}.

    @param request: The C{Request} being rendered to.
    @param element: An C{IRenderable} which will be rendered.
    @param doctype: A C{bytes} which will be written as the first line of
        the request, or C{None} to disable writing of a doctype.  The C{string}
        should not include a trailing newline and will default to the HTML5
        doctype C{'<!DOCTYPE html>'}.

    @returns: NOT_DONE_YET

    @since: 12.1
    """
    if doctype is not None:
        request.write(doctype)
        request.write(b"\n")

    if _failElement is None:
        _failElement = twisted.web.util.FailureElement

    d = flatten(request, element, request.write)

    def eb(failure):
        log.err(failure, "An error occurred while rendering the response.")
        if request.site.displayTracebacks:
            return flatten(request, _failElement(failure), request.write).encode("utf8")
        else:
            request.write(
                (
                    b'<div style="font-size:800%;'
                    b"background-color:#FFF;"
                    b"color:#F00"
                    b'">An error occurred while rendering the response.</div>'
                )
            )

    d.addErrback(eb)
    d.addBoth(lambda _: request.finish())
    return NOT_DONE_YET