mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-30 03:14:22 +00:00
Merge branch 'master' of github.com:mitmproxy/mitmproxy
This commit is contained in:
commit
c780fc7bdf
@ -7,6 +7,7 @@ import os
|
||||
from .. import utils
|
||||
from ..protocol.http import CONTENT_MISSING, decoded
|
||||
from . import signals
|
||||
import netlib.utils
|
||||
|
||||
try:
|
||||
import pyperclip
|
||||
@ -379,7 +380,7 @@ def format_flow(f, focus, extended=False, hostheader=False, padding=2):
|
||||
)
|
||||
if f.response:
|
||||
if f.response.content:
|
||||
contentdesc = utils.pretty_size(len(f.response.content))
|
||||
contentdesc = netlib.utils.pretty_size(len(f.response.content))
|
||||
elif f.response.content == CONTENT_MISSING:
|
||||
contentdesc = "[content missing]"
|
||||
else:
|
||||
|
@ -60,7 +60,7 @@ def trailer(clen, txt, limit):
|
||||
txt.append(
|
||||
urwid.Text(
|
||||
[
|
||||
("highlight", "... %s of data not shown. Press "%utils.pretty_size(rem)),
|
||||
("highlight", "... %s of data not shown. Press "%netlib.utils.pretty_size(rem)),
|
||||
("key", "f"),
|
||||
("highlight", " to load all data.")
|
||||
]
|
||||
|
@ -1,8 +1,8 @@
|
||||
import time
|
||||
import os.path
|
||||
|
||||
import urwid
|
||||
|
||||
import netlib.utils
|
||||
from . import pathedit, signals, common
|
||||
from .. import utils
|
||||
|
||||
@ -22,7 +22,6 @@ class ActionBar(urwid.WidgetWrap):
|
||||
self.onekey = False
|
||||
self.pathprompt = False
|
||||
|
||||
|
||||
def sig_message(self, sender, message, expire=None):
|
||||
w = urwid.Text(message)
|
||||
self._w = w
|
||||
@ -191,7 +190,7 @@ class StatusBar(urwid.WidgetWrap):
|
||||
opts.append("following")
|
||||
if self.master.stream_large_bodies:
|
||||
opts.append(
|
||||
"stream:%s" % utils.pretty_size(
|
||||
"stream:%s" % netlib.utils.pretty_size(
|
||||
self.master.stream_large_bodies.max_size
|
||||
)
|
||||
)
|
||||
|
@ -207,7 +207,7 @@ class DumpMaster(flow.FlowMaster):
|
||||
if f.response.content == http.CONTENT_MISSING:
|
||||
sz = "(content missing)"
|
||||
else:
|
||||
sz = utils.pretty_size(len(f.response.content))
|
||||
sz = netlib.utils.pretty_size(len(f.response.content))
|
||||
print(" << %s %s" % (str_response(f.response), sz), file=self.outfile)
|
||||
self._print_message(f.response)
|
||||
|
||||
|
@ -691,7 +691,10 @@ class HTTPResponse(HTTPMessage):
|
||||
return f
|
||||
|
||||
def __repr__(self):
|
||||
size = utils.pretty_size(len(self.content)) if self.content else "content missing"
|
||||
if self.content:
|
||||
size = netlib.utils.pretty_size(len(self.content))
|
||||
else:
|
||||
size = "content missing"
|
||||
return "<HTTPResponse: {code} {msg} ({contenttype}, {size})>".format(
|
||||
code=self.code,
|
||||
msg=self.msg,
|
||||
|
@ -96,20 +96,6 @@ def multipartdecode(hdrs, content):
|
||||
return r
|
||||
return []
|
||||
|
||||
def pretty_size(size):
|
||||
suffixes = [
|
||||
("B", 2**10),
|
||||
("kB", 2**20),
|
||||
("MB", 2**30),
|
||||
]
|
||||
for suf, lim in suffixes:
|
||||
if size >= lim:
|
||||
continue
|
||||
else:
|
||||
x = round(size/float(lim/2**10), 2)
|
||||
if x == int(x):
|
||||
x = int(x)
|
||||
return str(x) + suf
|
||||
|
||||
def pretty_duration(secs):
|
||||
formatters = [
|
||||
@ -124,6 +110,7 @@ def pretty_duration(secs):
|
||||
#less than 1 sec
|
||||
return "{:.0f}ms".format(secs*1000)
|
||||
|
||||
|
||||
class Data:
|
||||
def __init__(self, name):
|
||||
m = __import__(name)
|
||||
|
@ -1,5 +1,5 @@
|
||||
import json
|
||||
from libmproxy import utils, flow
|
||||
from libmproxy import utils
|
||||
from netlib import odict
|
||||
import tutils
|
||||
|
||||
@ -9,9 +9,11 @@ utils.CERT_SLEEP_TIME = 0
|
||||
def test_format_timestamp():
|
||||
assert utils.format_timestamp(utils.timestamp())
|
||||
|
||||
|
||||
def test_format_timestamp_with_milli():
|
||||
assert utils.format_timestamp_with_milli(utils.timestamp())
|
||||
|
||||
|
||||
def test_isBin():
|
||||
assert not utils.isBin("testing\n\r")
|
||||
assert utils.isBin("testing\x01")
|
||||
@ -31,13 +33,6 @@ def test_clean_hanging_newline():
|
||||
assert utils.clean_hanging_newline("foo") == "foo"
|
||||
|
||||
|
||||
def test_pretty_size():
|
||||
assert utils.pretty_size(100) == "100B"
|
||||
assert utils.pretty_size(1024) == "1kB"
|
||||
assert utils.pretty_size(1024 + (1024/2.0)) == "1.5kB"
|
||||
assert utils.pretty_size(1024*1024) == "1MB"
|
||||
|
||||
|
||||
def test_pkg_data():
|
||||
assert utils.pkg_data.path("console")
|
||||
tutils.raises("does not exist", utils.pkg_data.path, "nonexistent")
|
||||
@ -135,7 +130,7 @@ def test_parse_size():
|
||||
def test_parse_content_type():
|
||||
p = utils.parse_content_type
|
||||
assert p("text/html") == ("text", "html", {})
|
||||
assert p("text") == None
|
||||
assert p("text") is None
|
||||
|
||||
v = p("text/html; charset=UTF-8")
|
||||
assert v == ('text', 'html', {'charset': 'UTF-8'})
|
||||
@ -146,4 +141,4 @@ def test_safe_subn():
|
||||
|
||||
|
||||
def test_urlencode():
|
||||
assert utils.urlencode([('foo','bar')])
|
||||
assert utils.urlencode([('foo', 'bar')])
|
||||
|
Loading…
Reference in New Issue
Block a user