当前位置: 首页>>代码示例>>Python>>正文


Python tutils.treq函数代码示例

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


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

示例1: test_flow

    def test_flow(self):
        """
            normal flow:

                connect -> request -> response
        """
        bc = tutils.tclient_conn()
        c = flow.State()

        req = tutils.treq(bc)
        f = c.add_request(req)
        assert f
        assert c.flow_count() == 1
        assert c.active_flow_count() == 1

        newreq = tutils.treq()
        assert c.add_request(newreq)
        assert c.active_flow_count() == 2

        resp = tutils.tresp(req)
        assert c.add_response(resp)
        assert c.flow_count() == 2
        assert c.active_flow_count() == 1

        unseen_resp = tutils.tresp()
        unseen_resp.flow = None
        assert not c.add_response(unseen_resp)
        assert c.active_flow_count() == 1

        resp = tutils.tresp(newreq)
        assert c.add_response(resp)
        assert c.active_flow_count() == 0
开发者ID:Jamie-Landeg-Jones,项目名称:mitmproxy,代码行数:32,代码来源:test_flow.py

示例2: test_flow

    def test_flow(self):
        """
            normal flow:

                connect -> request -> response
        """
        bc = flow.ClientConnect(("address", 22))
        c = flow.State()

        req = tutils.treq(bc)
        f = c.add_request(req)
        assert f
        assert c.flow_count() == 1
        assert c._flow_map.get(req)
        assert c.active_flow_count() == 1

        newreq = tutils.treq()
        assert c.add_request(newreq)
        assert c._flow_map.get(newreq)
        assert c.active_flow_count() == 2

        resp = tutils.tresp(req)
        assert c.add_response(resp)
        assert c.flow_count() == 2
        assert c._flow_map.get(resp.request)
        assert c.active_flow_count() == 1

        unseen_resp = tutils.tresp()
        assert not c.add_response(unseen_resp)
        assert not c._flow_map.get(unseen_resp.request)
        assert c.active_flow_count() == 1

        resp = tutils.tresp(newreq)
        assert c.add_response(resp)
        assert c.active_flow_count() == 0
开发者ID:alxsoares,项目名称:mitmproxy,代码行数:35,代码来源:test_flow.py

示例3: test_set_limit

    def test_set_limit(self):
        c = flow.State()

        req = tutils.treq()
        assert len(c.view) == 0

        c.add_request(req)
        assert len(c.view) == 1

        c.set_limit("~s")
        assert c.limit_txt == "~s"
        assert len(c.view) == 0
        resp = tutils.tresp(req)
        c.add_response(resp)
        assert len(c.view) == 1
        c.set_limit(None)
        assert len(c.view) == 1

        req = tutils.treq()
        c.add_request(req)
        assert len(c.view) == 2
        c.set_limit("~q")
        assert len(c.view) == 1
        c.set_limit("~s")
        assert len(c.view) == 1

        assert "Invalid" in c.set_limit("~")
开发者ID:alxsoares,项目名称:mitmproxy,代码行数:27,代码来源:test_flow.py

示例4: test_set_limit

    def test_set_limit(self):
        c = flow.State()

        req = tutils.treq()
        c.clientconnect(req.client_conn)
        assert len(c.view) == 0

        f = c.add_request(req)
        assert len(c.view) == 1

        c.set_limit("~s")
        assert len(c.view) == 0
        resp = tutils.tresp(req)
        c.add_response(resp)
        assert len(c.view) == 1
        c.set_limit(None)
        assert len(c.view) == 1

        req = tutils.treq()
        c.clientconnect(req.client_conn)
        c.add_request(req)
        assert len(c.view) == 2
        c.set_limit("~q")
        assert len(c.view) == 1
        c.set_limit("~s")
        assert len(c.view) == 1

        assert "Invalid" in c.set_limit("~")
开发者ID:xuzhe,项目名称:mitmproxy,代码行数:28,代码来源:test_flow.py

