diff options
author | Maximilian Hils <git@maximilianhils.com> | 2016-04-02 14:38:33 +0200 |
---|---|---|
committer | Maximilian Hils <git@maximilianhils.com> | 2016-04-02 14:38:33 +0200 |
commit | 806aa0f41c7816b2859a6961939ed19499b73fe7 (patch) | |
tree | 069ce4a304fe3fab07def4a5daa3068c0140f2d8 /netlib/utils.py | |
parent | 4ee8808b44c5a3377ac2c1dfc4ba5fb10d559ef5 (diff) | |
download | mitmproxy-806aa0f41c7816b2859a6961939ed19499b73fe7.tar.gz mitmproxy-806aa0f41c7816b2859a6961939ed19499b73fe7.tar.bz2 mitmproxy-806aa0f41c7816b2859a6961939ed19499b73fe7.zip |
improve .replace() and move it into netlib
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) |