本文整理汇总了Python中netlib.tutils.raises函数的典型用法代码示例。如果您正苦于以下问题:Python raises函数的具体用法?Python raises怎么用?Python raises使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了raises函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_client_greeting_assert_socks5
def test_client_greeting_assert_socks5():
raw = tutils.treader("\x00\x00")
msg = socks.ClientGreeting.from_file(raw)
tutils.raises(socks.SocksError, msg.assert_socks5)
raw = tutils.treader("HTTP/1.1 200 OK" + " " * 100)
msg = socks.ClientGreeting.from_file(raw)
try:
msg.assert_socks5()
except socks.SocksError as e:
assert "Invalid SOCKS version" in str(e)
assert "HTTP" not in str(e)
else:
assert False
raw = tutils.treader("GET / HTTP/1.1" + " " * 100)
msg = socks.ClientGreeting.from_file(raw)
try:
msg.assert_socks5()
except socks.SocksError as e:
assert "Invalid SOCKS version" in str(e)
assert "HTTP" in str(e)
else:
assert False
raw = tutils.treader("XX")
tutils.raises(
socks.SocksError,
socks.ClientGreeting.from_file,
raw,
fail_early=True)
开发者ID:gsilverman-memeo-inc,项目名称:netlib,代码行数:31,代码来源:test_socks.py
示例2: test_always_bytes
def test_always_bytes():
assert strutils.always_bytes(bytes(bytearray(range(256)))) == bytes(bytearray(range(256)))
assert strutils.always_bytes("foo") == b"foo"
with tutils.raises(ValueError):
strutils.always_bytes(u"\u2605", "ascii")
with tutils.raises(TypeError):
strutils.always_bytes(42, "ascii")
开发者ID:mkagenius,项目名称:mitmproxy,代码行数:7,代码来源:test_strutils.py
示例3: test_settings_frame_to_bytes
def test_settings_frame_to_bytes():
f = SettingsFrame(
length=0,
flags=Frame.FLAG_NO_FLAGS,
stream_id=0x0)
assert f.to_bytes().encode('hex') == '000000040000000000'
f = SettingsFrame(
length=0,
flags=SettingsFrame.FLAG_ACK,
stream_id=0x0)
assert f.to_bytes().encode('hex') == '000000040100000000'
f = SettingsFrame(
length=6,
flags=SettingsFrame.FLAG_ACK,
stream_id=0x0,
settings={
SettingsFrame.SETTINGS.SETTINGS_ENABLE_PUSH: 1})
assert f.to_bytes().encode('hex') == '000006040100000000000200000001'
f = SettingsFrame(
length=12,
flags=Frame.FLAG_NO_FLAGS,
stream_id=0x0,
settings={
SettingsFrame.SETTINGS.SETTINGS_ENABLE_PUSH: 1,
SettingsFrame.SETTINGS.SETTINGS_MAX_CONCURRENT_STREAMS: 0x12345678})
assert f.to_bytes().encode('hex') == '00000c040000000000000200000001000312345678'
f = SettingsFrame(
length=0,
flags=Frame.FLAG_NO_FLAGS,
stream_id=0x1234567)
tutils.raises(ValueError, f.to_bytes)
开发者ID:tempbottle,项目名称:netlib,代码行数:35,代码来源:test_frames.py
示例4: test_too_large_frames
def test_too_large_frames():
f = DataFrame(
length=9000,
flags=Frame.FLAG_END_STREAM,
stream_id=0x1234567,
payload='foobar' * 3000)
tutils.raises(FrameSizeError, f.to_bytes)
开发者ID:gsilverman-memeo-inc,项目名称:netlib,代码行数:7,代码来源:test_frames.py
示例5: test_ignore
def test_ignore(self):
spec = '304:h"Alternate-Protocol"="mitmproxy-will-remove-this"'
n = self.pathod(spec)
self._ignore_on()
i = self.pathod(spec)
i2 = self.pathod(spec)
self._ignore_off()
assert i.status_code == i2.status_code == n.status_code == 304
assert "Alternate-Protocol" in i.headers
assert "Alternate-Protocol" in i2.headers
assert "Alternate-Protocol" not in n.headers
# Test that we get the original SSL cert
if self.ssl:
i_cert = SSLCert(i.sslinfo.certchain[0])
i2_cert = SSLCert(i2.sslinfo.certchain[0])
n_cert = SSLCert(n.sslinfo.certchain[0])
assert i_cert == i2_cert
assert i_cert != n_cert
# Test Non-HTTP traffic
spec = "200:i0,@100:d0" # this results in just 100 random bytes
# mitmproxy responds with bad gateway
assert self.pathod(spec).status_code == 502
self._ignore_on()
tutils.raises(
"invalid server response",
self.pathod,
spec) # pathoc tries to parse answer as HTTP
self._ignore_off()
开发者ID:camerony,项目名称:mitmproxy,代码行数:32,代码来源:test_server.py
示例6: test_options
def test_options():
o = TO(two="three")
assert o.keys() == set(["one", "two"])
assert o.one is None
assert o.two == "three"
o.one = "one"
assert o.one == "one"
with tutils.raises(TypeError):
TO(nonexistent = "value")
with tutils.raises("no such option"):
o.nonexistent = "value"
with tutils.raises("no such option"):
o.update(nonexistent = "value")
rec = []
def sub(opts, updated):
rec.append(copy.copy(opts))
o.changed.connect(sub)
o.one = "ninety"
assert len(rec) == 1
assert rec[-1].one == "ninety"
o.update(one="oink")
assert len(rec) == 2
assert rec[-1].one == "oink"
开发者ID:Angelcold,项目名称:mitmproxy,代码行数:30,代码来源:test_optmanager.py
示例7: test_reader_read_error
def test_reader_read_error(self):
s = cStringIO.StringIO("foobar\nfoobar")
s = tcp.Reader(s)
o = mock.MagicMock()
o.read = mock.MagicMock(side_effect=socket.error)
s.o = o
tutils.raises(tcp.NetLibDisconnect, s.read, 10)
开发者ID:gsilverman-memeo-inc,项目名称:netlib,代码行数:7,代码来源:test_tcp.py
示例8: test_writer_flush_error
def test_writer_flush_error(self):
s = cStringIO.StringIO()
s = tcp.Writer(s)
o = mock.MagicMock()
o.flush = mock.MagicMock(side_effect=socket.error)
s.o = o
tutils.raises(tcp.NetLibDisconnect, s.flush)
开发者ID:gsilverman-memeo-inc,项目名称:netlib,代码行数:7,代码来源:test_tcp.py
示例9: test_legacy_first_line
def test_legacy_first_line(self):
req = tutils.treq()
assert req.legacy_first_line('relative') == "GET /path HTTP/1.1"
assert req.legacy_first_line('authority') == "GET address:22 HTTP/1.1"
assert req.legacy_first_line('absolute') == "GET http://address:22/path HTTP/1.1"
tutils.raises(http.HttpError, req.legacy_first_line, 'foobar')
开发者ID:fireswood,项目名称:netlib,代码行数:7,代码来源:test_semantics.py
示例10: test_too_large_frames
def test_too_large_frames():
f = DataFrame(
length=9000,
flags=Frame.FLAG_END_STREAM,
stream_id=0x1234567,
payload='foobar' * 3000)
tutils.raises(HttpSyntaxException, f.to_bytes)
开发者ID:pombredanne,项目名称:netlib,代码行数:7,代码来源:test_frames.py
示例11: test_priority_frame_to_bytes
def test_priority_frame_to_bytes():
f = PriorityFrame(
length=5,
flags=(Frame.FLAG_NO_FLAGS),
stream_id=0x1234567,
exclusive=True,
stream_dependency=0x0,
weight=42)
assert_equal(f.to_bytes().encode('hex'), '000005020001234567800000002a')
f = PriorityFrame(
length=5,
flags=(Frame.FLAG_NO_FLAGS),
stream_id=0x1234567,
exclusive=False,
stream_dependency=0x7654321,
weight=21)
assert_equal(f.to_bytes().encode('hex'), '0000050200012345670765432115')
f = PriorityFrame(
length=5,
flags=Frame.FLAG_NO_FLAGS,
stream_id=0x0,
stream_dependency=0x1234567)
tutils.raises(ValueError, f.to_bytes)
开发者ID:pombredanne,项目名称:netlib,代码行数:25,代码来源:test_frames.py
示例12: test_replay
def test_replay(self):
o = dump.Options(server_replay=["nonexistent"], kill=True)
tutils.raises(dump.DumpError, dump.DumpMaster, None, o)
with tutils.tmpdir() as t:
p = os.path.join(t, "rep")
self.flowfile(p)
o = dump.Options(server_replay=[p], kill=True)
o.verbosity = 0
o.flow_detail = 0
m = dump.DumpMaster(None, o)
self.cycle(m, b"content")
self.cycle(m, b"content")
o = dump.Options(server_replay=[p], kill=False)
o.verbosity = 0
o.flow_detail = 0
m = dump.DumpMaster(None, o)
self.cycle(m, b"nonexistent")
o = dump.Options(client_replay=[p], kill=False)
o.verbosity = 0
o.flow_detail = 0
m = dump.DumpMaster(None, o)
开发者ID:DrakeCaraker,项目名称:mitmproxy,代码行数:26,代码来源:test_dump.py
示例13: test_invalid_flags
def test_invalid_flags():
tutils.raises(
ValueError,
DataFrame,
flags=ContinuationFrame.FLAG_END_HEADERS,
stream_id=0x1234567,
payload='foobar')
开发者ID:pombredanne,项目名称:netlib,代码行数:7,代码来源:test_frames.py
示例14: test_push_promise_frame_to_bytes
def test_push_promise_frame_to_bytes():
f = PushPromiseFrame(
length=10,
flags=Frame.FLAG_NO_FLAGS,
stream_id=0x1234567,
promised_stream=0x7654321,
header_block_fragment='foobar')
assert_equal(
f.to_bytes().encode('hex'),
'00000a05000123456707654321666f6f626172')
f = PushPromiseFrame(
length=14,
flags=HeadersFrame.FLAG_PADDED,
stream_id=0x1234567,
promised_stream=0x7654321,
header_block_fragment='foobar',
pad_length=3)
assert_equal(
f.to_bytes().encode('hex'),
'00000e0508012345670307654321666f6f626172000000')
f = PushPromiseFrame(
length=4,
flags=Frame.FLAG_NO_FLAGS,
stream_id=0x0,
promised_stream=0x1234567)
tutils.raises(ValueError, f.to_bytes)
f = PushPromiseFrame(
length=4,
flags=Frame.FLAG_NO_FLAGS,
stream_id=0x1234567,
promised_stream=0x0)
tutils.raises(ValueError, f.to_bytes)
开发者ID:pombredanne,项目名称:netlib,代码行数:35,代码来源:test_frames.py
示例15: test_bidi
def test_bidi():
b = utils.BiDi(a=1, b=2)
assert b.a == 1
assert b.get_name(1) == "a"
assert b.get_name(5) is None
tutils.raises(AttributeError, getattr, b, "c")
tutils.raises(ValueError, utils.BiDi, one=1, two=1)
开发者ID:Angelcold,项目名称:mitmproxy,代码行数:7,代码来源:test_utils.py
示例16: test_reader_read_error
def test_reader_read_error(self):
s = BytesIO(b"foobar\nfoobar")
s = tcp.Reader(s)
o = mock.MagicMock()
o.read = mock.MagicMock(side_effect=socket.error)
s.o = o
tutils.raises(TcpDisconnect, s.read, 10)
开发者ID:bemre,项目名称:mitmproxy,代码行数:7,代码来源:test_tcp.py
示例17: test_writer_flush_error
def test_writer_flush_error(self):
s = BytesIO()
s = tcp.Writer(s)
o = mock.MagicMock()
o.flush = mock.MagicMock(side_effect=socket.error)
s.o = o
tutils.raises(TcpDisconnect, s.flush)
开发者ID:bemre,项目名称:mitmproxy,代码行数:7,代码来源:test_tcp.py
示例18: test_goaway_frame_to_bytes
def test_goaway_frame_to_bytes():
f = GoAwayFrame(
length=8,
flags=Frame.FLAG_NO_FLAGS,
stream_id=0x0,
last_stream=0x1234567,
error_code=0x87654321,
data=b'')
assert_equal(
f.to_bytes().encode('hex'),
'0000080700000000000123456787654321')
f = GoAwayFrame(
length=14,
flags=Frame.FLAG_NO_FLAGS,
stream_id=0x0,
last_stream=0x1234567,
error_code=0x87654321,
data=b'foobar')
assert_equal(
f.to_bytes().encode('hex'),
'00000e0700000000000123456787654321666f6f626172')
f = GoAwayFrame(
length=8,
flags=Frame.FLAG_NO_FLAGS,
stream_id=0x1234567,
last_stream=0x1234567,
error_code=0x87654321)
tutils.raises(ValueError, f.to_bytes)
开发者ID:pombredanne,项目名称:netlib,代码行数:30,代码来源:test_frames.py
示例19: test_read_chunked
def test_read_chunked():
req = treq(content=None)
req.headers["Transfer-Encoding"] = "chunked"
data = b"1\r\na\r\n0\r\n"
with raises(HttpSyntaxException):
b"".join(_read_chunked(BytesIO(data)))
data = b"1\r\na\r\n0\r\n\r\n"
assert b"".join(_read_chunked(BytesIO(data))) == b"a"
data = b"\r\n\r\n1\r\na\r\n1\r\nb\r\n0\r\n\r\n"
assert b"".join(_read_chunked(BytesIO(data))) == b"ab"
data = b"\r\n"
with raises("closed prematurely"):
b"".join(_read_chunked(BytesIO(data)))
data = b"1\r\nfoo"
with raises("malformed chunked body"):
b"".join(_read_chunked(BytesIO(data)))
data = b"foo\r\nfoo"
with raises(HttpSyntaxException):
b"".join(_read_chunked(BytesIO(data)))
data = b"5\r\naaaaa\r\n0\r\n\r\n"
with raises("too large"):
b"".join(_read_chunked(BytesIO(data), limit=2))
开发者ID:ellerbrock,项目名称:mitmproxy,代码行数:29,代码来源:test_read.py
示例20: test_invalid_headers
def test_invalid_headers(self):
data = """
HTTP/1.1 200 OK
\tContent-Length: 3
foo
"""
tutils.raises("invalid headers", self.tst, data, "GET", None)
开发者ID:camerony,项目名称:netlib,代码行数:8,代码来源:test_protocol.py
注:本文中的netlib.tutils.raises函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论