aboutsummaryrefslogtreecommitdiffstats
path: root/netlib
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2016-07-01 14:10:48 -0700
committerMaximilian Hils <git@maximilianhils.com>2016-07-01 14:10:48 -0700
commit536c7acd13426d42dc863ae8b50e6c3a4cb2e858 (patch)
treee868530aef8353273a3107b57645fd5b02e717b0 /netlib
parente0ed7699ca1258414a99812720f168e14a6ca219 (diff)
downloadmitmproxy-536c7acd13426d42dc863ae8b50e6c3a4cb2e858.tar.gz
mitmproxy-536c7acd13426d42dc863ae8b50e6c3a4cb2e858.tar.bz2
mitmproxy-536c7acd13426d42dc863ae8b50e6c3a4cb2e858.zip
py3++
Diffstat (limited to 'netlib')
-rw-r--r--netlib/http/headers.py6
-rw-r--r--netlib/http/message.py8
-rw-r--r--netlib/http/request.py10
-rw-r--r--netlib/strutils.py10
4 files changed, 17 insertions, 17 deletions
diff --git a/netlib/http/headers.py b/netlib/http/headers.py
index 14888ea9..f052a53b 100644
--- a/netlib/http/headers.py
+++ b/netlib/http/headers.py
@@ -156,8 +156,10 @@ class Headers(multidict.MultiDict):
Returns:
The number of replacements made.
"""
- pattern = _always_bytes(pattern)
- repl = _always_bytes(repl)
+ if isinstance(pattern, six.text_type):
+ pattern = strutils.escaped_str_to_bytes(pattern)
+ if isinstance(repl, six.text_type):
+ repl = strutils.escaped_str_to_bytes(repl)
pattern = re.compile(pattern, flags)
replacements = 0
diff --git a/netlib/http/message.py b/netlib/http/message.py
index b633b671..0583c246 100644
--- a/netlib/http/message.py
+++ b/netlib/http/message.py
@@ -1,5 +1,6 @@
from __future__ import absolute_import, print_function, division
+import re
import warnings
import six
@@ -196,11 +197,14 @@ class Message(basetypes.Serializable):
Returns:
The number of replacements made.
"""
- # TODO: Proper distinction between text and bytes.
+ if isinstance(pattern, six.text_type):
+ pattern = strutils.escaped_str_to_bytes(pattern)
+ if isinstance(repl, six.text_type):
+ repl = strutils.escaped_str_to_bytes(repl)
replacements = 0
if self.content:
with decoded(self):
- self.content, replacements = strutils.safe_subn(
+ self.content, replacements = re.subn(
pattern, repl, self.content, flags=flags
)
replacements += self.headers.replace(pattern, repl, flags)
diff --git a/netlib/http/request.py b/netlib/http/request.py
index b64ccc51..ff057b79 100644
--- a/netlib/http/request.py
+++ b/netlib/http/request.py
@@ -65,10 +65,14 @@ class Request(message.Message):
Returns:
The number of replacements made.
"""
- # TODO: Proper distinction between text and bytes.
+ if isinstance(pattern, six.text_type):
+ pattern = strutils.escaped_str_to_bytes(pattern)
+ if isinstance(repl, six.text_type):
+ repl = strutils.escaped_str_to_bytes(repl)
+
c = super(Request, self).replace(pattern, repl, flags)
- self.path, pc = strutils.safe_subn(
- pattern, repl, self.path, flags=flags
+ self.path, pc = re.subn(
+ pattern, repl, self.data.path, flags=flags
)
c += pc
return c
diff --git a/netlib/strutils.py b/netlib/strutils.py
index 5ad41c7e..ca6eaa42 100644
--- a/netlib/strutils.py
+++ b/netlib/strutils.py
@@ -1,4 +1,3 @@
-import re
import unicodedata
import codecs
@@ -56,15 +55,6 @@ def clean_bin(s, keep_spacing=True):
)
-def safe_subn(pattern, repl, target, *args, **kwargs):
- """
- There are Unicode conversion problems with re.subn. We try to smooth
- that over by casting the pattern and replacement to strings. We really
- need a better solution that is aware of the actual content ecoding.
- """
- return re.subn(str(pattern), str(repl), target, *args, **kwargs)
-
-
def bytes_to_escaped_str(data):
"""
Take bytes and return a safe string that can be displayed to the user.