• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python txtorcon.TorConfig类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中txtorcon.TorConfig的典型用法代码示例。如果您正苦于以下问题:Python TorConfig类的具体用法?Python TorConfig怎么用?Python TorConfig使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了TorConfig类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_basic_launch

    def test_basic_launch(self):
        config = TorConfig()
        config.OrPort = 1234
        config.SocksPort = 9999

        def connector(proto, trans):
            proto._set_valid_events('STATUS_CLIENT')
            proto.makeConnection(trans)
            proto.post_bootstrap.callback(proto)
            return proto.post_bootstrap

        class OnProgress:
            def __init__(self, test, expected):
                self.test = test
                self.expected = expected

            def __call__(self, percent, tag, summary):
                self.test.assertEqual(self.expected[0], (percent, tag, summary))
                self.expected = self.expected[1:]
                self.test.assertTrue('"' not in summary)
                self.test.assertTrue(percent >= 0 and percent <= 100)            
            
        def on_protocol(proto):
            proto.outReceived('Bootstrapped 100%\n')
            proto.progress = OnProgress(self, [(90, 'circuit_create', 'Establishing a Tor circuit'),
                                               (100, 'done', 'Done')])

        trans = FakeProcessTransport()
        trans.protocol = self.protocol
        self.othertrans = trans
        creator = functools.partial(connector, self.protocol, self.transport)
        d = launch_tor(config, FakeReactor(self, trans, on_protocol), connection_creator=creator)
        d.addCallback(self.setup_complete_no_errors, config)
        return d
开发者ID:aagbsn,项目名称:txtorcon,代码行数:34,代码来源:test_torconfig.py


示例2: test_hidden_service_parse_error

 def test_hidden_service_parse_error(self):
     conf = TorConfig(FakeControlProtocol(['config/names=']))
     try:
         conf._setup_hidden_services('''FakeHiddenServiceKey=foo''')
         self.fail()
     except RuntimeError, e:
         self.assertTrue('parse' in str(e))
开发者ID:aagbsn,项目名称:txtorcon,代码行数:7,代码来源:test_torconfig.py


示例3: test_tor_connection_user_data_dir

    def test_tor_connection_user_data_dir(self):
        """
        Test that we don't delete a user-supplied data directory.
        """

        config = TorConfig()
        config.OrPort = 1234

        class Connector:
            def __call__(self, proto, trans):
                proto._set_valid_events('STATUS_CLIENT')
                proto.makeConnection(trans)
                proto.post_bootstrap.callback(proto)
                return proto.post_bootstrap

        def on_protocol(proto):
            proto.outReceived('Bootstrapped 90%\n')
            proto.outReceived('Bootstrapped 100%\n')

        my_dir = tempfile.mkdtemp(prefix='tortmp')
        config.DataDirectory = my_dir
        trans = FakeProcessTransport()
        trans.protocol = self.protocol
        self.othertrans = trans
        creator = functools.partial(Connector(), self.protocol, self.transport)
        d = launch_tor(config, FakeReactor(self, trans, on_protocol), connection_creator=creator)
        def still_have_data_dir(proto, tester):
            proto.cleanup()             # FIXME? not really unit-testy as this is sort of internal function
            tester.assertTrue(os.path.exists(my_dir))
            delete_file_or_tree(my_dir)
        d.addCallback(still_have_data_dir, self)
        d.addErrback(self.fail)
        return d
开发者ID:aagbsn,项目名称:txtorcon,代码行数:33,代码来源:test_torconfig.py


示例4: test_add_hidden_service_to_empty_config

 def test_add_hidden_service_to_empty_config(self):
     conf = TorConfig()
     h = HiddenService(conf, '/fake/path', ['80 127.0.0.1:1234'], '', 3)
     conf.hiddenservices.append(h)
     self.assertEqual(len(conf.hiddenservices), 1)
     self.assertEqual(h, conf.hiddenservices[0])
     self.assertTrue(conf.needs_save())
开发者ID:aagbsn,项目名称:txtorcon,代码行数:7,代码来源:test_torconfig.py


