本文整理汇总了Python中txtorcon.TorConfig.socks_endpoint方法的典型用法代码示例。如果您正苦于以下问题:Python TorConfig.socks_endpoint方法的具体用法?Python TorConfig.socks_endpoint怎么用?Python TorConfig.socks_endpoint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类txtorcon.TorConfig
的用法示例。
在下文中一共展示了TorConfig.socks_endpoint方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SocksEndpointTests
# 需要导入模块: from txtorcon import TorConfig [as 别名]
# 或者: from txtorcon.TorConfig import socks_endpoint [as 别名]
class SocksEndpointTests(unittest.TestCase):
def setUp(self):
self.reactor = Mock()
self.config = TorConfig()
self.config.SocksPort = []
def test_nothing_configurd(self):
with self.assertRaises(Exception) as ctx:
self.config.socks_endpoint(self.reactor, '1234')
self.assertTrue('No SOCKS ports configured' in str(ctx.exception))
def test_default(self):
self.config.SocksPort = ['1234', '4321']
ep = self.config.socks_endpoint(self.reactor)
factory = Mock()
ep.connect(factory)
self.assertEqual(1, len(self.reactor.mock_calls))
call = self.reactor.mock_calls[0]
self.assertEqual('connectTCP', call[0])
self.assertEqual('127.0.0.1', call[1][0])
self.assertEqual(1234, call[1][1])
def test_explicit_host(self):
self.config.SocksPort = ['127.0.0.20:1234']
ep = self.config.socks_endpoint(self.reactor)
factory = Mock()
ep.connect(factory)
self.assertEqual(1, len(self.reactor.mock_calls))
call = self.reactor.mock_calls[0]
self.assertEqual('connectTCP', call[0])
self.assertEqual('127.0.0.20', call[1][0])
self.assertEqual(1234, call[1][1])
def test_something_not_configured(self):
self.config.SocksPort = ['1234', '4321']
with self.assertRaises(Exception) as ctx:
self.config.socks_endpoint(self.reactor, '1111')
self.assertTrue('No SOCKSPort configured' in str(ctx.exception))
def test_unix_socks(self):
self.config.SocksPort = ['unix:/foo']
self.config.socks_endpoint(self.reactor, 'unix:/foo')
def test_with_options(self):
self.config.SocksPort = ['9150 IPv6Traffic PreferIPv6 KeepAliveIsolateSOCKSAuth']
ep = self.config.socks_endpoint(self.reactor, 9150)
factory = Mock()
ep.connect(factory)
self.assertEqual(1, len(self.reactor.mock_calls))
call = self.reactor.mock_calls[0]
self.assertEqual('connectTCP', call[0])
self.assertEqual('127.0.0.1', call[1][0])
self.assertEqual(9150, call[1][1])
def test_with_options_in_ask(self):
self.config.SocksPort = ['9150 IPv6Traffic PreferIPv6 KeepAliveIsolateSOCKSAuth']
with self.assertRaises(Exception) as ctx:
self.config.socks_endpoint(self.reactor,
'9150 KeepAliveIsolateSOCKSAuth')
self.assertTrue("Can't specify options" in str(ctx.exception))