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/utils.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'libmproxy/utils.py') diff --git a/libmproxy/utils.py b/libmproxy/utils.py index 9ac9c0b8..3dbeb620 100644 --- a/libmproxy/utils.py +++ b/libmproxy/utils.py @@ -1,15 +1,15 @@ # Copyright (C) 2010 Aldo Cortesi -# +# # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. -# +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -# +# # You should have received a copy of the GNU General Public License # along with this program. If not, see . import re, os, subprocess, datetime, textwrap, errno @@ -67,7 +67,7 @@ def cleanBin(s): if i not in "\n\r\t": parts.append(".") return "".join(parts) - + TAG = r""" <\s* @@ -279,16 +279,16 @@ class Headers: ret.append([name, value]) self.lst = ret - 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 header keys - and values. Returns the number of replacements made. + and values. Returns the number of replacements made. """ nlst, count = [], 0 for i in self.lst: - k, c = re.subn(pattern, repl, i[0], count, flags) + k, c = re.subn(pattern, repl, i[0], *args, **kwargs) count += c - v, c = re.subn(pattern, repl, i[1], count, flags) + v, c = re.subn(pattern, repl, i[1], *args, **kwargs) count += c nlst.append([k, v]) self.lst = nlst -- cgit v1.2.3