diff options
author | Maximilian Hils <git@maximilianhils.com> | 2016-04-03 08:17:30 -0700 |
---|---|---|
committer | Maximilian Hils <git@maximilianhils.com> | 2016-04-03 08:17:30 -0700 |
commit | 0259f479974f4f61e28bf1dac0d0f5229e468c36 (patch) | |
tree | 7bf64d328bf6dcbe12d4e8f4b6cba20125b3bf34 /netlib/utils.py | |
parent | 84f650aabf739f40b3ff414c646257141babd6e1 (diff) | |
parent | 806aa0f41c7816b2859a6961939ed19499b73fe7 (diff) | |
download | mitmproxy-0259f479974f4f61e28bf1dac0d0f5229e468c36.tar.gz mitmproxy-0259f479974f4f61e28bf1dac0d0f5229e468c36.tar.bz2 mitmproxy-0259f479974f4f61e28bf1dac0d0f5229e468c36.zip |
Merge branch 'better-replace'
Diffstat (limited to 'netlib/utils.py')
-rw-r--r-- | netlib/utils.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/netlib/utils.py b/netlib/utils.py index 09be29d9..dda76808 100644 --- a/netlib/utils.py +++ b/netlib/utils.py @@ -414,8 +414,18 @@ def http2_read_raw_frame(rfile): body = rfile.safe_read(length) return [header, body] + def http2_read_frame(rfile): header, body = http2_read_raw_frame(rfile) frame, length = hyperframe.frame.Frame.parse_frame_header(header) frame.parse_body(memoryview(body)) return frame + + +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) |