示例5: test_parse_user_path

    def test_parse_user_path(self):
        # this makes sure we expand users and symlinks in
        # hiddenServiceDir args. see Issue #77

        # make sure we have a valid thing from get_global_tor without
        # actually launching tor
        config = TorConfig()
        config.post_bootstrap = defer.succeed(config)
        from txtorcon import torconfig
        torconfig._global_tor_config = None
        get_global_tor(
            self.reactor,
            _tor_launcher=lambda react, config, prog: defer.succeed(config)
        )
        ep = serverFromString(
            self.reactor,
            'onion:88:localPort=1234:hiddenServiceDir=~/blam/blarg'
        )
        # would be nice to have a fixed path here, but then would have
        # to run as a known user :/
        # maybe using the docker stuff to run integration tests better here?
        self.assertEqual(
            os.path.expanduser('~/blam/blarg'),
            ep.hidden_service_dir
        )
开发者ID:coffeemakr,项目名称:txtorcon,代码行数:25,代码来源:test_endpoints.py


示例6: test_tor_produces_stderr_output

    def test_tor_produces_stderr_output(self):
        config = TorConfig()
        config.OrPort = 1234
        config.SocksPort = 9999

        def connector(proto, trans):
            proto._set_valid_events('STATUS_CLIENT')
            proto.makeConnection(trans)
            proto.post_bootstrap.callback(proto)
            return proto.post_bootstrap

        def on_protocol(proto):
            proto.errReceived('Something went horribly wrong!\n')

        trans = FakeProcessTransport()
        trans.protocol = self.protocol
        self.othertrans = trans
        fakeout = StringIO()
        fakeerr = StringIO()
        creator = functools.partial(connector, self.protocol, self.transport)
        d = launch_tor(config, FakeReactor(self, trans, on_protocol),
                       connection_creator=creator, tor_binary='/bin/echo',
                       stdout=fakeout, stderr=fakeerr)
        d.addCallback(self.fail)        # should't get callback
        d.addErrback(self.setup_fails_stderr, fakeout, fakeerr)
        self.assertFalse(self.protocol.on_disconnect)
        return d
开发者ID:arlolra,项目名称:txtorcon,代码行数:27,代码来源:test_torconfig.py


示例7: test_options_hidden

    def test_options_hidden(self):
        self.protocol.answers.append(
            'HiddenServiceDir=/fake/path\nHiddenServicePort=80 '
            '127.0.0.1:1234\nHiddenServiceDirGroupReadable=1\n'
        )

        conf = TorConfig(self.protocol)
        yield conf.post_bootstrap
        self.assertTrue(conf.post_bootstrap.called)
        self.assertTrue('HiddenServiceOptions' not in conf.config)
        self.assertTrue('HiddenServices' in conf.config)
        self.assertEqual(len(conf.HiddenServices), 1)

        self.assertTrue(not conf.needs_save())
        conf.hiddenservices.append(
            HiddenService(conf, '/some/dir', '80 127.0.0.1:2345', 'auth', 2, True)
        )
        conf.hiddenservices[0].ports.append('443 127.0.0.1:443')
        self.assertTrue(conf.needs_save())
        conf.save()

        self.assertEqual(len(self.protocol.sets), 9)
        self.assertEqual(self.protocol.sets[0], ('HiddenServiceDir', '/fake/path'))
        self.assertEqual(self.protocol.sets[1], ('HiddenServiceDirGroupReadable', '1'))
        self.assertEqual(self.protocol.sets[2], ('HiddenServicePort', '80 127.0.0.1:1234'))
        self.assertEqual(self.protocol.sets[3], ('HiddenServicePort', '443 127.0.0.1:443'))
        self.assertEqual(self.protocol.sets[4], ('HiddenServiceDir', '/some/dir'))
        self.assertEqual(self.protocol.sets[5], ('HiddenServiceDirGroupReadable', '1'))
        self.assertEqual(self.protocol.sets[6], ('HiddenServicePort', '80 127.0.0.1:2345'))
        self.assertEqual(self.protocol.sets[7], ('HiddenServiceVersion', '2'))
        self.assertEqual(self.protocol.sets[8], ('HiddenServiceAuthorizeClient', 'auth'))
开发者ID:felipedau,项目名称:txtorcon,代码行数:31,代码来源:test_torconfig.py


