本文整理汇总了Python中stem.control.Controller.get_socks_listeners方法的典型用法代码示例。如果您正苦于以下问题:Python Controller.get_socks_listeners方法的具体用法?Python Controller.get_socks_listeners怎么用?Python Controller.get_socks_listeners使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stem.control.Controller
的用法示例。
在下文中一共展示了Controller.get_socks_listeners方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestControl
# 需要导入模块: from stem.control import Controller [as 别名]
# 或者: from stem.control.Controller import get_socks_listeners [as 别名]
#.........这里部分代码省略.........
"address": "123.45.67.89",
"exit-policy/default": "reject *:25,reject *:119,reject *:135-139,reject *:445,reject *:563,reject *:1214,reject *:4661-4666,reject *:6346-6429,reject *:6699,reject *:6881-6999,accept *:*",
}[param]
expected = ExitPolicy(
'reject 0.0.0.0/8:*', # private entries
'reject 169.254.0.0/16:*',
'reject 127.0.0.0/8:*',
'reject 192.168.0.0/16:*',
'reject 10.0.0.0/8:*',
'reject 172.16.0.0/12:*',
'reject 123.45.67.89:*', # relay's public address
'accept *:80', # finally we get to our ExitPolicy
'accept *:443',
'accept 43.5.5.5:*',
'reject *:22',
'reject *:25', # default policy
'reject *:119',
'reject *:135-139',
'reject *:445',
'reject *:563',
'reject *:1214',
'reject *:4661-4666',
'reject *:6346-6429',
'reject *:6699',
'reject *:6881-6999',
'accept *:*',
)
self.assertEqual(expected, self.controller.get_exit_policy())
@patch('stem.control.Controller.get_info')
@patch('stem.control.Controller.get_conf')
def test_get_socks_listeners_old(self, get_conf_mock, get_info_mock):
"""
Exercises the get_socks_listeners() method as though talking to an old tor
instance.
"""
# An old tor raises stem.InvalidArguments for get_info about socks, but
# get_socks_listeners should work anyway.
get_info_mock.side_effect = InvalidArguments
get_conf_mock.side_effect = lambda param, **kwargs: {
"SocksPort": "9050",
"SocksListenAddress": ["127.0.0.1"],
}[param]
self.assertEqual([('127.0.0.1', 9050)], self.controller.get_socks_listeners())
# Again, an old tor, but SocksListenAddress overrides the port number.
get_conf_mock.side_effect = lambda param, **kwargs: {
"SocksPort": "9050",
"SocksListenAddress": ["127.0.0.1:1112"],
}[param]
self.assertEqual([('127.0.0.1', 1112)], self.controller.get_socks_listeners())
# Again, an old tor, but multiple listeners
get_conf_mock.side_effect = lambda param, **kwargs: {
"SocksPort": "9050",
"SocksListenAddress": ["127.0.0.1:1112", "127.0.0.1:1114"],
}[param]
示例2: TestControl
# 需要导入模块: from stem.control import Controller [as 别名]
# 或者: from stem.control.Controller import get_socks_listeners [as 别名]
#.........这里部分代码省略.........
mocking.mock_method(Controller, "get_info", mocking.return_for_args({
("address", None): "123.45.67.89",
("exit-policy/default",): "reject *:25,reject *:119,reject *:135-139,reject *:445,reject *:563,reject *:1214,reject *:4661-4666,reject *:6346-6429,reject *:6699,reject *:6881-6999,accept *:*"
}, is_method = True))
expected = ExitPolicy(
'reject 0.0.0.0/8:*', # private entries
'reject 169.254.0.0/16:*',
'reject 127.0.0.0/8:*',
'reject 192.168.0.0/16:*',
'reject 10.0.0.0/8:*',
'reject 172.16.0.0/12:*',
'reject 123.45.67.89:*', # relay's public address
'accept *:80', # finally we get to our ExitPolicy
'accept *:443',
'accept 43.5.5.5:*',
'reject *:22',
'reject *:25', # default policy
'reject *:119',
'reject *:135-139',
'reject *:445',
'reject *:563',
'reject *:1214',
'reject *:4661-4666',
'reject *:6346-6429',
'reject *:6699',
'reject *:6881-6999',
'accept *:*',
)
self.assertEqual(expected, self.controller.get_exit_policy())
def test_get_socks_listeners_old(self):
"""
Exercises the get_socks_listeners() method as though talking to an old tor
instance.
"""
# An old tor raises stem.InvalidArguments for get_info about socks, but
# get_socks_listeners should work anyway.
mocking.mock_method(Controller, "get_info", mocking.raise_exception(InvalidArguments))
mocking.mock_method(Controller, "get_conf", mocking.return_for_args({
("SocksPort",): "9050",
("SocksListenAddress", "multiple=True"): ["127.0.0.1"]
}, is_method = True))
self.assertEqual([('127.0.0.1', 9050)], self.controller.get_socks_listeners())
# Again, an old tor, but SocksListenAddress overrides the port number.
mocking.mock_method(Controller, "get_conf", mocking.return_for_args({
("SocksPort",): "9050",
("SocksListenAddress", "multiple=True"): ["127.0.0.1:1112"]
}, is_method = True))
self.assertEqual([('127.0.0.1', 1112)], self.controller.get_socks_listeners())
# Again, an old tor, but multiple listeners
mocking.mock_method(Controller, "get_conf", mocking.return_for_args({
("SocksPort",): "9050",
("SocksListenAddress", "multiple=True"): ["127.0.0.1:1112", "127.0.0.1:1114"]
}, is_method = True))
self.assertEqual([('127.0.0.1', 1112), ('127.0.0.1', 1114)], self.controller.get_socks_listeners())
示例3: TestControl
# 需要导入模块: from stem.control import Controller [as 别名]
# 或者: from stem.control.Controller import get_socks_listeners [as 别名]
class TestControl(unittest.TestCase):
def setUp(self):
socket = stem.socket.ControlSocket()
self.controller = Controller(socket)
def tearDown(self):
mocking.revert_mocking()
def test_parse_circ_path(self):
"""
Exercises the _parse_circ_path() helper function.
"""
# empty input
self.assertEqual([], _parse_circ_path(None))
self.assertEqual([], _parse_circ_path(''))
# check the pydoc examples
pydoc_examples = {
'$999A226EBED397F331B612FE1E4CFAE5C1F201BA=piyaz':
[('999A226EBED397F331B612FE1E4CFAE5C1F201BA', 'piyaz')],
'$E57A476CD4DFBD99B4EE52A100A58610AD6E80B9,hamburgerphone,PrivacyRepublic14':
[('E57A476CD4DFBD99B4EE52A100A58610AD6E80B9', None),
(None, 'hamburgerphone'),
(None, 'PrivacyRepublic14'),
],
}
for test_input, expected in pydoc_examples.items():
self.assertEqual(expected, _parse_circ_path(test_input))
# exercise with some invalid inputs
malformed_inputs = [
'=piyaz', # no fingerprint
'999A226EBED397F331B612FE1E4CFAE5C1F201BA=piyaz', # fingerprint missing prefix
'$999A226EBED397F331B612FE1E4CFAE5C1F201BAA=piyaz', # fingerprint too long
'$999A226EBED397F331B612FE1E4CFAE5C1F201B=piyaz', # fingerprint too short
'$999A226EBED397F331B612FE1E4CFAE5C1F201Bz=piyaz', # invalid character in fingerprint
'$999A226EBED397F331B612FE1E4CFAE5C1F201BA=', # no nickname
]
for test_input in malformed_inputs:
self.assertRaises(ProtocolError, _parse_circ_path, test_input)
def test_event_listening(self):
"""
Exercises the add_event_listener and remove_event_listener methods.
"""
# set up for failure to create any events
mocking.mock_method(Controller, "get_version", mocking.return_value(stem.version.Version('0.1.0.14')))
self.assertRaises(InvalidRequest, self.controller.add_event_listener, mocking.no_op(), EventType.BW)
# set up to only fail newer events
mocking.mock_method(Controller, "get_version", mocking.return_value(stem.version.Version('0.2.0.35')))
# EventType.BW is one of the earliest events
self.controller.add_event_listener(mocking.no_op(), EventType.BW)
# EventType.SIGNAL was added in tor version 0.2.3.1-alpha
self.assertRaises(InvalidRequest, self.controller.add_event_listener, mocking.no_op(), EventType.SIGNAL)
def test_get_socks_listeners_old(self):
"""
Exercises the get_socks_listeners() method as though talking to an old tor
instance.
"""
# An old tor raises stem.InvalidArguments for get_info about socks, but
# get_socks_listeners should work anyway.
mocking.mock_method(Controller, "get_info", mocking.raise_exception(InvalidArguments))
mocking.mock_method(Controller, "get_conf", mocking.return_for_args({
("SocksPort",): "9050",
("SocksListenAddress", "multiple=True"): ["127.0.0.1"]
}, is_method = True))
self.assertEqual([('127.0.0.1', 9050)], self.controller.get_socks_listeners())
# Again, an old tor, but SocksListenAddress overrides the port number.
mocking.mock_method(Controller, "get_conf", mocking.return_for_args({
("SocksPort",): "9050",
("SocksListenAddress", "multiple=True"): ["127.0.0.1:1112"]
}, is_method = True))
self.assertEqual([('127.0.0.1', 1112)], self.controller.get_socks_listeners())
# Again, an old tor, but multiple listeners
mocking.mock_method(Controller, "get_conf", mocking.return_for_args({
("SocksPort",): "9050",
("SocksListenAddress", "multiple=True"): ["127.0.0.1:1112", "127.0.0.1:1114"]
}, is_method = True))
self.assertEqual([('127.0.0.1', 1112), ('127.0.0.1', 1114)], self.controller.get_socks_listeners())
# Again, an old tor, but no SOCKS listeners
#.........这里部分代码省略.........
示例4: TestControl
# 需要导入模块: from stem.control import Controller [as 别名]
# 或者: from stem.control.Controller import get_socks_listeners [as 别名]
#.........这里部分代码省略.........
}[param]
self.assertEqual([("127.0.0.1", 9050)], self.controller.get_listeners(Listener.CONTROL))
self.assertEqual([9050], self.controller.get_ports(Listener.CONTROL))
# non-local addresss
get_conf_mock.side_effect = lambda param, **kwargs: {
"ControlPort": "9050",
"ControlListenAddress": ["27.4.4.1"],
}[param]
self.assertEqual([("27.4.4.1", 9050)], self.controller.get_listeners(Listener.CONTROL))
self.assertEqual([], self.controller.get_ports(Listener.CONTROL))
# Exercise via the GETINFO option.
get_info_mock.side_effect = None
get_info_mock.return_value = '"127.0.0.1:1112" "127.0.0.1:1114"'
self.assertEqual([("127.0.0.1", 1112), ("127.0.0.1", 1114)], self.controller.get_listeners(Listener.CONTROL))
self.assertEqual([1112, 1114], self.controller.get_ports(Listener.CONTROL))
# unix socket file
get_info_mock.return_value = '"unix:/tmp/tor/socket"'
self.assertEqual([], self.controller.get_listeners(Listener.CONTROL))
self.assertEqual([], self.controller.get_ports(Listener.CONTROL))
@patch("stem.control.Controller.get_info")
@patch("stem.control.Controller.get_conf")
def test_get_socks_listeners_old(self, get_conf_mock, get_info_mock):
"""
Exercises the get_socks_listeners() method as though talking to an old tor
instance.
"""
# An old tor raises stem.InvalidArguments for get_info about socks, but
# get_socks_listeners should work anyway.
get_info_mock.side_effect = InvalidArguments
get_conf_mock.side_effect = lambda param, **kwargs: {"SocksPort": "9050", "SocksListenAddress": ["127.0.0.1"]}[
param
]
self.assertEqual([("127.0.0.1", 9050)], self.controller.get_socks_listeners())
# Again, an old tor, but SocksListenAddress overrides the port number.
get_conf_mock.side_effect = lambda param, **kwargs: {
"SocksPort": "9050",
"SocksListenAddress": ["127.0.0.1:1112"],
}[param]
self.assertEqual([("127.0.0.1", 1112)], self.controller.get_socks_listeners())
# Again, an old tor, but multiple listeners
get_conf_mock.side_effect = lambda param, **kwargs: {
"SocksPort": "9050",
"SocksListenAddress": ["127.0.0.1:1112", "127.0.0.1:1114"],
}[param]
示例5: TestControl
# 需要导入模块: from stem.control import Controller [as 别名]
# 或者: from stem.control.Controller import get_socks_listeners [as 别名]
#.........这里部分代码省略.........
self.assertEqual([('27.4.4.1', 9050)], self.controller.get_listeners(Listener.CONTROL))
self.assertEqual([], self.controller.get_ports(Listener.CONTROL))
# Exercise via the GETINFO option.
get_info_mock.side_effect = None
get_info_mock.return_value = '"127.0.0.1:1112" "127.0.0.1:1114"'
self.assertEqual(
[('127.0.0.1', 1112), ('127.0.0.1', 1114)],
self.controller.get_listeners(Listener.CONTROL)
)
self.assertEqual([1112, 1114], self.controller.get_ports(Listener.CONTROL))
# IPv6 address
get_info_mock.return_value = '"0.0.0.0:9001" "[fe80:0000:0000:0000:0202:b3ff:fe1e:8329]:9001"'
self.assertEqual(
[('0.0.0.0', 9001), ('fe80:0000:0000:0000:0202:b3ff:fe1e:8329', 9001)],
self.controller.get_listeners(Listener.CONTROL)
)
# unix socket file
get_info_mock.return_value = '"unix:/tmp/tor/socket"'
self.assertEqual([], self.controller.get_listeners(Listener.CONTROL))
self.assertEqual([], self.controller.get_ports(Listener.CONTROL))
@patch('stem.control.Controller.get_info')
@patch('stem.control.Controller.get_conf')
def test_get_socks_listeners_old(self, get_conf_mock, get_info_mock):
"""
Exercises the get_socks_listeners() method as though talking to an old tor
instance.
"""
# An old tor raises stem.InvalidArguments for get_info about socks, but
# get_socks_listeners should work anyway.
get_info_mock.side_effect = InvalidArguments
get_conf_mock.side_effect = lambda param, **kwargs: {
'SocksPort': '9050',
'SocksListenAddress': ['127.0.0.1'],
}[param]
self.assertEqual([('127.0.0.1', 9050)], self.controller.get_socks_listeners())
# Again, an old tor, but SocksListenAddress overrides the port number.
get_conf_mock.side_effect = lambda param, **kwargs: {
'SocksPort': '9050',
'SocksListenAddress': ['127.0.0.1:1112'],
}[param]
self.assertEqual([('127.0.0.1', 1112)], self.controller.get_socks_listeners())
# Again, an old tor, but multiple listeners
get_conf_mock.side_effect = lambda param, **kwargs: {
'SocksPort': '9050',
'SocksListenAddress': ['127.0.0.1:1112', '127.0.0.1:1114'],
}[param]