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


Python filt.parse函数代码示例

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


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

示例1: test_binaryops

    def test_binaryops(self):
        a = filt.parse("~u foobar | ~h voing")
        isinstance(a, filt.FOr)
        self._dump(a)

        a = filt.parse("~u foobar & ~h voing")
        isinstance(a, filt.FAnd)
        self._dump(a)
开发者ID:AlTune,项目名称:mitmproxy,代码行数:8,代码来源:test_filt.py

示例2: test_quoting

    def test_quoting(self):
        a = filt.parse("~u 'foo ~u bar' ~u voing")
        assert a.lst[0].expr == "foo ~u bar"
        assert a.lst[1].expr == "voing"
        self._dump(a)

        a = filt.parse("~u foobar")
        assert a.expr == "foobar"

        a = filt.parse(r"~u 'foobar\"\''")
        assert a.expr == "foobar\"'"

        a = filt.parse(r'~u "foo \'bar"')
        assert a.expr == "foo 'bar"
开发者ID:AlTune,项目名称:mitmproxy,代码行数:14,代码来源:test_filt.py

示例3: __init__

    def __init__(self, server, options):
        flow.FlowMaster.__init__(self, options, server, flow.State())
        self.addons.add(*builtins.default_addons())
        # This line is just for type hinting
        self.options = self.options  # type: Options
        self.o = options
        self.showhost = options.showhost
        self.replay_ignore_params = options.replay_ignore_params
        self.replay_ignore_content = options.replay_ignore_content
        self.replay_ignore_host = options.replay_ignore_host
        self.refresh_server_playback = options.refresh_server_playback
        self.replay_ignore_payload_params = options.replay_ignore_payload_params

        self.set_stream_large_bodies(options.stream_large_bodies)

        if self.server and self.server.config.http2 and not tcp.HAS_ALPN:  # pragma: no cover
            print("ALPN support missing (OpenSSL 1.0.2+ required)!\n"
                  "HTTP/2 is disabled. Use --no-http2 to silence this warning.",
                  file=sys.stderr)

        if options.filtstr:
            self.filt = filt.parse(options.filtstr)
        else:
            self.filt = None

        if options.replacements:
            for i in options.replacements:
                self.replacehooks.add(*i)

        if options.setheaders:
            for i in options.setheaders:
                self.setheaders.add(*i)

        if options.server_replay:
            self.start_server_playback(
                self._readflow(options.server_replay),
                options.kill, options.rheaders,
                not options.keepserving,
                options.nopop,
                options.replay_ignore_params,
                options.replay_ignore_content,
                options.replay_ignore_payload_params,
                options.replay_ignore_host
            )

        if options.client_replay:
            self.start_client_playback(
                self._readflow(options.client_replay),
                not options.keepserving
            )

        if options.rfile:
            try:
                self.load_flows_file(options.rfile)
            except exceptions.FlowReadException as v:
                self.add_event("Flow file corrupted.", "error")
                raise DumpError(v)

        if self.options.app:
            self.start_app(self.options.app_host, self.options.app_port)
开发者ID:HuangGuoZhou,项目名称:mitmproxy,代码行数:60,代码来源:dump.py

示例4: set_intercept

 def set_intercept(self, txt):
     if txt:
         f = filt.parse(txt)
         if not f:
             return "Invalid filter expression."
         self.intercept = f
     else:
         self.intercept = None
开发者ID:AlTune,项目名称:mitmproxy,代码行数:8,代码来源:state.py

示例5: configure

 def configure(self, options):
     if options.stickyauth:
         flt = filt.parse(options.stickyauth)
         if not flt:
             raise exceptions.OptionsError(
                 "stickyauth: invalid filter expression: %s" % options.stickyauth
             )
         self.flt = flt
开发者ID:DrakeCaraker,项目名称:mitmproxy,代码行数:8,代码来源:stickyauth.py

示例6: configure

 def configure(self, options, updated):
     if options.stickycookie:
         flt = filt.parse(options.stickycookie)
         if not flt:
             raise exceptions.OptionsError(
                 "stickycookie: invalid filter expression: %s" % options.stickycookie
             )
         self.flt = flt
开发者ID:Angelcold,项目名称:mitmproxy,代码行数:8,代码来源:stickycookie.py

示例7: test_handle_response

    def test_handle_response(self):
        s = flow.StickyAuthState(filt.parse(".*"))
        f = tutils.tflow(resp=True)
        f.request.headers["authorization"] = "foo"
        s.handle_request(f)
        assert "address" in s.hosts

        f = tutils.tflow(resp=True)
        s.handle_request(f)
        assert f.request.headers["authorization"] == "foo"
开发者ID:Amerge,项目名称:mitmproxy,代码行数:10,代码来源:test_flow.py

示例8: set_stickyauth

 def set_stickyauth(self, txt):
     if txt:
         flt = filt.parse(txt)
         if not flt:
             return "Invalid filter expression."
         self.stickyauth_state = modules.StickyAuthState(flt)
         self.stickyauth_txt = txt
     else:
         self.stickyauth_state = None
         self.stickyauth_txt = None
