Move match function to Flow

This commit is contained in:
Shadab Zafar 2016-07-21 12:59:52 +05:30
parent 4a3e9c0563
commit 6135ec1196
3 changed files with 20 additions and 40 deletions

View File

@ -8,6 +8,8 @@ from mitmproxy import stateobject
from mitmproxy.models.connections import ClientConnection from mitmproxy.models.connections import ClientConnection
from mitmproxy.models.connections import ServerConnection from mitmproxy.models.connections import ServerConnection
import six
from netlib import version from netlib import version
from typing import Optional # noqa from typing import Optional # noqa
@ -175,3 +177,21 @@ class Flow(stateobject.StateObject):
self.intercepted = False self.intercepted = False
self.reply.ack() self.reply.ack()
master.handle_accept_intercept(self) master.handle_accept_intercept(self)
def match(self, f):
"""
Match this flow against a compiled filter expression. Returns True
if matched, False if not.
If f is a string, it will be compiled as a filter expression. If
the expression is invalid, ValueError is raised.
"""
if isinstance(f, six.string_types):
from .. import filt
f = filt.parse(f)
if not f:
raise ValueError("Invalid filter expression.")
if f:
return f(self)
return True

View File

@ -2,7 +2,6 @@ from __future__ import absolute_import, print_function, division
import cgi import cgi
import warnings import warnings
import six
from mitmproxy.models.flow import Flow from mitmproxy.models.flow import Flow
from netlib import version from netlib import version
@ -211,24 +210,6 @@ class HTTPFlow(Flow):
f.response = self.response.copy() f.response = self.response.copy()
return f return f
def match(self, f):
"""
Match this flow against a compiled filter expression. Returns True
if matched, False if not.
If f is a string, it will be compiled as a filter expression. If
the expression is invalid, ValueError is raised.
"""
if isinstance(f, six.string_types):
from .. import filt
f = filt.parse(f)
if not f:
raise ValueError("Invalid filter expression.")
if f:
return f(self)
return True
def replace(self, pattern, repl, *args, **kwargs): def replace(self, pattern, repl, *args, **kwargs):
""" """
Replaces a regular expression pattern with repl in both request and Replaces a regular expression pattern with repl in both request and

View File

@ -7,8 +7,6 @@ from typing import List
import netlib.basetypes import netlib.basetypes
from mitmproxy.models.flow import Flow from mitmproxy.models.flow import Flow
import six
class TCPMessage(netlib.basetypes.Serializable): class TCPMessage(netlib.basetypes.Serializable):
@ -55,22 +53,3 @@ class TCPFlow(Flow):
def __repr__(self): def __repr__(self):
return "<TCPFlow ({} messages)>".format(len(self.messages)) return "<TCPFlow ({} messages)>".format(len(self.messages))
def match(self, f):
"""
Match this flow against a compiled filter expression. Returns True
if matched, False if not.
If f is a string, it will be compiled as a filter expression. If
the expression is invalid, ValueError is raised.
"""
if isinstance(f, six.string_types):
from .. import filt
f = filt.parse(f)
if not f:
raise ValueError("Invalid filter expression.")
if f:
return f(self)
return True