本文整理汇总了Python中txtorcon.TorConfig.bootstrap方法的典型用法代码示例。如果您正苦于以下问题:Python TorConfig.bootstrap方法的具体用法?Python TorConfig.bootstrap怎么用?Python TorConfig.bootstrap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类txtorcon.TorConfig
的用法示例。
在下文中一共展示了TorConfig.bootstrap方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_explicit_data_dir
# 需要导入模块: from txtorcon import TorConfig [as 别名]
# 或者: from txtorcon.TorConfig import bootstrap [as 别名]
def test_explicit_data_dir(self):
config = TorConfig()
td = tempfile.mkdtemp()
ep = TCPHiddenServiceEndpoint(self.reactor, config, 123, td)
# fake out some things so we don't actually have to launch + bootstrap
class FakeTorProcessProtocol(object):
tor_protocol = self.reactor.protocol
process = FakeTorProcessProtocol()
ep._launch_tor = Mock(return_value=process)
config._update_proto(Mock())
config.bootstrap()
yield config.post_bootstrap
# make sure listen() correctly configures our hidden-serivce
# with the explicit directory we passed in above
port = yield ep.listen(NoOpProtocolFactory())
self.assertEqual(1, len(config.HiddenServices))
self.assertEqual(config.HiddenServices[0].dir, td)
shutil.rmtree(td)
示例2: EndpointTests
# 需要导入模块: from txtorcon import TorConfig [as 别名]
# 或者: from txtorcon.TorConfig import bootstrap [as 别名]
class EndpointTests(unittest.TestCase):
def setUp(self):
self.reactor = FakeReactorTcp()
self.protocol = FakeControlProtocol([])
self.config = TorConfig(self.protocol)
def test_basic(self):
ep = TCPHiddenServiceEndpoint(self.reactor, self.config, 123)
d = ep.listen(FakeProtocolFactory())
self.protocol.answers.append('''config/names=
HiddenServiceOptions Virtual
OK''')
self.protocol.answers.append('HiddenServiceOptions')
self.config.bootstrap()
return d
def test_failure(self):
self.reactor.failures = 2
ep = TCPHiddenServiceEndpoint(self.reactor, self.config, 123)
d = ep.listen(FakeProtocolFactory())
self.protocol.answers.append('''config/names=
HiddenServiceOptions Virtual
OK''')
self.protocol.answers.append('HiddenServiceOptions')
self.config.bootstrap()
return d
def check_error(self, failure):
self.assertTrue(failure.type == error.CannotListenError)
return None
def test_too_many_failures(self):
self.reactor.failures = 12
ep = TCPHiddenServiceEndpoint(self.reactor, self.config, 123)
d = ep.listen(FakeProtocolFactory())
self.protocol.answers.append('''config/names=
HiddenServiceOptions Virtual
OK''')
self.protocol.answers.append('HiddenServiceOptions')
self.config.bootstrap()
d.addErrback(self.check_error)
return d
示例3: EndpointTests
# 需要导入模块: from txtorcon import TorConfig [as 别名]
# 或者: from txtorcon.TorConfig import bootstrap [as 别名]
#.........这里部分代码省略.........
# why does the new_callable thing need a callable that
# returns a callable? Feels like I must be doing something
# wrong somewhere...
def bam(*args, **kw):
return self.protocol
return bam
with patch('txtorcon.endpoints.launch_tor') as launch_mock:
with patch('txtorcon.endpoints.build_tor_connection', new_callable=boom) as btc:
client = clientFromString(
self.reactor,
"tcp:host=localhost:port=9050"
)
ep = yield TCPHiddenServiceEndpoint.system_tor(self.reactor,
client, 80)
port = yield ep.listen(NoOpProtocolFactory())
toa = port.getHost()
self.assertTrue(hasattr(toa, 'onion_uri'))
self.assertTrue(hasattr(toa, 'onion_port'))
port.startListening()
str(port)
port.tor_config
# system_tor should be connecting to a running one,
# *not* launching a new one.
self.assertFalse(launch_mock.called)
@defer.inlineCallbacks
def test_basic(self):
listen = RuntimeError("listen")
connect = RuntimeError("connect")
reactor = proto_helpers.RaisingMemoryReactor(listen, connect)
reactor.addSystemEventTrigger = Mock()
ep = TCPHiddenServiceEndpoint(reactor, self.config, 123)
self.config.bootstrap()
yield self.config.post_bootstrap
self.assertTrue(IProgressProvider.providedBy(ep))
try:
port = yield ep.listen(NoOpProtocolFactory())
self.fail("Should have been an exception")
except RuntimeError as e:
# make sure we called listenTCP not connectTCP
self.assertEqual(e, listen)
repr(self.config.HiddenServices)
def test_progress_updates(self):
config = TorConfig()
ep = TCPHiddenServiceEndpoint(self.reactor, config, 123)
self.assertTrue(IProgressProvider.providedBy(ep))
prog = IProgressProvider(ep)
ding = Mock()
prog.add_progress_listener(ding)
args = (50, "blarg", "Doing that thing we talked about.")
# kind-of cheating, test-wise?
ep._tor_progress_update(*args)
self.assertTrue(ding.called_with(*args))
@patch('txtorcon.endpoints.launch_tor')
def test_progress_updates_private_tor(self, tor):
ep = TCPHiddenServiceEndpoint.private_tor(self.reactor, 1234)
tor.call_args[1]['progress_updates'](40, 'FOO', 'foo to the bar')
return ep
def __test_progress_updates_system_tor(self):
示例4: EndpointTests
# 需要导入模块: from txtorcon import TorConfig [as 别名]
# 或者: from txtorcon.TorConfig import bootstrap [as 别名]
class EndpointTests(unittest.TestCase):
def setUp(self):
self.reactor = FakeReactorTcp()
self.protocol = FakeControlProtocol([])
self.config = TorConfig(self.protocol)
def test_basic(self):
ep = TCPHiddenServiceEndpoint(self.reactor, self.config, 123)
d = ep.listen(FakeProtocolFactory())
self.protocol.answers.append('''config/names=
HiddenServiceOptions Virtual
OK''')
self.protocol.answers.append('HiddenServiceOptions')
self.config.bootstrap()
return d
def test_explicit_data_dir(self):
ep = TCPHiddenServiceEndpoint(self.reactor, self.config, 123, '/mumble/mumble')
d = ep.listen(FakeProtocolFactory())
self.protocol.answers.append('''config/names=
HiddenServiceOptions Virtual
OK''')
self.protocol.answers.append('HiddenServiceOptions')
self.config.bootstrap()
return d
def test_explicit_data_dir_valid_hostname(self):
datadir = tempfile.mkdtemp()
with open(os.path.join(datadir, 'hostname'), 'w') as f:
f.write('timaq4ygg2iegci7.onion')
with open(os.path.join(datadir, 'private_key'), 'w') as f:
f.write('foo\nbar')
try:
ep = TCPHiddenServiceEndpoint(self.reactor, self.config, 123, datadir)
self.assertEqual(ep.onion_uri, 'timaq4ygg2iegci7.onion')
self.assertEqual(ep.onion_private_key, 'foo\nbar')
finally:
shutil.rmtree(datadir, ignore_errors=True)
def test_failure(self):
self.reactor.failures = 2
ep = TCPHiddenServiceEndpoint(self.reactor, self.config, 123)
d = ep.listen(FakeProtocolFactory())
self.protocol.answers.append('''config/names=
HiddenServiceOptions Virtual
OK''')
self.protocol.answers.append('HiddenServiceOptions')
self.config.bootstrap()
return d
def check_error(self, failure):
self.assertEqual(failure.type, error.CannotListenError)
return None
def test_too_many_failures(self):
self.reactor.failures = 12
ep = TCPHiddenServiceEndpoint(self.reactor, self.config, 123)
d = ep.listen(FakeProtocolFactory())
self.protocol.answers.append('''config/names=
HiddenServiceOptions Virtual
OK''')
self.protocol.answers.append('HiddenServiceOptions')
self.config.bootstrap()
d.addErrback(self.check_error)
return d
示例5: EndpointTests
# 需要导入模块: from txtorcon import TorConfig [as 别名]
# 或者: from txtorcon.TorConfig import bootstrap [as 别名]
class EndpointTests(unittest.TestCase):
def setUp(self):
self.reactor = FakeReactorTcp()
self.protocol = FakeControlProtocol([])
self.config = TorConfig(self.protocol)
def test_basic(self):
ep = TCPHiddenServiceEndpoint(self.reactor, self.config, 123)
d = ep.listen(FakeProtocolFactory())
self.protocol.answers.append('config/names=\nHiddenServiceOptions Virtual')
self.protocol.answers.append('HiddenServiceOptions')
self.config.bootstrap()
self.assertEqual('127.0.0.1', ep.tcp_endpoint._interface)
## make sure _ListWrapper's __repr__ doesn't explode
repr(self.config.HiddenServices)
return d
def test_multiple_listen(self):
ep = TCPHiddenServiceEndpoint(self.reactor, self.config, 123)
d0 = ep.listen(FakeProtocolFactory())
@defer.inlineCallbacks
def more_listen(arg):
yield arg.stopListening()
d1 = ep.listen(FakeProtocolFactory())
def foo(arg):
return arg
d1.addBoth(foo)
defer.returnValue(arg)
return
d0.addBoth(more_listen)
self.protocol.answers.append('config/names=\nHiddenServiceOptions Virtual')
self.protocol.answers.append('HiddenServiceOptions')
self.config.bootstrap()
def check(arg):
self.assertEqual('127.0.0.1', ep.tcp_endpoint._interface)
d0.addCallback(check).addErrback(self.fail)
return d0
def test_bad_listener(self):
def test_gen(*args, **kw):
kw['interface'] = '0.0.0.0'
return TCP4ServerEndpoint(*args, **kw)
ep = TCPHiddenServiceEndpoint(self.reactor, self.config, 123,
endpoint_generator=test_gen)
d = ep.listen(FakeProtocolFactory())
class ErrorCallback(object):
got_error = None
def __call__(self, err, *args, **kw):
self.got_error = err.value
error_cb = ErrorCallback()
d.addErrback(error_cb)
## enough answers so the config bootstraps properly
self.protocol.answers.append('config/names=\nHiddenServiceOptions Virtual')
self.protocol.answers.append('HiddenServiceOptions')
self.config.bootstrap()
## now we should have attempted to listen on the endpoint our
## test_gen() is generating - which should be the "wrong"
## answer of anything (0.0.0.0)
self.assertEqual('0.0.0.0', ep.tcp_endpoint._interface)
## ...and the point of this test; ensure we got an error
## trying to listen on not-127.*
self.assertTrue(error_cb.got_error is not None)
self.assertTrue(isinstance(error_cb.got_error, RuntimeError))
return d
def test_already_bootstrapped(self):
self.protocol.answers.append('''config/names=
HiddenServiceOptions Virtual''')
self.protocol.answers.append('HiddenServiceOptions')
self.config.bootstrap()
ep = TCPHiddenServiceEndpoint(self.reactor, self.config, 123)
d = ep.listen(FakeProtocolFactory())
return d
def test_explicit_data_dir(self):
ep = TCPHiddenServiceEndpoint(self.reactor, self.config, 123, '/mumble/mumble')
d = ep.listen(FakeProtocolFactory())
self.protocol.answers.append('config/names=\nHiddenServiceOptions Virtual')
self.protocol.answers.append('HiddenServiceOptions')
self.config.bootstrap()
return d
def test_explicit_data_dir_valid_hostname(self):
datadir = tempfile.mkdtemp()
with open(os.path.join(datadir, 'hostname'), 'w') as f:
#.........这里部分代码省略.........
示例6: EndpointTests
# 需要导入模块: from txtorcon import TorConfig [as 别名]
# 或者: from txtorcon.TorConfig import bootstrap [as 别名]
class EndpointTests(unittest.TestCase):
def setUp(self):
from txtorcon import endpoints
endpoints._global_tor_config = None
del endpoints._global_tor_lock
endpoints._global_tor_lock = defer.DeferredLock()
self.reactor = FakeReactorTcp(self)
self.protocol = FakeControlProtocol([])
self.config = TorConfig(self.protocol)
self.protocol.answers.append('config/names=\nHiddenServiceOptions Virtual')
self.protocol.answers.append('HiddenServiceOptions')
self.patcher = patch('txtorcon.torconfig.find_tor_binary', return_value='/not/tor')
self.patcher.start()
def tearDown(self):
from txtorcon import endpoints
endpoints._global_tor_config = None
del endpoints._global_tor_lock
endpoints._global_tor_lock = defer.DeferredLock()
self.patcher.stop()
@defer.inlineCallbacks
def test_global_tor(self):
config = yield get_global_tor(Mock(), _tor_launcher=lambda x, y, z: True)
self.assertEqual(0, config.SOCKSPort)
@defer.inlineCallbacks
def test_global_tor_error(self):
config0 = yield get_global_tor(Mock(), _tor_launcher=lambda x, y, z: True)
# now if we specify a control_port it should be an error since
# the above should have launched one.
try:
config1 = yield get_global_tor(Mock(), control_port=111,
_tor_launcher=lambda x, y, z: True)
self.fail()
except RuntimeError as e:
# should be an error
pass
@defer.inlineCallbacks
def test_endpoint_properties(self):
ep = yield TCPHiddenServiceEndpoint.private_tor(Mock(), 80)
self.assertEqual(None, ep.onion_private_key)
self.assertEqual(None, ep.onion_uri)
ep.hiddenservice = Mock()
ep.hiddenservice.private_key = 'mumble'
self.assertEqual('mumble', ep.onion_private_key)
@defer.inlineCallbacks
def test_private_tor(self):
m = Mock()
from txtorcon import endpoints
endpoints.launch_tor = m
ep = yield TCPHiddenServiceEndpoint.private_tor(Mock(), 80,
control_port=1234)
m.assert_called()
@defer.inlineCallbacks
def test_private_tor_no_control_port(self):
m = Mock()
from txtorcon import endpoints
endpoints.launch_tor = m
ep = yield TCPHiddenServiceEndpoint.private_tor(Mock(), 80)
m.assert_called()
@defer.inlineCallbacks
def test_system_tor(self):
from test_torconfig import FakeControlProtocol
def boom(*args):
# why does the new_callable thing need a callable that
# returns a callable? Feels like I must be doing something
# wrong somewhere...
def bam(*args, **kw):
return self.protocol
return bam
with patch('txtorcon.endpoints.launch_tor') as m:
with patch('txtorcon.endpoints.build_tor_connection', new_callable=boom) as btc:
client = clientFromString(self.reactor, "tcp:host=localhost:port=9050")
ep = yield TCPHiddenServiceEndpoint.system_tor(self.reactor,
client, 80)
port = yield ep.listen(NoOpProtocolFactory())
toa = port.getHost()
self.assertTrue(hasattr(toa, 'onion_uri'))
self.assertTrue(hasattr(toa, 'onion_port'))
port.startListening()
str(port)
port.tor_config
m.assert_called()
@defer.inlineCallbacks
def test_basic(self):
listen = RuntimeError("listen")
connect = RuntimeError("connect")
reactor = proto_helpers.RaisingMemoryReactor(listen, connect)
reactor.addSystemEventTrigger = Mock()
ep = TCPHiddenServiceEndpoint(reactor, self.config, 123)
self.config.bootstrap()
#.........这里部分代码省略.........
示例7: test_no_confchanged_event
# 需要导入模块: from txtorcon import TorConfig [as 别名]
# 或者: from txtorcon.TorConfig import bootstrap [as 别名]
def test_no_confchanged_event(self):
conf = TorConfig(self.protocol)
self.protocol.add_event_listener = Mock(side_effect=RuntimeError)
d = defer.Deferred()
self.protocol.get_info_raw = Mock(return_value=d)
conf.bootstrap()