本文整理汇总了Python中txtorcon.TorConfig.create_socks_endpoint方法的典型用法代码示例。如果您正苦于以下问题:Python TorConfig.create_socks_endpoint方法的具体用法?Python TorConfig.create_socks_endpoint怎么用?Python TorConfig.create_socks_endpoint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类txtorcon.TorConfig
的用法示例。
在下文中一共展示了TorConfig.create_socks_endpoint方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: CreateSocksEndpointTests
# 需要导入模块: from txtorcon import TorConfig [as 别名]
# 或者: from txtorcon.TorConfig import create_socks_endpoint [as 别名]
class CreateSocksEndpointTests(unittest.TestCase):
def setUp(self):
self.reactor = Mock()
self.config = TorConfig()
self.config.SocksPort = []
self.config.bootstrap = defer.succeed(self.config)
@defer.inlineCallbacks
def test_create_default_no_ports(self):
with self.assertRaises(Exception) as ctx:
yield self.config.create_socks_endpoint(self.reactor, None)
self.assertTrue('no SocksPorts configured' in str(ctx.exception))
@defer.inlineCallbacks
def test_create_default(self):
self.config.SocksPort = ['9150']
ep = yield self.config.create_socks_endpoint(self.reactor, None)
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])
@defer.inlineCallbacks
def test_create_tcp(self):
ep = yield self.config.create_socks_endpoint(
self.reactor, "9050",
)
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(9050, call[1][1])
@defer.inlineCallbacks
def test_create_error_on_save(self):
self.config.SocksPort = []
def boom(*args, **kw):
raise TorProtocolError(551, "Something bad happened")
with patch.object(TorConfig, 'save', boom):
with self.assertRaises(Exception) as ctx:
yield self.config.create_socks_endpoint(self.reactor, 'unix:/foo')
err = str(ctx.exception)
self.assertTrue('error from Tor' in err)
self.assertTrue('specific ownership/permissions requirements' in err)