示例#1
0
    def __call__(self, environ: WSGIEnvironment,
                 start_response: StartResponse) -> WSGIResponse:
        req = http.Request(environ)

        output_format = get_output_format(
            req.get_ascii_input_mandatory("output_format", "html").lower())
        mime_type = get_mime_type_from_output_format(output_format)

        resp = Response(headers=default_response_headers(req),
                        mimetype=mime_type)
        funnel = OutputFunnel(resp)

        timeout_manager = TimeoutManager()
        timeout_manager.enable_timeout(req.request_timeout)

        theme = Theme()
        config_obj = config_module.make_config_object(
            config_module.get_default_config())

        with AppContext(self), RequestContext(
                req=req,
                resp=resp,
                funnel=funnel,
                config_obj=config_obj,
                user=LoggedInNobody(),
                html_obj=htmllib.html(req, resp, funnel, output_format),
                timeout_manager=timeout_manager,
                display_options=DisplayOptions(),
                theme=theme,
        ), patch_json(json):
            config_module.initialize()
            theme.from_config(config.ui_theme)
            return self.wsgi_app(environ, start_response)
示例#2
0
    def __call__(self, environ, start_response):
        req = http.Request(environ)

        output_format = get_output_format(
            req.get_ascii_input_mandatory("output_format", "html").lower())
        mime_type = get_mime_type_from_output_format(output_format)

        resp = Response(headers=default_response_headers(req),
                        mimetype=mime_type)
        funnel = OutputFunnel(resp)

        timeout_manager = TimeoutManager()
        timeout_manager.enable_timeout(req.request_timeout)

        theme = Theme()

        with AppContext(self), RequestContext(
                req=req,
                resp=resp,
                funnel=funnel,
                html_obj=htmllib.html(req, resp, funnel, output_format),
                timeout_manager=timeout_manager,
                display_options=DisplayOptions(),
                theme=theme,
        ), patch_json(json):
            config.initialize()
            theme.from_config(config.ui_theme, config.theme_choices())
            return self.wsgi_app(environ, start_response)
示例#3
0
def test_patch_json_to_json_method() -> None:
    class Ding:
        def __init__(self):
            self._a = 1

        def to_json(self):
            return self.__dict__

    with pytest.raises(TypeError, match="is not JSON serializable"):
        assert json.dumps(Ding()) == ""

    with patch_json(json):
        assert json.dumps(Ding()) == '{"_a": 1}'

    with pytest.raises(TypeError, match="is not JSON serializable"):
        assert json.dumps(Ding()) == ""
示例#4
0
def fixture_patch_json():
    with patch_json(json):
        yield
示例#5
0
def fixture_patch_json() -> Iterator[None]:
    with patch_json(json):
        yield
示例#6
0
def test_patch_json_slash_escape() -> None:
    assert json.dumps("a/b") == '"a/b"'
    with patch_json(json):
        assert json.dumps("a/b") == '"a\\/b"'
    assert json.dumps("a/b") == '"a/b"'