• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python tutils.tresp函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中mitmproxy.test.tutils.tresp函数的典型用法代码示例。如果您正苦于以下问题:Python tresp函数的具体用法?Python tresp怎么用?Python tresp使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了tresp函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_storage_bodies

 async def test_storage_bodies(self):
     # Need to test for configure
     # Need to test for set_order
     s = self.start_session(fp=0.5)
     f = self.tft()
     f2 = self.tft(start=1)
     f.request.content = b"A" * 1001
     s.request(f)
     s.request(f2)
     await asyncio.sleep(1.0)
     content = s.db_store.con.execute(
         "SELECT type_id, content FROM body WHERE body.flow_id == (?);", [f.id]
     ).fetchall()[0]
     assert content == (1, b"A" * 1001)
     assert s.db_store.body_ledger == {f.id}
     f.response = http.HTTPResponse.wrap(tutils.tresp(content=b"A" * 1001))
     f2.response = http.HTTPResponse.wrap(tutils.tresp(content=b"A" * 1001))
     # Content length is wrong for some reason -- quick fix
     f.response.headers['content-length'] = b"1001"
     f2.response.headers['content-length'] = b"1001"
     s.response(f)
     s.response(f2)
     await asyncio.sleep(1.0)
     rows = s.db_store.con.execute(
         "SELECT type_id, content FROM body WHERE body.flow_id == (?);", [f.id]
     ).fetchall()
     assert len(rows) == 1
     rows = s.db_store.con.execute(
         "SELECT type_id, content FROM body WHERE body.flow_id == (?);", [f2.id]
     ).fetchall()
     assert len(rows) == 1
     assert s.db_store.body_ledger == {f.id}
     assert all([lf.__dict__ == rf.__dict__ for lf, rf in list(zip(s.load_view(), [f, f2]))])
开发者ID:mitmproxy,项目名称:mitmproxy,代码行数:33,代码来源:test_session.py


示例2: test_eq

    def test_eq(self):
        data = tutils.tresp(timestamp_start=42, timestamp_end=42).data
        same = tutils.tresp(timestamp_start=42, timestamp_end=42).data
        assert data == same

        other = tutils.tresp(content=b"foo").data
        assert data != other

        assert data != 0
开发者ID:mitmproxy,项目名称:mitmproxy,代码行数:9,代码来源:test_message.py


示例3: test_eq_ne

    def test_eq_ne(self):
        resp = tutils.tresp(timestamp_start=42, timestamp_end=42)
        same = tutils.tresp(timestamp_start=42, timestamp_end=42)
        assert resp == same

        other = tutils.tresp(timestamp_start=0, timestamp_end=0)
        assert resp != other

        assert resp != 0
开发者ID:mitmproxy,项目名称:mitmproxy,代码行数:9,代码来源:test_message.py


示例4: test_expected_http_body_size

def test_expected_http_body_size():
    # Expect: 100-continue
    assert expected_http_body_size(
        treq(headers=Headers(expect="100-continue", content_length="42"))
    ) == 0

    # http://tools.ietf.org/html/rfc7230#section-3.3
    assert expected_http_body_size(
        treq(method=b"HEAD"),
        tresp(headers=Headers(content_length="42"))
    ) == 0
    assert expected_http_body_size(
        treq(method=b"CONNECT"),
        tresp()
    ) == 0
    for code in (100, 204, 304):
        assert expected_http_body_size(
            treq(),
            tresp(status_code=code)
        ) == 0

    # chunked
    assert expected_http_body_size(
        treq(headers=Headers(transfer_encoding="chunked")),
    ) is None

    # explicit length
    for val in (b"foo", b"-7"):
        with pytest.raises(exceptions.HttpSyntaxException):
            expected_http_body_size(
                treq(headers=Headers(content_length=val))
            )
    assert expected_http_body_size(
        treq(headers=Headers(content_length="42"))
    ) == 42

    # more than 1 content-length headers with same value
    assert expected_http_body_size(
        treq(headers=Headers([(b'content-length', b'42'), (b'content-length', b'42')]))
    ) == 42

    # more than 1 content-length headers with conflicting value
    with pytest.raises(exceptions.HttpSyntaxException):
        expected_http_body_size(
            treq(headers=Headers([(b'content-length', b'42'), (b'content-length', b'45')]))
        )

    # no length
    assert expected_http_body_size(
        treq(headers=Headers())
    ) == 0
    assert expected_http_body_size(
        treq(headers=Headers()), tresp(headers=Headers())
    ) == -1
开发者ID:StevenVanAcker,项目名称:mitmproxy,代码行数:54,代码来源:test_read.py


示例5: test_assemble_response

