From 821b97c19cc0ae2dc7e73dccffa80e31ed5414ff Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Sun, 17 Jul 2016 16:20:11 +1200 Subject: [PATCH] Remove old ReplaceHooks code --- mitmproxy/flow/__init__.py | 4 +-- mitmproxy/flow/modules.py | 53 -------------------------------------- 2 files changed, 2 insertions(+), 55 deletions(-) diff --git a/mitmproxy/flow/__init__.py b/mitmproxy/flow/__init__.py index caa175289..8f08bed7c 100644 --- a/mitmproxy/flow/__init__.py +++ b/mitmproxy/flow/__init__.py @@ -4,7 +4,7 @@ from mitmproxy.flow import export, modules from mitmproxy.flow.io import FlowWriter, FilteredFlowWriter, FlowReader, read_flows_from_paths from mitmproxy.flow.master import FlowMaster from mitmproxy.flow.modules import ( - AppRegistry, ReplaceHooks, SetHeaders, StreamLargeBodies, ClientPlaybackState, + AppRegistry, SetHeaders, StreamLargeBodies, ClientPlaybackState, ServerPlaybackState ) from mitmproxy.flow.state import State, FlowView @@ -16,7 +16,7 @@ __all__ = [ "export", "modules", "FlowWriter", "FilteredFlowWriter", "FlowReader", "read_flows_from_paths", "FlowMaster", - "AppRegistry", "ReplaceHooks", "SetHeaders", "StreamLargeBodies", "ClientPlaybackState", + "AppRegistry", "SetHeaders", "StreamLargeBodies", "ClientPlaybackState", "ServerPlaybackState", "State", "FlowView", "options", ] diff --git a/mitmproxy/flow/modules.py b/mitmproxy/flow/modules.py index d1f3dd42d..0ad392d2f 100644 --- a/mitmproxy/flow/modules.py +++ b/mitmproxy/flow/modules.py @@ -1,7 +1,6 @@ from __future__ import absolute_import, print_function, division import hashlib -import re from six.moves import urllib @@ -40,58 +39,6 @@ class AppRegistry: return self.apps.get((host, request.port), None) -class ReplaceHooks: - def __init__(self): - self.lst = [] - - def set(self, r): - self.clear() - for i in r: - self.add(*i) - - def add(self, fpatt, rex, s): - """ - add a replacement hook. - - fpatt: a string specifying a filter pattern. - rex: a regular expression. - s: the replacement string - - returns true if hook was added, false if the pattern could not be - parsed. - """ - cpatt = filt.parse(fpatt) - if not cpatt: - return False - try: - re.compile(rex) - except re.error: - return False - self.lst.append((fpatt, rex, s, cpatt)) - return True - - def get_specs(self): - """ - Retrieve the hook specifcations. Returns a list of (fpatt, rex, s) - tuples. - """ - return [i[:3] for i in self.lst] - - def count(self): - return len(self.lst) - - def run(self, f): - for _, rex, s, cpatt in self.lst: - if cpatt(f): - if f.response: - f.response.replace(rex, s) - else: - f.request.replace(rex, s) - - def clear(self): - self.lst = [] - - class SetHeaders: def __init__(self): self.lst = []