mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-23 00:01:36 +00:00
Consolidate some functions to strutils.bytes_to_escaped_str
This commit is contained in:
parent
3d9dbd6a49
commit
31012d782f
@ -3,8 +3,9 @@ import pprint
|
||||
import io
|
||||
import copy
|
||||
from flask import Flask, jsonify, render_template, request, abort, make_response
|
||||
from . import version, language, utils
|
||||
from . import version, language
|
||||
from netlib.http import user_agents
|
||||
from netlib import strutils
|
||||
|
||||
logging.basicConfig(level="DEBUG")
|
||||
EXAMPLE_HOST = "example.com"
|
||||
@ -166,7 +167,7 @@ def make_app(noapi, debug):
|
||||
settings.websocket_key = EXAMPLE_WEBSOCKET_KEY
|
||||
language.serve(safe, s, settings)
|
||||
|
||||
args["output"] = utils.escape_unprintables(s.getvalue())
|
||||
args["output"] = strutils.bytes_to_escaped_str(s.getvalue())
|
||||
return render(template, False, **args)
|
||||
|
||||
@app.route('/response_preview')
|
||||
|
@ -18,10 +18,11 @@ from netlib.exceptions import HttpException, TcpDisconnect, TcpTimeout, TlsExcep
|
||||
NetlibException
|
||||
from netlib.http import http1, http2
|
||||
|
||||
from . import utils, log, language
|
||||
from . import log, language
|
||||
|
||||
import logging
|
||||
from netlib.tutils import treq
|
||||
from netlib import strutils
|
||||
|
||||
logging.getLogger("hpack").setLevel(logging.WARNING)
|
||||
|
||||
@ -427,7 +428,7 @@ class Pathoc(tcp.TCPClient):
|
||||
finally:
|
||||
if resp:
|
||||
lg("<< %s %s: %s bytes" % (
|
||||
resp.status_code, xrepr(resp.reason), len(resp.content)
|
||||
resp.status_code, strutils.bytes_to_escaped_str(resp.reason), len(resp.content)
|
||||
))
|
||||
if resp.status_code in self.ignorecodes:
|
||||
lg.suppress()
|
||||
|
@ -2,8 +2,6 @@ import os
|
||||
import sys
|
||||
import netlib.utils
|
||||
|
||||
from netlib import strutils
|
||||
|
||||
|
||||
class MemBool(object):
|
||||
|
||||
@ -28,18 +26,6 @@ def parse_anchor_spec(s):
|
||||
return tuple(s.split("=", 1))
|
||||
|
||||
|
||||
def escape_unprintables(s):
|
||||
"""
|
||||
Like inner_repr, but preserves line breaks.
|
||||
"""
|
||||
s = s.replace(b"\r\n", b"PATHOD_MARKER_RN")
|
||||
s = s.replace(b"\n", b"PATHOD_MARKER_N")
|
||||
s = strutils.bytes_to_escaped_str(s)
|
||||
s = s.replace("PATHOD_MARKER_RN", "\n")
|
||||
s = s.replace("PATHOD_MARKER_N", "\n")
|
||||
return s
|
||||
|
||||
|
||||
data = netlib.utils.Data(__name__)
|
||||
|
||||
|
||||
|
@ -1,8 +1,6 @@
|
||||
from pathod import utils
|
||||
import tutils
|
||||
|
||||
import six
|
||||
|
||||
|
||||
def test_membool():
|
||||
m = utils.MemBool()
|
||||
@ -20,12 +18,3 @@ def test_parse_anchor_spec():
|
||||
|
||||
def test_data_path():
|
||||
tutils.raises(ValueError, utils.data.path, "nonexistent")
|
||||
|
||||
|
||||
def test_escape_unprintables():
|
||||
s = bytes(range(256))
|
||||
if six.PY2:
|
||||
s = "".join([chr(i) for i in range(255)])
|
||||
e = utils.escape_unprintables(s)
|
||||
assert e.encode('ascii')
|
||||
assert "PATHOD_MARKER" not in e
|
||||
|
Loading…
Reference in New Issue
Block a user