From db99da6af560f80bc169979f6d8681de3879acf2 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Wed, 2 Feb 2011 11:44:28 +1300 Subject: Improve script handling. - Display output in external viewer when script exits with error. - Add a "changed" indicator to show if a request can be reverted. --- libmproxy/flow.py | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) (limited to 'libmproxy/flow.py') diff --git a/libmproxy/flow.py b/libmproxy/flow.py index d3bba4b3..cf39bed9 100644 --- a/libmproxy/flow.py +++ b/libmproxy/flow.py @@ -6,7 +6,12 @@ import subprocess, base64, sys from contrib import bson import proxy, threading -class RunException(Exception): pass +class RunException(Exception): + def __init__(self, msg, returncode, errout): + Exception.__init__(self, msg) + self.returncode = returncode + self.errout = errout + class ReplayConnection: pass @@ -58,6 +63,7 @@ class Flow: Returns a (flow, stderr output) tuple, or raises RunException if there's an error. """ + self.backup() data = self.script_serialize() try: p = subprocess.Popen( @@ -67,13 +73,21 @@ class Flow: stderr=subprocess.PIPE, ) except OSError, e: - raise RunException(e.args[1]) + raise RunException(e.args[1], None, None) so, se = p.communicate(data) if p.returncode: - raise RunException("Script returned error code %s"%p.returncode) + raise RunException( + "Script returned error code %s"%p.returncode, + p.returncode, + se + ) f = Flow.script_deserialize(so) if not f: - raise RunException("Invalid response from script.") + raise RunException( + "Invalid response from script.", + p.returncode, + se + ) return f, se def dump(self): @@ -106,6 +120,14 @@ class Flow: def __eq__(self, other): return self.get_state() == other.get_state() + def modified(self): + # FIXME: Save a serialization in backup, compare current with + # backup to detect if flow has _really_ been modified. + if self._backup: + return True + else: + return False + def backup(self): if not self._backup: self._backup = [ @@ -119,6 +141,7 @@ class Flow: if self._backup: restore = [i.copy() if i else None for i in self._backup] self.connection, self.request, self.response, self.error = restore + self._backup = None def match(self, pattern): if pattern: -- cgit v1.2.3