开发者ID:AlTune,项目名称:mitmproxy,代码行数:10,代码来源:master.py

示例9: is_error

 def is_error(self, col, val):
     if col == 0:
         if not filt.parse(val):
             return "Invalid filter specification."
     elif col == 1:
         try:
             re.compile(val)
         except re.error:
             return "Invalid regular expression."
     return False
开发者ID:Angelcold,项目名称:mitmproxy,代码行数:10,代码来源:editors.py

示例10: test_simple

 def test_simple(self):
     assert not filt.parse("~b")
     assert filt.parse("~q")
     assert filt.parse("~c 10")
     assert filt.parse("~m foobar")
     assert filt.parse("~u foobar")
     assert filt.parse("~q ~c 10")
     p = filt.parse("~q ~c 10")
     self._dump(p)
     assert len(p.lst) == 2
开发者ID:AlTune,项目名称:mitmproxy,代码行数:10,代码来源:test_filt.py

示例11: set_limit

 def set_limit(self, txt):
     if txt == self.limit_txt:
         return
     if txt:
         f = filt.parse(txt)
         if not f:
             return "Invalid filter expression."
         self.view._close()
         self.view = FlowView(self.flows, f)
     else:
         self.view._close()
         self.view = FlowView(self.flows, None)
开发者ID:AlTune,项目名称:mitmproxy,代码行数:12,代码来源:state.py

示例12: configure

 def configure(self, options, updated):
     if options.filtstr:
         self.filter = filt.parse(options.filtstr)
         if not self.filter:
             raise exceptions.OptionsError(
                 "Invalid filter expression: %s" % options.filtstr
             )
     else:
         self.filter = None
     self.flow_detail = options.flow_detail
     self.outfp = options.tfile
     self.showhost = options.showhost
开发者ID:guangshi1982,项目名称:mitmproxy,代码行数:12,代码来源:dumper.py

示例13: configure

    def configure(self, options, updated):
        """
            options.setheaders is a tuple of (fpatt, header, value)

            fpatt: String specifying a filter pattern.
            header: Header name.
            value: Header value string
        """
        for fpatt, header, value in options.setheaders:
            cpatt = filt.parse(fpatt)
            if not cpatt:
                raise exceptions.OptionsError(
                    "Invalid setheader filter pattern %s" % fpatt
                )
            self.lst.append((fpatt, header, value, cpatt))
开发者ID:Angelcold,项目名称:mitmproxy,代码行数:15,代码来源:setheaders.py

示例14: test_response

    def test_response(self):
        c = (
            "SSID=mooo; domain=.google.com, FOO=bar; Domain=.google.com; Path=/; "
            "Expires=Wed, 13-Jan-2021 22:23:01 GMT; Secure; "
        )

        s, f = self._response(c, "host")
        assert not s.jar.keys()

        s, f = self._response(c, "www.google.com")
        assert list(s.jar.keys())[0] == ('.google.com', 80, '/')

        s, f = self._response("SSID=mooo", "www.google.com")
        assert list(s.jar.keys())[0] == ('www.google.com', 80, '/')

        # Test setting of multiple cookies
        c1 = "somecookie=test; Path=/"
        c2 = "othercookie=helloworld; Path=/"
        s, f = self._response(c1, "www.google.com")
        f.response.headers["Set-Cookie"] = c2
        s.handle_response(f)
        googlekey = list(s.jar.keys())[0]
        assert len(s.jar[googlekey].keys()) == 2

        # Test setting of weird cookie keys
        s = flow.StickyCookieState(filt.parse(".*"))
        f = tutils.tflow(req=netlib.tutils.treq(host="www.google.com", port=80), resp=True)
        cs = [
            "foo/bar=hello",
            "foo:bar=world",
            "[email protected]=fizz",
            "foo,bar=buzz",
        ]
        for c in cs:
            f.response.headers["Set-Cookie"] = c
            s.handle_response(f)
        googlekey = list(s.jar.keys())[0]
        assert len(s.jar[googlekey]) == len(cs)

        # Test overwriting of a cookie value
        c1 = "somecookie=helloworld; Path=/"
        c2 = "somecookie=newvalue; Path=/"
        s, f = self._response(c1, "www.google.com")
        f.response.headers["Set-Cookie"] = c2
        s.handle_response(f)
        googlekey = list(s.jar.keys())[0]
        assert len(s.jar[googlekey]) == 1
        assert list(s.jar[googlekey]["somecookie"].values())[0] == "newvalue"
开发者ID:christofferqa,项目名称:mitmproxy,代码行数:48,代码来源:test_flow.py

示例15: test_filter

    def test_filter(self):
        sio = StringIO()
        fl = filt.parse("~c 200")
        w = flow.FilteredFlowWriter(sio, fl)

        f = tutils.tflow(resp=True)
        f.response.status_code = 200
        w.add(f)

        f = tutils.tflow(resp=True)
        f.response.status_code = 201
        w.add(f)

        sio.seek(0)
        r = flow.FlowReader(sio)
        assert len(list(r.stream()))
开发者ID:Amerge,项目名称:mitmproxy,代码行数:16,代码来源:test_flow.py


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