diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2016-06-02 12:31:41 +1200 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2016-06-02 12:31:41 +1200 |
commit | cccdc9842648518de7ee48ce461801954fc334c8 (patch) | |
tree | 288941673dc0db7ffe96be55ae2c34a1ce5db916 /mitmproxy | |
parent | eaa3b308f7bb48256ccf56ea07d008fa5f9dd6ad (diff) | |
download | mitmproxy-cccdc9842648518de7ee48ce461801954fc334c8.tar.gz mitmproxy-cccdc9842648518de7ee48ce461801954fc334c8.tar.bz2 mitmproxy-cccdc9842648518de7ee48ce461801954fc334c8.zip |
Utils reorganisation: add netlib.strutils
Extract a number of string and format-related functions to netlib.strutils.
Diffstat (limited to 'mitmproxy')
-rw-r--r-- | mitmproxy/contentviews.py | 5 | ||||
-rw-r--r-- | mitmproxy/dump.py | 14 | ||||
-rw-r--r-- | mitmproxy/flow/master.py | 4 |
3 files changed, 12 insertions, 11 deletions
diff --git a/mitmproxy/contentviews.py b/mitmproxy/contentviews.py index 87cb2aa0..0ddf7c64 100644 --- a/mitmproxy/contentviews.py +++ b/mitmproxy/contentviews.py @@ -36,6 +36,7 @@ from netlib import encoding from netlib import http from netlib import odict from netlib.http import url +from netlib import strutils import netlib.utils try: @@ -581,9 +582,9 @@ def safe_to_print(lines, encoding="utf8"): clean_line = [] for (style, text) in line: try: - text = netlib.utils.clean_bin(text.decode(encoding, "strict")) + text = strutils.clean_bin(text.decode(encoding, "strict")) except UnicodeDecodeError: - text = netlib.utils.clean_bin(text).decode(encoding, "strict") + text = strutils.clean_bin(text).decode(encoding, "strict") clean_line.append((style, text)) yield clean_line diff --git a/mitmproxy/dump.py b/mitmproxy/dump.py index f5d6725c..b1005ee7 100644 --- a/mitmproxy/dump.py +++ b/mitmproxy/dump.py @@ -13,7 +13,7 @@ from mitmproxy import filt from mitmproxy import flow from netlib import human from netlib import tcp -from netlib import utils +from netlib import strutils class DumpError(Exception): @@ -181,8 +181,8 @@ class DumpMaster(flow.FlowMaster): if self.o.flow_detail >= 2: headers = "\r\n".join( "{}: {}".format( - click.style(utils.bytes_to_escaped_str(k), fg="blue", bold=True), - click.style(utils.bytes_to_escaped_str(v), fg="blue")) + click.style(strutils.bytes_to_escaped_str(k), fg="blue", bold=True), + click.style(strutils.bytes_to_escaped_str(v), fg="blue")) for k, v in message.headers.fields ) self.echo(headers, indent=4) @@ -244,7 +244,7 @@ class DumpMaster(flow.FlowMaster): stickycookie = "" if flow.client_conn: - client = click.style(utils.bytes_to_escaped_str(flow.client_conn.address.host), bold=True) + client = click.style(strutils.bytes_to_escaped_str(flow.client_conn.address.host), bold=True) else: client = click.style("[replay]", fg="yellow", bold=True) @@ -253,12 +253,12 @@ class DumpMaster(flow.FlowMaster): GET="green", DELETE="red" ).get(method.upper(), "magenta") - method = click.style(utils.bytes_to_escaped_str(method), fg=method_color, bold=True) + method = click.style(strutils.bytes_to_escaped_str(method), fg=method_color, bold=True) if self.showhost: url = flow.request.pretty_url else: url = flow.request.url - url = click.style(utils.bytes_to_escaped_str(url), bold=True) + url = click.style(strutils.bytes_to_escaped_str(url), bold=True) httpversion = "" if flow.request.http_version not in ("HTTP/1.1", "HTTP/1.0"): @@ -288,7 +288,7 @@ class DumpMaster(flow.FlowMaster): elif 400 <= code < 600: code_color = "red" code = click.style(str(code), fg=code_color, bold=True, blink=(code == 418)) - reason = click.style(utils.bytes_to_escaped_str(flow.response.reason), fg=code_color, bold=True) + reason = click.style(strutils.bytes_to_escaped_str(flow.response.reason), fg=code_color, bold=True) if flow.response.content is None: size = "(content missing)" diff --git a/mitmproxy/flow/master.py b/mitmproxy/flow/master.py index a198018e..ec0bf36d 100644 --- a/mitmproxy/flow/master.py +++ b/mitmproxy/flow/master.py @@ -16,7 +16,7 @@ from mitmproxy.flow import modules from mitmproxy.onboarding import app from mitmproxy.protocol import http_replay from mitmproxy.proxy.config import HostMatcher -from netlib import utils +from netlib import strutils class FlowMaster(controller.Master): @@ -499,7 +499,7 @@ class FlowMaster(controller.Master): server=repr(flow.server_conn.address), direction=direction, ), "info") - self.add_event(utils.clean_bin(message.content), "debug") + self.add_event(strutils.clean_bin(message.content), "debug") @controller.handler def tcp_error(self, flow): |