From 806aa0f41c7816b2859a6961939ed19499b73fe7 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Sat, 2 Apr 2016 14:38:33 +0200 Subject: improve .replace() and move it into netlib --- netlib/utils.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'netlib/utils.py') 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) -- cgit v1.2.3