test & examples: zap six
This commit is contained in:
parent
839813a84c
commit
ce98a9219e
|
@ -1,5 +1,5 @@
|
|||
import re
|
||||
from six.moves import urllib
|
||||
import urllib
|
||||
|
||||
# set of SSL/TLS capable hosts
|
||||
secure_hosts = set()
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
from six.moves import cStringIO as StringIO
|
||||
import io
|
||||
from PIL import Image
|
||||
|
||||
|
||||
def response(flow):
|
||||
if flow.response.headers.get("content-type", "").startswith("image"):
|
||||
try:
|
||||
s = StringIO(flow.response.content)
|
||||
s = io.StringIO(flow.response.content)
|
||||
img = Image.open(s).rotate(180)
|
||||
s2 = StringIO()
|
||||
s2 = io.StringIO()
|
||||
img.save(s2, "png")
|
||||
flow.response.content = s2.getvalue()
|
||||
flow.response.headers["content-type"] = "image/png"
|
||||
|
|
|
@ -535,10 +535,11 @@ class TlsLayer(base.Layer):
|
|||
except netlib.exceptions.TlsException as e:
|
||||
raise exceptions.TlsProtocolException(
|
||||
"Cannot establish TLS with {address} (sni: {sni}): {e}".format(
|
||||
address=repr(self.server_conn.address),
|
||||
sni=self.server_sni,
|
||||
e=repr(e),
|
||||
))
|
||||
address=repr(self.server_conn.address),
|
||||
sni=self.server_sni,
|
||||
e=repr(e)
|
||||
)
|
||||
)
|
||||
|
||||
proto = self.alpn_for_client_connection.decode() if self.alpn_for_client_connection else '-'
|
||||
self.log("ALPN selected by server: {}".format(proto), "debug")
|
||||
|
|
|
@ -9,7 +9,6 @@ setup(
|
|||
"twine>=1.6.5, <1.8",
|
||||
"virtualenv>=14.0.5, <15.1",
|
||||
"wheel>=0.29.0, <0.30",
|
||||
"six>=1.10.0, <1.11",
|
||||
"pysftp>=0.2.8, !=0.2.9, <0.3",
|
||||
],
|
||||
entry_points={
|
||||
|
|
1
setup.py
1
setup.py
|
@ -79,7 +79,6 @@ setup(
|
|||
"pyparsing>=2.1.3, <2.2",
|
||||
"pyperclip>=1.5.22, <1.6",
|
||||
"requests>=2.9.1, <2.12",
|
||||
"six>=1.10, <1.11",
|
||||
"tornado>=4.3, <4.5",
|
||||
"urwid>=1.3.1, <1.4",
|
||||
"watchdog>=0.8.3, <0.9",
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import io
|
||||
|
||||
from .. import tutils, mastertest
|
||||
from six.moves import cStringIO as StringIO
|
||||
|
||||
from mitmproxy.builtins import dumper
|
||||
from mitmproxy.flow import state
|
||||
|
@ -13,7 +14,7 @@ import mock
|
|||
class TestDumper(mastertest.MasterTest):
|
||||
def test_simple(self):
|
||||
d = dumper.Dumper()
|
||||
sio = StringIO()
|
||||
sio = io.StringIO()
|
||||
|
||||
updated = {"tfile", "flow_detail"}
|
||||
d.configure(dump.Options(tfile = sio, flow_detail = 0), updated)
|
||||
|
@ -24,17 +25,17 @@ class TestDumper(mastertest.MasterTest):
|
|||
d.response(tutils.tflow())
|
||||
assert sio.getvalue()
|
||||
|
||||
sio = StringIO()
|
||||
sio = io.StringIO()
|
||||
d.configure(dump.Options(tfile = sio, flow_detail = 4), updated)
|
||||
d.response(tutils.tflow(resp=True))
|
||||
assert "<<" in sio.getvalue()
|
||||
|
||||
sio = StringIO()
|
||||
sio = io.StringIO()
|
||||
d.configure(dump.Options(tfile = sio, flow_detail = 4), updated)
|
||||
d.response(tutils.tflow(err=True))
|
||||
assert "<<" in sio.getvalue()
|
||||
|
||||
sio = StringIO()
|
||||
sio = io.StringIO()
|
||||
d.configure(dump.Options(tfile = sio, flow_detail = 4), updated)
|
||||
flow = tutils.tflow()
|
||||
flow.request = netlib.tutils.treq()
|
||||
|
@ -47,7 +48,7 @@ class TestDumper(mastertest.MasterTest):
|
|||
d.response(flow)
|
||||
assert sio.getvalue()
|
||||
|
||||
sio = StringIO()
|
||||
sio = io.StringIO()
|
||||
d.configure(dump.Options(tfile = sio, flow_detail = 4), updated)
|
||||
flow = tutils.tflow(resp=netlib.tutils.tresp(content=b"{"))
|
||||
flow.response.headers["content-type"] = "application/json"
|
||||
|
@ -55,7 +56,7 @@ class TestDumper(mastertest.MasterTest):
|
|||
d.response(flow)
|
||||
assert sio.getvalue()
|
||||
|
||||
sio = StringIO()
|
||||
sio = io.StringIO()
|
||||
d.configure(dump.Options(tfile = sio), updated)
|
||||
flow = tutils.tflow()
|
||||
flow.request.content = None
|
||||
|
@ -71,7 +72,7 @@ class TestContentView(mastertest.MasterTest):
|
|||
view_auto.side_effect = exceptions.ContentViewException("")
|
||||
|
||||
s = state.State()
|
||||
sio = StringIO()
|
||||
sio = io.StringIO()
|
||||
o = dump.Options(
|
||||
flow_detail=4,
|
||||
verbosity=3,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
from .. import mastertest
|
||||
from six.moves import cStringIO as StringIO
|
||||
import io
|
||||
|
||||
from mitmproxy.builtins import termlog
|
||||
from mitmproxy import controller
|
||||
|
@ -9,7 +9,7 @@ from mitmproxy import dump
|
|||
class TestTermLog(mastertest.MasterTest):
|
||||
def test_simple(self):
|
||||
t = termlog.TermLog()
|
||||
sio = StringIO()
|
||||
sio = io.StringIO()
|
||||
t.configure(dump.Options(tfile = sio, verbosity = 2), set([]))
|
||||
t.log(controller.LogEntry("one", "info"))
|
||||
assert "one" in sio.getvalue()
|
||||
|
|
|
@ -4,7 +4,7 @@ from threading import Thread, Event
|
|||
from mock import Mock
|
||||
|
||||
from mitmproxy import controller
|
||||
from six.moves import queue
|
||||
import queue
|
||||
|
||||
from mitmproxy.exceptions import Kill, ControlException
|
||||
from mitmproxy.proxy import DummyServer
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import os
|
||||
from six.moves import cStringIO as StringIO
|
||||
import io
|
||||
|
||||
from mitmproxy import dump, flow, exceptions
|
||||
from . import tutils, mastertest
|
||||
|
@ -15,7 +15,7 @@ class TestDumpMaster(mastertest.MasterTest):
|
|||
options["verbosity"] = 0
|
||||
if "flow_detail" not in options:
|
||||
options["flow_detail"] = 0
|
||||
o = dump.Options(filtstr=flt, tfile=StringIO(), **options)
|
||||
o = dump.Options(filtstr=flt, tfile=io.StringIO(), **options)
|
||||
return dump.DumpMaster(None, o)
|
||||
|
||||
def test_basic(self):
|
||||
|
@ -38,7 +38,7 @@ class TestDumpMaster(mastertest.MasterTest):
|
|||
|
||||
def test_error(self):
|
||||
o = dump.Options(
|
||||
tfile=StringIO(),
|
||||
tfile=io.StringIO(),
|
||||
flow_detail=1
|
||||
)
|
||||
m = dump.DumpMaster(None, o)
|
||||
|
@ -107,7 +107,7 @@ class TestDumpMaster(mastertest.MasterTest):
|
|||
def test_replacements(self):
|
||||
o = dump.Options(
|
||||
replacements=[(".*", "content", "foo")],
|
||||
tfile = StringIO(),
|
||||
tfile = io.StringIO(),
|
||||
)
|
||||
o.verbosity = 0
|
||||
o.flow_detail = 0
|
||||
|
@ -118,7 +118,7 @@ class TestDumpMaster(mastertest.MasterTest):
|
|||
def test_setheader(self):
|
||||
o = dump.Options(
|
||||
setheaders=[(".*", "one", "two")],
|
||||
tfile=StringIO()
|
||||
tfile=io.StringIO()
|
||||
)
|
||||
o.verbosity = 0
|
||||
o.flow_detail = 0
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import json
|
||||
import os
|
||||
|
||||
import six
|
||||
import shlex
|
||||
|
||||
from mitmproxy import options
|
||||
from mitmproxy import contentviews
|
||||
|
@ -122,7 +121,7 @@ class TestHARDump():
|
|||
with tutils.tmpdir() as tdir:
|
||||
path = os.path.join(tdir, "somefile")
|
||||
|
||||
m, sc = tscript("har_dump.py", six.moves.shlex_quote(path))
|
||||
m, sc = tscript("har_dump.py", shlex.quote(path))
|
||||
m.addons.invoke(m, "response", self.flow())
|
||||
m.addons.remove(sc)
|
||||
|
||||
|
@ -135,7 +134,7 @@ class TestHARDump():
|
|||
with tutils.tmpdir() as tdir:
|
||||
path = os.path.join(tdir, "somefile")
|
||||
|
||||
m, sc = tscript("har_dump.py", six.moves.shlex_quote(path))
|
||||
m, sc = tscript("har_dump.py", shlex.quote(path))
|
||||
m.addons.invoke(m, "response", self.flow(resp_content=b"foo" + b"\xFF" * 10))
|
||||
m.addons.remove(sc)
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from six.moves import cStringIO as StringIO
|
||||
import io
|
||||
from mock import patch
|
||||
|
||||
from mitmproxy import flowfilter
|
||||
|
@ -9,7 +9,7 @@ from . import tutils
|
|||
class TestParsing:
|
||||
|
||||
def _dump(self, x):
|
||||
c = StringIO()
|
||||
c = io.StringIO()
|
||||
x.dump(fp=c)
|
||||
assert c.getvalue()
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from six.moves import socketserver
|
||||
import socketserver
|
||||
from time import sleep
|
||||
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ import sys
|
|||
from contextlib import contextmanager
|
||||
from unittest.case import SkipTest
|
||||
|
||||
from six.moves import cStringIO as StringIO
|
||||
import io
|
||||
|
||||
import netlib.utils
|
||||
import netlib.tutils
|
||||
|
@ -203,7 +203,7 @@ raises = netlib.tutils.raises
|
|||
|
||||
@contextmanager
|
||||
def capture_stderr(command, *args, **kwargs):
|
||||
out, sys.stderr = sys.stderr, StringIO()
|
||||
out, sys.stderr = sys.stderr, io.StringIO()
|
||||
command(*args, **kwargs)
|
||||
yield sys.stderr.getvalue()
|
||||
sys.stderr = out
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import absolute_import, print_function, division
|
||||
|
||||
import six
|
||||
|
||||
from netlib.tutils import tresp
|
||||
from netlib import http, tutils
|
||||
|
||||
|
@ -245,7 +243,7 @@ class TestMessageText(object):
|
|||
with tutils.raises(ValueError):
|
||||
assert r.text
|
||||
|
||||
assert r.get_text(strict=False) == u'\ufffd' if six.PY2 else '\udcff'
|
||||
assert r.get_text(strict=False) == '\udcff'
|
||||
|
||||
def test_cannot_encode(self):
|
||||
r = tresp()
|
||||
|
@ -271,4 +269,4 @@ class TestMessageText(object):
|
|||
r.headers["content-type"] = "text/html; charset=latin1"
|
||||
r.text = u'\udcff'
|
||||
assert r.headers["content-type"] == "text/html; charset=utf-8"
|
||||
assert r.raw_content == b'\xed\xb3\xbf' if six.PY2 else b"\xFF"
|
||||
assert r.raw_content == b"\xFF"
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import absolute_import, print_function, division
|
||||
|
||||
import six
|
||||
|
||||
from netlib.http import Headers
|
||||
from netlib.tutils import treq, raises
|
||||
from .test_message import _test_decoded_attr, _test_passthrough_attr
|
||||
|
@ -57,10 +55,6 @@ class TestRequestCore(object):
|
|||
assert req.data.path is None
|
||||
|
||||
def test_host(self):
|
||||
if six.PY2:
|
||||
from unittest import SkipTest
|
||||
raise SkipTest()
|
||||
|
||||
request = treq()
|
||||
assert request.host == request.data.host.decode("idna")
|
||||
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import six
|
||||
from netlib import tutils
|
||||
from netlib.http import url
|
||||
|
||||
|
@ -58,10 +57,7 @@ def test_unparse():
|
|||
assert url.unparse("https", "foo.com", 443, "") == "https://foo.com"
|
||||
|
||||
|
||||
if six.PY2:
|
||||
surrogates = bytes(bytearray(range(256)))
|
||||
else:
|
||||
surrogates = bytes(range(256)).decode("utf8", "surrogateescape")
|
||||
surrogates = bytes(range(256)).decode("utf8", "surrogateescape")
|
||||
|
||||
surrogates_quoted = (
|
||||
'%00%01%02%03%04%05%06%07%08%09%0A%0B%0C%0D%0E%0F'
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
from __future__ import (absolute_import, print_function, division)
|
||||
from six.moves import cStringIO as StringIO
|
||||
import io
|
||||
|
||||
from netlib import debug
|
||||
|
||||
|
||||
def test_dump_info():
|
||||
cs = StringIO()
|
||||
cs = io.StringIO()
|
||||
debug.dump_info(None, None, file=cs, testing=True)
|
||||
assert cs.getvalue()
|
||||
|
||||
|
||||
def test_dump_stacks():
|
||||
cs = StringIO()
|
||||
cs = io.StringIO()
|
||||
debug.dump_stacks(None, None, file=cs, testing=True)
|
||||
assert cs.getvalue()
|
||||
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
import six
|
||||
|
||||
from netlib import strutils, tutils
|
||||
|
||||
|
||||
|
@ -15,12 +13,8 @@ def test_always_bytes():
|
|||
def test_native():
|
||||
with tutils.raises(TypeError):
|
||||
strutils.native(42)
|
||||
if six.PY2:
|
||||
assert strutils.native(u"foo") == b"foo"
|
||||
assert strutils.native(b"foo") == b"foo"
|
||||
else:
|
||||
assert strutils.native(u"foo") == u"foo"
|
||||
assert strutils.native(b"foo") == u"foo"
|
||||
assert strutils.native(u"foo") == u"foo"
|
||||
assert strutils.native(b"foo") == u"foo"
|
||||
|
||||
|
||||
def test_escape_control_characters():
|
||||
|
@ -40,9 +34,8 @@ def test_escape_control_characters():
|
|||
u'=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~.'
|
||||
)
|
||||
|
||||
if not six.PY2:
|
||||
with tutils.raises(ValueError):
|
||||
strutils.escape_control_characters(b"foo")
|
||||
with tutils.raises(ValueError):
|
||||
strutils.escape_control_characters(b"foo")
|
||||
|
||||
|
||||
def test_bytes_to_escaped_str():
|
||||
|
@ -76,12 +69,8 @@ def test_escaped_str_to_bytes():
|
|||
assert strutils.escaped_str_to_bytes(u"&!?=\\\\)") == br"&!?=\)"
|
||||
assert strutils.escaped_str_to_bytes(u"\u00fc") == b'\xc3\xbc'
|
||||
|
||||
if six.PY2:
|
||||
with tutils.raises(ValueError):
|
||||
strutils.escaped_str_to_bytes(42)
|
||||
else:
|
||||
with tutils.raises(ValueError):
|
||||
strutils.escaped_str_to_bytes(b"very byte")
|
||||
with tutils.raises(ValueError):
|
||||
strutils.escaped_str_to_bytes(b"very byte")
|
||||
|
||||
|
||||
def test_is_mostly_bin():
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
from io import BytesIO
|
||||
from six.moves import queue
|
||||
import queue
|
||||
import time
|
||||
import socket
|
||||
import random
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
from io import StringIO
|
||||
import io
|
||||
import mock
|
||||
from netlib import version_check
|
||||
|
||||
|
||||
@mock.patch("sys.exit")
|
||||
def test_check_pyopenssl_version(sexit):
|
||||
fp = StringIO()
|
||||
fp = io.StringIO()
|
||||
version_check.check_pyopenssl_version(fp=fp)
|
||||
assert not fp.getvalue()
|
||||
assert not sexit.called
|
||||
|
@ -19,7 +19,7 @@ def test_check_pyopenssl_version(sexit):
|
|||
@mock.patch("OpenSSL.__version__")
|
||||
def test_unparseable_pyopenssl_version(version, sexit):
|
||||
version.split.return_value = ["foo", "bar"]
|
||||
fp = StringIO()
|
||||
fp = io.StringIO()
|
||||
version_check.check_pyopenssl_version(fp=fp)
|
||||
assert "Cannot parse" in fp.getvalue()
|
||||
assert not sexit.called
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
from __future__ import (absolute_import, print_function, division)
|
||||
|
||||
import threading
|
||||
from six.moves import queue
|
||||
from io import StringIO
|
||||
import queue
|
||||
import io
|
||||
import OpenSSL
|
||||
|
||||
from netlib import tcp
|
||||
|
@ -80,7 +80,7 @@ class _TServer(tcp.TCPServer):
|
|||
h.finish()
|
||||
|
||||
def handle_error(self, connection, client_address, fp=None):
|
||||
s = StringIO()
|
||||
s = io.StringIO()
|
||||
tcp.TCPServer.handle_error(self, connection, client_address, s)
|
||||
self.q.put(s.getvalue())
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from six import BytesIO
|
||||
import io
|
||||
|
||||
from pathod.language import actions, parse_pathoc, parse_pathod, serve
|
||||
|
||||
|
@ -60,7 +60,7 @@ class TestInject:
|
|||
assert v.offset == "r"
|
||||
|
||||
def test_serve(self):
|
||||
s = BytesIO()
|
||||
s = io.BytesIO()
|
||||
r = next(parse_pathod("400:i0,'foo'"))
|
||||
assert serve(r, s, {})
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from six import BytesIO
|
||||
import io
|
||||
from pathod import language
|
||||
from pathod.language import http, base
|
||||
|
||||
|
@ -10,7 +10,7 @@ def parse_request(s):
|
|||
|
||||
|
||||
def test_make_error_response():
|
||||
d = BytesIO()
|
||||
d = io.BytesIO()
|
||||
s = http.make_error_response("foo")
|
||||
language.serve(s, d, {})
|
||||
|
||||
|
@ -76,7 +76,7 @@ class TestRequest:
|
|||
assert r[0].values({})
|
||||
|
||||
def test_render(self):
|
||||
s = BytesIO()
|
||||
s = io.BytesIO()
|
||||
r = parse_request("GET:'/foo'")
|
||||
assert language.serve(
|
||||
r,
|
||||
|
@ -163,7 +163,7 @@ class TestResponse:
|
|||
assert b"OK" in [i[:] for i in r.preamble({})]
|
||||
|
||||
def test_render(self):
|
||||
s = BytesIO()
|
||||
s = io.BytesIO()
|
||||
r = next(language.parse_pathod("400:m'msg'"))
|
||||
assert language.serve(r, s, {})
|
||||
|
||||
|
@ -173,13 +173,13 @@ class TestResponse:
|
|||
assert "p0" not in s.spec()
|
||||
|
||||
def test_raw(self):
|
||||
s = BytesIO()
|
||||
s = io.BytesIO()
|
||||
r = next(language.parse_pathod("400:b'foo'"))
|
||||
language.serve(r, s, {})
|
||||
v = s.getvalue()
|
||||
assert b"Content-Length" in v
|
||||
|
||||
s = BytesIO()
|
||||
s = io.BytesIO()
|
||||
r = next(language.parse_pathod("400:b'foo':r"))
|
||||
language.serve(r, s, {})
|
||||
v = s.getvalue()
|
||||
|
@ -187,7 +187,7 @@ class TestResponse:
|
|||
|
||||
def test_length(self):
|
||||
def testlen(x):
|
||||
s = BytesIO()
|
||||
s = io.BytesIO()
|
||||
x = next(x)
|
||||
language.serve(x, s, language.Settings())
|
||||
assert x.length(language.Settings()) == len(s.getvalue())
|
||||
|
@ -198,7 +198,7 @@ class TestResponse:
|
|||
def test_maximum_length(self):
|
||||
def testlen(x):
|
||||
x = next(x)
|
||||
s = BytesIO()
|
||||
s = io.BytesIO()
|
||||
m = x.maximum_length({})
|
||||
language.serve(x, s, {})
|
||||
assert m >= len(s.getvalue())
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from six import BytesIO
|
||||
import io
|
||||
|
||||
from netlib import tcp
|
||||
from netlib.http import user_agents
|
||||
|
@ -26,7 +26,7 @@ def default_settings():
|
|||
|
||||
|
||||
def test_make_error_response():
|
||||
d = BytesIO()
|
||||
d = io.BytesIO()
|
||||
s = http2.make_error_response("foo", "bar")
|
||||
language.serve(s, d, default_settings())
|
||||
|
||||
|
@ -85,7 +85,7 @@ class TestRequest:
|
|||
assert r[1].method.string() == b"GET"
|
||||
|
||||
def test_render_simple(self):
|
||||
s = BytesIO()
|
||||
s = io.BytesIO()
|
||||
r = parse_request("GET:'/foo'")
|
||||
assert language.serve(
|
||||
r,
|
||||
|
@ -127,7 +127,7 @@ class TestRequest:
|
|||
assert r.headers[0].values(default_settings()) == (b"user-agent", user_agents.get_by_shortcut('a')[2].encode())
|
||||
|
||||
def test_render_with_headers(self):
|
||||
s = BytesIO()
|
||||
s = io.BytesIO()
|
||||
r = parse_request('GET:/foo:h"foo"="bar"')
|
||||
assert language.serve(
|
||||
r,
|
||||
|
@ -143,7 +143,7 @@ class TestRequest:
|
|||
assert r.values(default_settings())
|
||||
|
||||
def test_render_with_body(self):
|
||||
s = BytesIO()
|
||||
s = io.BytesIO()
|
||||
r = parse_request("GET:'/foo':bfoobar")
|
||||
assert language.serve(
|
||||
r,
|
||||
|
@ -200,7 +200,7 @@ class TestResponse:
|
|||
assert r.body.string() == b"foobar"
|
||||
|
||||
def test_render_simple(self):
|
||||
s = BytesIO()
|
||||
s = io.BytesIO()
|
||||
r = parse_response('200')
|
||||
assert language.serve(
|
||||
r,
|
||||
|
@ -209,7 +209,7 @@ class TestResponse:
|
|||
)
|
||||
|
||||
def test_render_with_headers(self):
|
||||
s = BytesIO()
|
||||
s = io.BytesIO()
|
||||
r = parse_response('200:h"foo"="bar"')
|
||||
assert language.serve(
|
||||
r,
|
||||
|
@ -218,7 +218,7 @@ class TestResponse:
|
|||
)
|
||||
|
||||
def test_render_with_body(self):
|
||||
s = BytesIO()
|
||||
s = io.BytesIO()
|
||||
r = parse_response('200:bfoobar')
|
||||
assert language.serve(
|
||||
r,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from six import BytesIO
|
||||
import io
|
||||
from pathod import language
|
||||
from pathod.language import writer
|
||||
|
||||
|
@ -6,12 +6,12 @@ from pathod.language import writer
|
|||
def test_send_chunk():
|
||||
v = b"foobarfoobar"
|
||||
for bs in range(1, len(v) + 2):
|
||||
s = BytesIO()
|
||||
s = io.BytesIO()
|
||||
writer.send_chunk(s, v, bs, 0, len(v))
|
||||
assert s.getvalue() == v
|
||||
for start in range(len(v)):
|
||||
for end in range(len(v)):
|
||||
s = BytesIO()
|
||||
s = io.BytesIO()
|
||||
writer.send_chunk(s, v, bs, start, end)
|
||||
assert s.getvalue() == v[start:end]
|
||||
|
||||
|
@ -19,21 +19,21 @@ def test_send_chunk():
|
|||
def test_write_values_inject():
|
||||
tst = b"foo"
|
||||
|
||||
s = BytesIO()
|
||||
s = io.BytesIO()
|
||||
writer.write_values(s, [tst], [(0, "inject", b"aaa")], blocksize=5)
|
||||
assert s.getvalue() == b"aaafoo"
|
||||
|
||||
s = BytesIO()
|
||||
s = io.BytesIO()
|
||||
writer.write_values(s, [tst], [(1, "inject", b"aaa")], blocksize=5)
|
||||
assert s.getvalue() == b"faaaoo"
|
||||
|
||||
s = BytesIO()
|
||||
s = io.BytesIO()
|
||||
writer.write_values(s, [tst], [(1, "inject", b"aaa")], blocksize=5)
|
||||
assert s.getvalue() == b"faaaoo"
|
||||
|
||||
|
||||
def test_write_values_disconnects():
|
||||
s = BytesIO()
|
||||
s = io.BytesIO()
|
||||
tst = b"foo" * 100
|
||||
writer.write_values(s, [tst], [(0, "disconnect")], blocksize=5)
|
||||
assert not s.getvalue()
|
||||
|
@ -41,13 +41,13 @@ def test_write_values_disconnects():
|
|||
|
||||
def test_write_values():
|
||||
tst = b"foobarvoing"
|
||||
s = BytesIO()
|
||||
s = io.BytesIO()
|
||||
writer.write_values(s, [tst], [])
|
||||
assert s.getvalue() == tst
|
||||
|
||||
for bs in range(1, len(tst) + 2):
|
||||
for off in range(len(tst)):
|
||||
s = BytesIO()
|
||||
s = io.BytesIO()
|
||||
writer.write_values(
|
||||
s, [tst], [(off, "disconnect")], blocksize=bs
|
||||
)
|
||||
|
@ -57,34 +57,34 @@ def test_write_values():
|
|||
def test_write_values_pauses():
|
||||
tst = "".join(str(i) for i in range(10)).encode()
|
||||
for i in range(2, 10):
|
||||
s = BytesIO()
|
||||
s = io.BytesIO()
|
||||
writer.write_values(
|
||||
s, [tst], [(2, "pause", 0), (1, "pause", 0)], blocksize=i
|
||||
)
|
||||
assert s.getvalue() == tst
|
||||
|
||||
for i in range(2, 10):
|
||||
s = BytesIO()
|
||||
s = io.BytesIO()
|
||||
writer.write_values(s, [tst], [(1, "pause", 0)], blocksize=i)
|
||||
assert s.getvalue() == tst
|
||||
|
||||
tst = [tst] * 5
|
||||
for i in range(2, 10):
|
||||
s = BytesIO()
|
||||
s = io.BytesIO()
|
||||
writer.write_values(s, tst[:], [(1, "pause", 0)], blocksize=i)
|
||||
assert s.getvalue() == b"".join(tst)
|
||||
|
||||
|
||||
def test_write_values_after():
|
||||
s = BytesIO()
|
||||
s = io.BytesIO()
|
||||
r = next(language.parse_pathod("400:da"))
|
||||
language.serve(r, s, {})
|
||||
|
||||
s = BytesIO()
|
||||
s = io.BytesIO()
|
||||
r = next(language.parse_pathod("400:pa,0"))
|
||||
language.serve(r, s, {})
|
||||
|
||||
s = BytesIO()
|
||||
s = io.BytesIO()
|
||||
r = next(language.parse_pathod("400:ia,'xx'"))
|
||||
language.serve(r, s, {})
|
||||
assert s.getvalue().endswith(b'xx')
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import io
|
||||
|
||||
from pathod import log
|
||||
from netlib.exceptions import TcpDisconnect
|
||||
|
||||
import six
|
||||
|
||||
|
||||
class DummyIO(six.StringIO):
|
||||
class DummyIO(io.StringIO):
|
||||
|
||||
def start_log(self, *args, **kwargs):
|
||||
pass
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
from six.moves import cStringIO as StringIO
|
||||
from six import BytesIO
|
||||
import io
|
||||
from mock import Mock
|
||||
|
||||
from netlib import http
|
||||
|
@ -21,7 +20,7 @@ def test_response():
|
|||
|
||||
class PathocTestDaemon(tutils.DaemonTests):
|
||||
def tval(self, requests, timeout=None, showssl=False, **kwargs):
|
||||
s = StringIO()
|
||||
s = io.StringIO()
|
||||
c = pathoc.Pathoc(
|
||||
("127.0.0.1", self.d.port),
|
||||
ssl=self.ssl,
|
||||
|
@ -71,7 +70,7 @@ class TestDaemonSSL(PathocTestDaemon):
|
|||
assert log[0]["request"]["clientcert"]["keyinfo"]
|
||||
|
||||
def test_http2_without_ssl(self):
|
||||
fp = StringIO()
|
||||
fp = io.StringIO()
|
||||
c = pathoc.Pathoc(
|
||||
("127.0.0.1", self.d.port),
|
||||
use_http2=True,
|
||||
|
@ -171,15 +170,15 @@ class TestDaemon(PathocTestDaemon):
|
|||
def test_connect_fail(self):
|
||||
to = ("foobar", 80)
|
||||
c = pathoc.Pathoc(("127.0.0.1", self.d.port), fp=None)
|
||||
c.rfile, c.wfile = BytesIO(), BytesIO()
|
||||
c.rfile, c.wfile = io.BytesIO(), io.BytesIO()
|
||||
with raises("connect failed"):
|
||||
c.http_connect(to)
|
||||
c.rfile = BytesIO(
|
||||
c.rfile = io.BytesIO(
|
||||
b"HTTP/1.1 500 OK\r\n"
|
||||
)
|
||||
with raises("connect failed"):
|
||||
c.http_connect(to)
|
||||
c.rfile = BytesIO(
|
||||
c.rfile = io.BytesIO(
|
||||
b"HTTP/1.1 200 OK\r\n"
|
||||
)
|
||||
c.http_connect(to)
|
||||
|
@ -187,7 +186,7 @@ class TestDaemon(PathocTestDaemon):
|
|||
def test_socks_connect(self):
|
||||
to = ("foobar", 80)
|
||||
c = pathoc.Pathoc(("127.0.0.1", self.d.port), fp=None)
|
||||
c.rfile, c.wfile = tutils.treader(b""), BytesIO()
|
||||
c.rfile, c.wfile = tutils.treader(b""), io.BytesIO()
|
||||
tutils.raises(pathoc.PathocError, c.socks_connect, to)
|
||||
|
||||
c.rfile = tutils.treader(
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from six.moves import cStringIO as StringIO
|
||||
import io
|
||||
import mock
|
||||
|
||||
from pathod import pathoc_cmdline as cmdline
|
||||
|
@ -9,7 +9,7 @@ from . import tutils
|
|||
@mock.patch("argparse.ArgumentParser.error")
|
||||
def test_pathoc(perror):
|
||||
assert cmdline.args_pathoc(["pathoc", "foo.com", "get:/"])
|
||||
s = StringIO()
|
||||
s = io.StringIO()
|
||||
with tutils.raises(SystemExit):
|
||||
cmdline.args_pathoc(["pathoc", "--show-uas"], s, s)
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from six.moves import cStringIO as StringIO
|
||||
import io
|
||||
|
||||
from pathod import pathod
|
||||
from netlib import tcp
|
||||
|
@ -10,7 +10,7 @@ from . import tutils
|
|||
class TestPathod(object):
|
||||
|
||||
def test_logging(self):
|
||||
s = StringIO()
|
||||
s = io.StringIO()
|
||||
p = pathod.Pathod(("127.0.0.1", 0), logfp=s)
|
||||
assert len(p.get_log()) == 0
|
||||
id = p.add_log(dict(s="foo"))
|
||||
|
|
|
@ -2,9 +2,8 @@ import tempfile
|
|||
import re
|
||||
import shutil
|
||||
import requests
|
||||
from six.moves import cStringIO as StringIO
|
||||
from six.moves import urllib
|
||||
from six import BytesIO
|
||||
import io
|
||||
import urllib
|
||||
|
||||
from netlib import tcp
|
||||
from netlib import utils
|
||||
|
@ -20,7 +19,7 @@ def treader(bytes):
|
|||
"""
|
||||
Construct a tcp.Read object from bytes.
|
||||
"""
|
||||
fp = BytesIO(bytes)
|
||||
fp = io.BytesIO(bytes)
|
||||
return tcp.Reader(fp)
|
||||
|
||||
|
||||
|
@ -79,7 +78,7 @@ class DaemonTests(object):
|
|||
return resp
|
||||
|
||||
def getpath(self, path, params=None):
|
||||
logfp = StringIO()
|
||||
logfp = io.StringIO()
|
||||
c = pathoc.Pathoc(
|
||||
("localhost", self.d.port),
|
||||
ssl=self.ssl,
|
||||
|
@ -92,7 +91,7 @@ class DaemonTests(object):
|
|||
return resp
|
||||
|
||||
def get(self, spec):
|
||||
logfp = StringIO()
|
||||
logfp = io.StringIO()
|
||||
c = pathoc.Pathoc(
|
||||
("localhost", self.d.port),
|
||||
ssl=self.ssl,
|
||||
|
@ -118,7 +117,7 @@ class DaemonTests(object):
|
|||
"""
|
||||
if ssl is None:
|
||||
ssl = self.ssl
|
||||
logfp = StringIO()
|
||||
logfp = io.StringIO()
|
||||
c = pathoc.Pathoc(
|
||||
("localhost", self.d.port),
|
||||
ssl=ssl,
|
||||
|
@ -148,6 +147,6 @@ test_data = utils.Data(__name__)
|
|||
|
||||
def render(r, settings=language.Settings()):
|
||||
r = r.resolve(settings)
|
||||
s = BytesIO()
|
||||
s = io.BytesIO()
|
||||
assert language.serve(r, s, settings)
|
||||
return s.getvalue()
|
||||
|
|
Loading…
Reference in New Issue