From 78049abac123332123990994b50a70bc789b7514 Mon Sep 17 00:00:00 2001 From: Stephen Altamirano Date: Tue, 26 Jul 2011 22:47:08 -0700 Subject: Changes replace logic to function in both Python 2.6.x and 2.7.x Tests now only assume Python 2.6.x rather than requiring 2.7.x. This does not preclude the use of flags as a kwarg in replace --- libmproxy/proxy.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'libmproxy/proxy.py') diff --git a/libmproxy/proxy.py b/libmproxy/proxy.py index 8d2888a4..e765d8b6 100644 --- a/libmproxy/proxy.py +++ b/libmproxy/proxy.py @@ -280,16 +280,16 @@ class Request(controller.Msg): else: return self.FMT_PROXY % (self.method, self.scheme, self.host, self.port, self.path, str(headers), content) - def replace(self, pattern, repl, count=0, flags=0): + def replace(self, pattern, repl, *args, **kwargs): """ Replaces a regular expression pattern with repl in both the headers and the body of the request. Returns the number of replacements - made. + made. """ - self.content, c = re.subn(pattern, repl, self.content, count, flags) - self.path, pc = re.subn(pattern, repl, self.path, count, flags) + self.content, c = re.subn(pattern, repl, self.content, *args, **kwargs) + self.path, pc = re.subn(pattern, repl, self.path, *args, **kwargs) c += pc - c += self.headers.replace(pattern, repl, count, flags) + c += self.headers.replace(pattern, repl, *args, **kwargs) return c @@ -418,14 +418,14 @@ class Response(controller.Msg): data = (proto, str(headers), content) return self.FMT%data - def replace(self, pattern, repl, count=0, flags=0): + def replace(self, pattern, repl, *args, **kwargs): """ Replaces a regular expression pattern with repl in both the headers and the body of the response. Returns the number of replacements - made. + made. """ - self.content, c = re.subn(pattern, repl, self.content, count, flags) - c += self.headers.replace(pattern, repl, count, flags) + self.content, c = re.subn(pattern, repl, self.content, *args, **kwargs) + c += self.headers.replace(pattern, repl, *args, **kwargs) return c @@ -497,13 +497,13 @@ class Error(controller.Msg): def __eq__(self, other): return self.get_state() == other.get_state() - def replace(self, pattern, repl, count=0, flags=0): + def replace(self, pattern, repl, *args, **kwargs): """ Replaces a regular expression pattern with repl in both the headers and the body of the request. Returns the number of replacements - made. + made. """ - self.msg, c = re.subn(pattern, repl, self.msg, count, flags) + self.msg, c = re.subn(pattern, repl, self.msg, *args, **kwargs) return c -- cgit v1.2.3