示例8: test_parse_relative_path

    def test_parse_relative_path(self):
        # this makes sure we convert a relative path to absolute
        # hiddenServiceDir args. see Issue #77

        # make sure we have a valid thing from get_global_tor without
        # actually launching tor
        config = TorConfig()
        config.post_bootstrap = defer.succeed(config)
        from txtorcon import torconfig
        torconfig._global_tor_config = None
        get_global_tor(
            self.reactor,
            _tor_launcher=lambda react, config, prog: defer.succeed(config)
        )

        orig = os.path.realpath('.')
        try:
            with util.TempDir() as t:
                t = str(t)
                os.chdir(t)
                os.mkdir(os.path.join(t, 'foo'))
                hsdir = os.path.join(t, 'foo', 'blam')
                os.mkdir(hsdir)

                ep = serverFromString(
                    self.reactor,
                    'onion:88:localPort=1234:hiddenServiceDir=foo/blam'
                )
                self.assertEqual(
                    os.path.realpath(hsdir),
                    ep.hidden_service_dir
                )

        finally:
            os.chdir(orig)
开发者ID:coffeemakr,项目名称:txtorcon,代码行数:35,代码来源:test_endpoints.py


示例9: test_tor_connection_fails

    def test_tor_connection_fails(self):
        """
        We fail to connect once, and then successfully connect --
        testing whether we're retrying properly on each Bootstrapped
        line from stdout.
        """

        config = TorConfig()
        config.OrPort = 1234
        config.SocksPort = 9999

        class Connector:
            count = 0

            def __call__(self, proto, trans):
                self.count += 1
                if self.count < 2:
                    return defer.fail(error.CannotListenError(None, None, None))

                proto._set_valid_events('STATUS_CLIENT')
                proto.makeConnection(trans)
                proto.post_bootstrap.callback(proto)
                return proto.post_bootstrap

        def on_protocol(proto):
            proto.outReceived('Bootstrapped 90%\n')
            proto.outReceived('Bootstrapped 100%\n')

        trans = FakeProcessTransport()
        trans.protocol = self.protocol
        self.othertrans = trans
        creator = functools.partial(Connector(), self.protocol, self.transport)
        d = launch_tor(config, FakeReactor(self, trans, on_protocol), connection_creator=creator, tor_binary='/bin/echo')
        d.addCallback(self.setup_complete_fails)
        return self.assertFailure(d, Exception)
开发者ID:biddyweb,项目名称:txtorcon,代码行数:35,代码来源:test_torconfig.py


示例10: test_tor_connection_user_control_port

    def test_tor_connection_user_control_port(self):
        """
        Confirm we use a user-supplied control-port properly
        """

        config = TorConfig()
        config.OrPort = 1234
        config.ControlPort = 4321

        class Connector:
            def __call__(self, proto, trans):
                proto._set_valid_events('STATUS_CLIENT')
                proto.makeConnection(trans)
                proto.post_bootstrap.callback(proto)
                return proto.post_bootstrap

        def on_protocol(proto):
            proto.outReceived('Bootstrapped 90%\n')
            proto.outReceived('Bootstrapped 100%\n')

        trans = FakeProcessTransport()
        trans.protocol = self.protocol
        self.othertrans = trans
        creator = functools.partial(Connector(), self.protocol, self.transport)
        d = launch_tor(config, FakeReactor(self, trans, on_protocol), connection_creator=creator)

        def check_control_port(proto, tester):
            ## we just want to ensure launch_tor() didn't mess with
            ## the controlport we set
            tester.assertEquals(config.ControlPort, 4321)

        d.addCallback(check_control_port, self)
        d.addErrback(self.fail)
        return d
开发者ID:aagbsn,项目名称:txtorcon,代码行数:34,代码来源:test_torconfig.py


示例11: test_set_wrong_object

    def test_set_wrong_object(self):
        conf = TorConfig(self.protocol)

        try:
            conf.log = ('this', 'is', 'a', 'tuple')
            self.fail()
        except ValueError, e:
            self.assertTrue('Not valid' in str(e))
开发者ID:aagbsn,项目名称:txtorcon,代码行数:8,代码来源:test_torconfig.py


示例12: test_log_set_index

    def test_log_set_index(self):
        conf = TorConfig(self.protocol)

        conf.log[0] = 'info file /tmp/foo.log'
        self.assertTrue(conf.needs_save())
        conf.save()

        self.assertTrue(self.protocol.sets[0] == ('Log', 'info file /tmp/foo.log'))
开发者ID:gsathya,项目名称:txtorcon,代码行数:8,代码来源:test_torconfig.py


示例13: _do_launch_tor

 def _do_launch_tor(self):
     tconfig = TorConfig()
     #tconfig.ControlPort = allocate_tcp_port() # defaults to 9052
     tconfig.SocksPort = allocate_tcp_port()
     socks_desc = "tcp:127.0.0.1:%d" % tconfig.SocksPort
     # this could take tor_binary=
     tproto = yield launch_tor(tconfig, self._reactor)
     returnValue((tproto, tconfig, socks_desc))