示例5: test_decodeencode

    def test_decodeencode(self):
        r = tutils.treq()
        r.headers["content-encoding"] = ["identity"]
        r.content = "falafel"
        r.decode()
        assert not r.headers["content-encoding"]
        assert r.content == "falafel"

        r = tutils.treq()
        r.content = "falafel"
        assert not r.decode()

        r = tutils.treq()
        r.headers["content-encoding"] = ["identity"]
        r.content = "falafel"
        r.encode("identity")
        assert r.headers["content-encoding"] == ["identity"]
        assert r.content == "falafel"

        r = tutils.treq()
        r.headers["content-encoding"] = ["identity"]
        r.content = "falafel"
        r.encode("gzip")
        assert r.headers["content-encoding"] == ["gzip"]
        assert r.content != "falafel"
        r.decode()
        assert not r.headers["content-encoding"]
        assert r.content == "falafel"
开发者ID:alxsoares,项目名称:mitmproxy,代码行数:28,代码来源:test_flow.py

示例6: test_killall

    def test_killall(self):
        s = flow.State()
        fm = flow.FlowMaster(None, s)

        r = tutils.treq()
        fm.handle_request(r)

        r = tutils.treq()
        fm.handle_request(r)

        for i in s.view:
            assert not i.request.acked
        s.killall(fm)
        for i in s.view:
            assert i.request.acked
开发者ID:alxsoares,项目名称:mitmproxy,代码行数:15,代码来源:test_flow.py

示例7: test_script

 def test_script(self):
     s = flow.State()
     fm = flow.FlowMaster(None, s)
     assert not fm.load_script([tutils.test_data.path("scripts/all.py")])
     req = tutils.treq()
     fm.handle_clientconnect(req.client_conn)
     assert fm.scripts[0].ns["log"][-1] == "clientconnect"
     f = fm.handle_request(req)
     assert fm.scripts[0].ns["log"][-1] == "request"
     resp = tutils.tresp(req)
     fm.handle_response(resp)
     assert fm.scripts[0].ns["log"][-1] == "response"
     #load second script
     assert not fm.load_script([tutils.test_data.path("scripts/all.py")])
     assert len(fm.scripts) == 2
     dc = flow.ClientDisconnect(req.client_conn)
     dc.reply = controller.DummyReply()
     fm.handle_clientdisconnect(dc)
     assert fm.scripts[0].ns["log"][-1] == "clientdisconnect"
     assert fm.scripts[1].ns["log"][-1] == "clientdisconnect"
     #unload first script
     fm.unload_script(fm.scripts[0])
     assert len(fm.scripts) == 1
     err = flow.Error(f.request, "msg")
     err.reply = controller.DummyReply()
     fm.handle_error(err)
     assert fm.scripts[0].ns["log"][-1] == "error"
开发者ID:billinghamj,项目名称:mitmproxy,代码行数:27,代码来源:test_flow.py

示例8: test_script_reqerr

 def test_script_reqerr(self):
     s = flow.State()
     fm = flow.FlowMaster(None, s)
     assert not fm.load_script(tutils.test_data.path("scripts/reqerr.py"))
     req = tutils.treq()
     fm.handle_clientconnect(req.client_conn)
     assert fm.handle_request(req)
开发者ID:alxsoares,项目名称:mitmproxy,代码行数:7,代码来源:test_flow.py

示例9: test_get_cert

    def test_get_cert(self):
        req = tutils.treq()
        resp = flow.Response(req, 200, "msg", flow.ODictCaseless(), "content", file("data/dercert").read())
        assert resp.get_cert()

        resp = tutils.tresp()
        assert not resp.get_cert()
开发者ID:rjmolesa,项目名称:mitmproxy,代码行数:7,代码来源:test_flow.py

示例10: test_backup

    def test_backup(self):
        c = flow.State()
        req = tutils.treq()
        f = c.add_request(req)

        f.backup()
        c.revert(f)
开发者ID:alxsoares,项目名称:mitmproxy,代码行数:7,代码来源:test_flow.py

示例11: test_all

    def test_all(self):
        s = flow.State()
        fm = flow.FlowMaster(None, s)
        fm.anticache = True
        fm.anticomp = True
        req = tutils.treq()
        fm.handle_clientconnect(req.client_conn)

        f = fm.handle_request(req)
        assert s.flow_count() == 1

        resp = tutils.tresp(req)
        fm.handle_response(resp)
        assert s.flow_count() == 1

        rx = tutils.tresp()
        assert not fm.handle_response(rx)

        dc = flow.ClientDisconnect(req.client_conn)
        req.client_conn.requestcount = 1
        fm.handle_clientdisconnect(dc)

        err = flow.Error(f.request, "msg")
        fm.handle_error(err)

        fm.load_script(tutils.test_data.path("scripts/a.py"))
        fm.shutdown()
开发者ID:alxsoares,项目名称:mitmproxy,代码行数:27,代码来源:test_flow.py

示例12: test_all

    def test_all(self):
        s = flow.State()
        fm = flow.FlowMaster(None, s)
        fm.anticache = True
        fm.anticomp = True
        req = tutils.treq()
        fm.handle_clientconnect(req.flow.client_conn)

        f = fm.handle_request(req)
        assert s.flow_count() == 1

        resp = tutils.tresp(req)
        fm.handle_response(resp)
        assert s.flow_count() == 1

        rx = tutils.tresp()
        rx.flow = None
        assert not fm.handle_response(rx)

        fm.handle_clientdisconnect(req.flow.client_conn)

        f.error = Error("msg")
        f.error.reply = controller.DummyReply()
        fm.handle_error(f.error)

        fm.load_script(tutils.test_data.path("scripts/a.py"))
        fm.shutdown()
开发者ID:Jamie-Landeg-Jones,项目名称:mitmproxy,代码行数:27,代码来源:test_flow.py

示例13: test_script

    def test_script(self):
        s = flow.State()
        fm = flow.FlowMaster(None, s)
        assert not fm.load_script(tutils.test_data.path("scripts/all.py"))
        req = tutils.treq()
        fm.handle_clientconnect(req.flow.client_conn)
        assert fm.scripts[0].ns["log"][-1] == "clientconnect"
        sc = ServerConnection((req.get_host(), req.get_port()), None)
        sc.reply = controller.DummyReply()
        fm.handle_serverconnection(sc)
        assert fm.scripts[0].ns["log"][-1] == "serverconnect"
        f = fm.handle_request(req)
        assert fm.scripts[0].ns["log"][-1] == "request"
        resp = tutils.tresp(req)
        fm.handle_response(resp)
        assert fm.scripts[0].ns["log"][-1] == "response"
        #load second script
        assert not fm.load_script(tutils.test_data.path("scripts/all.py"))
        assert len(fm.scripts) == 2
        fm.handle_clientdisconnect(sc)
        assert fm.scripts[0].ns["log"][-1] == "clientdisconnect"
        assert fm.scripts[1].ns["log"][-1] == "clientdisconnect"


        #unload first script
        fm.unload_scripts()
        assert len(fm.scripts) == 0

        assert not fm.load_script(tutils.test_data.path("scripts/all.py"))
        err = tutils.terr()
        err.reply = controller.DummyReply()
        fm.handle_error(err)
        assert fm.scripts[0].ns["log"][-1] == "error"
开发者ID:Jamie-Landeg-Jones,项目名称:mitmproxy,代码行数:33,代码来源:test_flow.py

示例14: test_header_size

 def test_header_size(self):
     h = flow.ODictCaseless()
     h["headername"] = ["headervalue"]
     r = tutils.treq()
     r.headers = h
     raw = r._assemble_headers()
     assert len(raw) == 62
开发者ID:AmineCherrai,项目名称:mitmproxy,代码行数:7,代码来源:test_flow.py

示例15: test_concurrent

    def test_concurrent(self):
        s = flow.State()
        fm = flow.FlowMaster(None, s)
        fm.load_script(tutils.test_data.path("scripts/concurrent_decorator.py"))

        with mock.patch("libmproxy.controller.DummyReply.__call__") as m:
            r1, r2 = tutils.treq(), tutils.treq()
            t_start = time.time()
            fm.handle_request(r1)
            r1.reply()
            fm.handle_request(r2)
            r2.reply()

            # Two instantiations
            assert m.call_count == 2
            assert (time.time() - t_start) < 0.09
开发者ID:Jamie-Landeg-Jones,项目名称:mitmproxy,代码行数:16,代码来源:test_script.py


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