def test_assemble_response():
    assert assemble_response(tresp()) == (
        b"HTTP/1.1 200 OK\r\n"
        b"header-response: svalue\r\n"
        b"content-length: 7\r\n"
        b"\r\n"
        b"message"
    )

    with raises(exceptions.HttpException):
        assemble_response(tresp(content=None))
开发者ID:MatthewShao,项目名称:mitmproxy,代码行数:11,代码来源:test_assemble.py


示例6: test_init

    def test_init(self):
        with pytest.raises(ValueError):
            tresp(headers="foobar")
        with pytest.raises(UnicodeEncodeError):
            tresp(http_version="föö/bä.r")
        with pytest.raises(UnicodeEncodeError):
            tresp(reason="fööbär")
        with pytest.raises(ValueError):
            tresp(content="foobar")

        assert isinstance(tresp(headers=()).headers, Headers)
开发者ID:StevenVanAcker,项目名称:mitmproxy,代码行数:11,代码来源:test_response.py


示例7: test_update_content_length_header

 def test_update_content_length_header(self):
     r = tutils.tresp()
     assert int(r.headers["content-length"]) == 7
     r.encode("gzip")
     assert int(r.headers["content-length"]) == 27
     r.decode()
     assert int(r.headers["content-length"]) == 7
开发者ID:mitmproxy,项目名称:mitmproxy,代码行数:7,代码来源:test_message.py


示例8: test_response

 def test_response(self, get_request_invuln, logger):
     mocked_flow = tflow.tflow(
         req=tutils.treq(path=b"index.html?q=1"),
         resp=tutils.tresp(content=b'<html></html>')
     )
     xss.response(mocked_flow)
     assert logger.args == []
开发者ID:mitmproxy,项目名称:mitmproxy,代码行数:7,代码来源:test_xss_scanner.py


示例9: test_none

 def test_none(self):
     r = tutils.tresp(content=None)
     assert r.text is None
     r.text = u"foo"
     assert r.text is not None
     r.text = None
     assert r.text is None
开发者ID:mitmproxy,项目名称:mitmproxy,代码行数:7,代码来源:test_message.py


示例10: test_response

 def test_response(self, monkeypatch, logger):
     logger.args = []
     monkeypatch.setattr("mitmproxy.ctx.log", logger)
     monkeypatch.setattr(requests, 'get', self.mocked_requests_invuln)
     mocked_flow = tflow.tflow(req=tutils.treq(path=b"index.html?q=1"), resp=tutils.tresp(content=b'<html></html>'))
     xss.response(mocked_flow)
     assert logger.args == []
开发者ID:cortesi,项目名称:mitmproxy,代码行数:7,代码来源:test_xss_scanner.py


示例11: test_get_cookies_simple

 def test_get_cookies_simple(self):
     resp = tresp()
     resp.headers = Headers(set_cookie="cookiename=cookievalue")
     result = resp.cookies
     assert len(result) == 1
     assert "cookiename" in result
     assert result["cookiename"] == ("cookievalue", CookieAttrs())
开发者ID:StevenVanAcker,项目名称:mitmproxy,代码行数:7,代码来源:test_response.py


示例12: test_storage_flush_with_specials

    async def test_storage_flush_with_specials(self):
        s = self.start_session(fp=0.5)
        f = self.tft()
        s.request(f)
        await asyncio.sleep(1)
        assert len(s._hot_store) == 0
        f.response = http.HTTPResponse.wrap(tutils.tresp())
        s.response(f)
        assert len(s._hot_store) == 1
        assert s.load_storage() == [f]
        await asyncio.sleep(1)
        assert all([lflow.__dict__ == flow.__dict__ for lflow, flow in list(zip(s.load_storage(), [f]))])

        f.server_conn.via = tflow.tserver_conn()
        s.request(f)
        await asyncio.sleep(0.6)
        assert len(s._hot_store) == 0
        assert all([lflow.__dict__ == flow.__dict__ for lflow, flow in list(zip(s.load_storage(), [f]))])

        flows = [self.tft() for _ in range(500)]
        s.update(flows)
        await asyncio.sleep(0.6)
        assert s._flush_period == s._FP_DEFAULT * s._FP_DECREMENT
        await asyncio.sleep(3)
        assert s._flush_period == s._FP_DEFAULT
开发者ID:mitmproxy,项目名称:mitmproxy,代码行数:25,代码来源:test_session.py


示例13: tflow