开发者ID:meejah,项目名称:magic-wormhole,代码行数:8,代码来源:tor_manager.py


示例14: test_log_set_slice

    def test_log_set_slice(self):
        conf = TorConfig(self.protocol)

        conf.log[0:1] = ['info file /tmp/foo.log']
        self.assertTrue(conf.needs_save())
        conf.save()

        self.assertEqual(self.protocol.sets[0], ('Log', 'info file /tmp/foo.log'))
开发者ID:aagbsn,项目名称:txtorcon,代码行数:8,代码来源:test_torconfig.py


示例15: test_multiple_orports

 def test_multiple_orports(self):
     self.protocol.post_bootstrap = None
     self.protocol.answers.append('config/names=\nOrPort CommaList')
     self.protocol.answers.append({'OrPort': '1234'})
     conf = TorConfig(self.protocol)
     conf.OrPort = ['1234', '4321']
     conf.save()
     self.assertEqual(self.protocol.sets, [('OrPort', '1234'),
                                           ('OrPort', '4321')])
开发者ID:biddyweb,项目名称:txtorcon,代码行数:9,代码来源:test_torconfig.py


示例16: test_log_set_capital

    def test_log_set_capital(self):
        conf = TorConfig(self.protocol)

        conf.Log.append('info file /tmp/foo.log')
        self.assertTrue(conf.needs_save())
        conf.save()

        self.assertEqual(self.protocol.sets[0], ('Log', 'notice file /var/log/tor/notices.log'))
        self.assertEqual(self.protocol.sets[1], ('Log', 'info file /tmp/foo.log'))
开发者ID:aagbsn,项目名称:txtorcon,代码行数:9,代码来源:test_torconfig.py


示例17: test_boolean_parse_error

 def test_boolean_parse_error(self):
     self.protocol.answers.append('config/names=\nfoo Boolean')
     self.protocol.answers.append({'foo': 'bar'})
     cfg = TorConfig(self.protocol)
     self.assertEqual(cfg.get_type('foo'), torconfig.Boolean)
     errs = self.flushLoggedErrors(ValueError)
     self.assertEqual(len(errs), 1)
     ## dunno if asserting strings in messages is a good idea...
     self.assertTrue('invalid literal' in errs[0].getErrorMessage())
开发者ID:biddyweb,项目名称:txtorcon,代码行数:9,代码来源:test_torconfig.py


示例18: test_iterate_torconfig

    def test_iterate_torconfig(self):
        cfg = TorConfig()
        cfg.FooBar = 'quux'
        cfg.save()
        cfg.Quux = 'blimblam'

        keys = sorted([k for k in cfg])

        self.assertEqual(['FooBar', 'Quux'], keys)
开发者ID:felipedau,项目名称:txtorcon,代码行数:9,代码来源:test_torconfig.py


示例19: test_multiple_append

 def test_multiple_append(self):
     conf = TorConfig()
     h0 = HiddenService(conf, '/fake/path', ['80 127.0.0.1:1234'], '', 3)
     h1 = HiddenService(conf, '/fake/path', ['90 127.0.0.1:4321'], '', 3)
     conf.hiddenservices.append(h0)
     conf.hiddenservices.append(h1)
     self.assertEqual(len(conf.hiddenservices), 2)
     self.assertEqual(h0, conf.hiddenservices[0])
     self.assertEqual(h1, conf.hiddenservices[1])
     self.assertTrue(conf.needs_save())
开发者ID:biddyweb,项目名称:txtorcon,代码行数:10,代码来源:test_torconfig.py


示例20: test_get_type

    def test_get_type(self):
        self.protocol.answers.append(
            'config/names=\nSomethingExciting CommaList\nHiddenServices Dependant'
        )
        self.protocol.answers.append({'SomethingExciting': 'a,b'})
        conf = TorConfig(self.protocol)

        from txtorcon.torconfig import HiddenService
        self.assertEqual(conf.get_type('SomethingExciting'), CommaList)
        self.assertEqual(conf.get_type('HiddenServices'), HiddenService)
开发者ID:felipedau,项目名称:txtorcon,代码行数:10,代码来源:test_torconfig.py



注:本文中的txtorcon.TorConfig类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python txtorcon.TorControlProtocol类代码示例发布时间:2022-05-27
下一篇:
Python txtorcon.TCPHiddenServiceEndpoint类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap