本文整理汇总了Python中netlib.tutils.treader函数的典型用法代码示例。如果您正苦于以下问题:Python treader函数的具体用法?Python treader怎么用?Python treader使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了treader函数的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_message_ipv4
def test_message_ipv4():
# Test ATYP=0x01 (IPV4)
raw = tutils.treader("\x05\x01\x00\x01\x7f\x00\x00\x01\xDE\xAD\xBE\xEF")
out = StringIO()
msg = socks.Message.from_file(raw)
assert raw.read(2) == "\xBE\xEF"
msg.to_file(out)
assert out.getvalue() == raw.getvalue()[:-2]
assert msg.addr == ("127.0.0.1", 0xDEAD)
开发者ID:gsilverman-memeo-inc,项目名称:netlib,代码行数:10,代码来源:test_socks.py
示例3: test_server_greeting
def test_server_greeting():
raw = tutils.treader("\x05\x02")
out = StringIO()
msg = socks.ServerGreeting.from_file(raw)
msg.assert_socks5()
msg.to_file(out)
assert out.getvalue() == raw.getvalue()
assert msg.ver == 5
assert msg.method == 0x02
开发者ID:gsilverman-memeo-inc,项目名称:netlib,代码行数:10,代码来源:test_socks.py
示例4: test_server_greeting_assert_socks5
def test_server_greeting_assert_socks5():
raw = tutils.treader("HTTP/1.1 200 OK" + " " * 100)
msg = socks.ServerGreeting.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("GET / HTTP/1.1" + " " * 100)
msg = socks.ServerGreeting.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
开发者ID:gsilverman-memeo-inc,项目名称:netlib,代码行数:20,代码来源:test_socks.py
示例5: test_username_password_auth_response
def test_username_password_auth_response():
raw = tutils.treader(b"\x01\x00\xBE\xEF")
out = BytesIO()
auth = socks.UsernamePasswordAuthResponse.from_file(raw)
auth.assert_authver1()
assert raw.read(2) == b"\xBE\xEF"
auth.to_file(out)
assert out.getvalue() == raw.getvalue()[:-2]
assert auth.ver == socks.USERNAME_PASSWORD_VERSION.DEFAULT
assert auth.status == 0
开发者ID:AlTune,项目名称:mitmproxy,代码行数:11,代码来源:test_socks.py
示例6: test_client_greeting
def test_client_greeting():
raw = tutils.treader("\x05\x02\x00\xBE\xEF")
out = StringIO()
msg = socks.ClientGreeting.from_file(raw)
msg.assert_socks5()
msg.to_file(out)
assert out.getvalue() == raw.getvalue()[:-1]
assert msg.ver == 5
assert len(msg.methods) == 2
assert 0xBE in msg.methods
assert 0xEF not in msg.methods
开发者ID:gsilverman-memeo-inc,项目名称:netlib,代码行数:12,代码来源:test_socks.py
示例7: test_username_password_auth
def test_username_password_auth():
raw = tutils.treader(b"\x01\x03usr\x03psd\xBE\xEF")
out = BytesIO()
auth = socks.UsernamePasswordAuth.from_file(raw)
auth.assert_authver1()
assert raw.read(2) == b"\xBE\xEF"
auth.to_file(out)
assert out.getvalue() == raw.getvalue()[:-2]
assert auth.ver == socks.USERNAME_PASSWORD_VERSION.DEFAULT
assert auth.username == "usr"
assert auth.password == "psd"
开发者ID:AlTune,项目名称:mitmproxy,代码行数:12,代码来源:test_socks.py
示例8: test_message
def test_message():
raw = tutils.treader("\x05\x01\x00\x03\x0bexample.com\xDE\xAD\xBE\xEF")
out = StringIO()
msg = socks.Message.from_file(raw)
msg.assert_socks5()
assert raw.read(2) == "\xBE\xEF"
msg.to_file(out)
assert out.getvalue() == raw.getvalue()[:-2]
assert msg.ver == 5
assert msg.msg == 0x01
assert msg.atyp == 0x03
assert msg.addr == ("example.com", 0xDEAD)
开发者ID:gsilverman-memeo-inc,项目名称:netlib,代码行数:13,代码来源:test_socks.py
示例9: test_message_ipv6
def test_message_ipv6():
# Test ATYP=0x04 (IPV6)
ipv6_addr = u"2001:db8:85a3:8d3:1319:8a2e:370:7344"
raw = tutils.treader(
b"\x05\x01\x00\x04" +
ipaddress.IPv6Address(ipv6_addr).packed +
b"\xDE\xAD\xBE\xEF")
out = BytesIO()
msg = socks.Message.from_file(raw)
assert raw.read(2) == b"\xBE\xEF"
msg.to_file(out)
assert out.getvalue() == raw.getvalue()[:-2]
assert msg.addr.host == ipv6_addr
开发者ID:AlTune,项目名称:mitmproxy,代码行数:15,代码来源:test_socks.py
示例10: test_message_ipv6
def test_message_ipv6():
if not hasattr(socket, "inet_ntop"):
raise SkipTest("Skipped because inet_ntop is not available")
# Test ATYP=0x04 (IPV6)
ipv6_addr = "2001:db8:85a3:8d3:1319:8a2e:370:7344"
raw = tutils.treader(
"\x05\x01\x00\x04" +
socket.inet_pton(
socket.AF_INET6,
ipv6_addr) +
"\xDE\xAD\xBE\xEF")
out = StringIO()
msg = socks.Message.from_file(raw)
assert raw.read(2) == "\xBE\xEF"
msg.to_file(out)
assert out.getvalue() == raw.getvalue()[:-2]
assert msg.addr.host == ipv6_addr
开发者ID:gsilverman-memeo-inc,项目名称:netlib,代码行数:19,代码来源:test_socks.py
示例11: test_deserialization_length
def test_deserialization_length(self, input, expected):
h = websockets.FrameHeader.from_file(tutils.treader(codecs.decode(input, 'hex')))
assert h.payload_length == expected
开发者ID:lordillusions,项目名称:mitmproxy,代码行数:3,代码来源:test_frame.py
示例12: round
def round(*args, **kwargs):
h = websockets.FrameHeader(*args, **kwargs)
h2 = websockets.FrameHeader.from_file(tutils.treader(bytes(h)))
assert h == h2
开发者ID:lordillusions,项目名称:mitmproxy,代码行数:4,代码来源:test_frame.py
示例13: test_funky
def test_funky(self):
f = websockets.FrameHeader(masking_key="test", mask=False)
bytes = f.to_bytes()
f2 = websockets.FrameHeader.from_file(tutils.treader(bytes))
assert not f2.mask
开发者ID:pombredanne,项目名称:netlib,代码行数:5,代码来源:test_websockets.py
示例14: round
def round(*args, **kwargs):
f = websockets.Frame(*args, **kwargs)
bytes = f.to_bytes()
f2 = websockets.Frame.from_file(tutils.treader(bytes))
assert f == f2
开发者ID:pombredanne,项目名称:netlib,代码行数:5,代码来源:test_websockets.py
示例15: round
def round(*args, **kwargs):
f = websockets.FrameHeader(*args, **kwargs)
f2 = websockets.FrameHeader.from_file(tutils.treader(bytes(f)))
assert f == f2
开发者ID:nicktang1983,项目名称:netlib,代码行数:4,代码来源:test_websockets.py
示例16: test_message_unknown_atyp
def test_message_unknown_atyp():
raw = tutils.treader("\x05\x02\x00\x02\x7f\x00\x00\x01\xDE\xAD\xBE\xEF")
tutils.raises(socks.SocksError, socks.Message.from_file, raw)
m = socks.Message(5, 1, 0x02, tcp.Address(("example.com", 5050)))
tutils.raises(socks.SocksError, m.to_file, StringIO())
开发者ID:gsilverman-memeo-inc,项目名称:netlib,代码行数:6,代码来源:test_socks.py
示例17: test_message_invalid_rsv
def test_message_invalid_rsv():
raw = tutils.treader("\x05\x01\xFF\x01\x7f\x00\x00\x01\xDE\xAD\xBE\xEF")
tutils.raises(socks.SocksError, socks.Message.from_file, raw)
开发者ID:gsilverman-memeo-inc,项目名称:netlib,代码行数:3,代码来源:test_socks.py
示例18: test_funky
def test_funky(self):
f = websockets.FrameHeader(masking_key=b"test", mask=False)
raw = bytes(f)
f2 = websockets.FrameHeader.from_file(tutils.treader(raw))
assert not f2.mask
开发者ID:nicktang1983,项目名称:netlib,代码行数:5,代码来源:test_websockets.py
示例19: test_message_assert_socks5
def test_message_assert_socks5():
raw = tutils.treader("\xEE\x01\x00\x03\x0bexample.com\xDE\xAD\xBE\xEF")
msg = socks.Message.from_file(raw)
tutils.raises(socks.SocksError, msg.assert_socks5)
开发者ID:gsilverman-memeo-inc,项目名称:netlib,代码行数:4,代码来源:test_socks.py
示例20: test_deserialization_masking
def test_deserialization_masking(self, input, expected):
h = websockets.FrameHeader.from_file(tutils.treader(codecs.decode(input, 'hex')))
assert h.mask == expected[0]
if h.mask:
assert h.masking_key == codecs.decode(expected[1], 'hex')
开发者ID:lordillusions,项目名称:mitmproxy,代码行数:5,代码来源:test_frame.py
注:本文中的netlib.tutils.treader函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论