def tflow(client_conn=True, server_conn=True, req=True, resp=None, err=None):
    """
    @type client_conn: bool | None | mitmproxy.proxy.connection.ClientConnection
    @type server_conn: bool | None | mitmproxy.proxy.connection.ServerConnection
    @type req:         bool | None | mitmproxy.proxy.protocol.http.HTTPRequest
    @type resp:        bool | None | mitmproxy.proxy.protocol.http.HTTPResponse
    @type err:         bool | None | mitmproxy.proxy.protocol.primitives.Error
    @return:           mitmproxy.proxy.protocol.http.HTTPFlow
    """
    if client_conn is True:
        client_conn = tclient_conn()
    if server_conn is True:
        server_conn = tserver_conn()
    if req is True:
        req = tutils.treq()
    if resp is True:
        resp = tutils.tresp()
    if err is True:
        err = terr()

    if req:
        req = http.HTTPRequest.wrap(req)
    if resp:
        resp = http.HTTPResponse.wrap(resp)

    f = http.HTTPFlow(client_conn, server_conn)
    f.request = req
    f.response = resp
    f.error = err
    f.reply = controller.DummyReply()
    return f
开发者ID:dwfreed,项目名称:mitmproxy,代码行数:31,代码来源:tflow.py


示例14: test_unknown_ce

 def test_unknown_ce(self):
     r = tutils.tresp()
     r.headers["content-type"] = "text/html; charset=wtf"
     r.raw_content = b"foo"
     with pytest.raises(ValueError):
         assert r.text == u"foo"
     assert r.get_text(strict=False) == u"foo"
开发者ID:mitmproxy,项目名称:mitmproxy,代码行数:7,代码来源:test_message.py


示例15: test_set_cookies

 def test_set_cookies(self):
     resp = tresp()
     resp.cookies["foo"] = ("bar", {})
     assert len(resp.cookies) == 1
     assert resp.cookies["foo"] == ("bar", CookieAttrs())
     resp.cookies = [["one", ("uno", CookieAttrs())], ["two", ("due", CookieAttrs())]]
     assert list(resp.cookies.keys()) == ["one", "two"]
开发者ID:StevenVanAcker,项目名称:mitmproxy,代码行数:7,代码来源:test_response.py


示例16: test_cannot_encode

    def test_cannot_encode(self):
        r = tutils.tresp()
        r.content = None
        assert "content-type" not in r.headers
        assert r.raw_content is None

        r.headers["content-type"] = "text/html; charset=latin1; foo=bar"
        r.text = u"☃"
        assert r.headers["content-type"] == "text/html; charset=utf-8; foo=bar"
        assert r.raw_content == b'\xe2\x98\x83'

        r.headers["content-type"] = "gibberish"
        r.text = u"☃"
        assert r.headers["content-type"] == "text/plain; charset=utf-8"
        assert r.raw_content == b'\xe2\x98\x83'

        del r.headers["content-type"]
        r.text = u"☃"
        assert r.headers["content-type"] == "text/plain; charset=utf-8"
        assert r.raw_content == b'\xe2\x98\x83'

        r.headers["content-type"] = "text/html; charset=latin1"
        r.text = u'\udcff'
        assert r.headers["content-type"] == "text/html; charset=utf-8"
        assert r.raw_content == b"\xFF"
开发者ID:mitmproxy,项目名称:mitmproxy,代码行数:25,代码来源:test_message.py


示例17: test_unknown_ce

 def test_unknown_ce(self):
     r = tutils.tresp()
     r.headers["content-encoding"] = "zopfli"
     r.raw_content = b"foo"
     with tutils.raises(ValueError):
         assert r.content
     assert r.headers["content-encoding"]
     assert r.get_content(strict=False) == b"foo"
开发者ID:MatthewShao,项目名称:mitmproxy,代码行数:8,代码来源:test_message.py


示例18: test_cannot_decode

    def test_cannot_decode(self):
        r = tutils.tresp()
        r.headers["content-type"] = "text/html; charset=utf8"
        r.raw_content = b"\xFF"
        with pytest.raises(ValueError):
            assert r.text

        assert r.get_text(strict=False) == '\udcff'
开发者ID:mitmproxy,项目名称:mitmproxy,代码行数:8,代码来源:test_message.py


示例19: test_get_cookies_no_value

 def test_get_cookies_no_value(self):
     resp = tresp()
     resp.headers = Headers(set_cookie="cookiename=; Expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/")
     result = resp.cookies
     assert len(result) == 1
     assert "cookiename" in result
     assert result["cookiename"][0] == ""
     assert len(result["cookiename"][1]) == 2
开发者ID:StevenVanAcker,项目名称:mitmproxy,代码行数:8,代码来源:test_response.py


示例20: test_utf8_as_ce

 def test_utf8_as_ce(self):
     r = tutils.tresp()
     r.headers["content-encoding"] = "utf8"
     r.raw_content = b"foo"
     with pytest.raises(ValueError):
         assert r.content
     assert r.headers["content-encoding"]
     assert r.get_content(strict=False) == b"foo"
开发者ID:mitmproxy,项目名称:mitmproxy,代码行数:8,代码来源:test_message.py



注:本文中的mitmproxy.test.tutils.tresp函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python strutils.bytes_to_escaped_str函数代码示例发布时间:2022-05-27
下一篇:
Python tutils.treq函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap