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

Python torcontrolprotocol.parse_keywords函数代码示例

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

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



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

示例1: test_multientry_keywords_2

 def test_multientry_keywords_2(self):
     x = parse_keywords("foo=bar\nfoo=zarimba")
     self.assertEqual(len(x), 1)
     self.assertTrue(isinstance(x["foo"], types.ListType))
     self.assertEqual(len(x["foo"]), 2)
     self.assertEqual(x["foo"][0], "bar")
     self.assertEqual(x["foo"][1], "zarimba")
开发者ID:glamrock,项目名称:txtorcon,代码行数:7,代码来源:test_torcontrolprotocol.py


示例2: _conf_changed

    def _conf_changed(self, arg):
        """
        internal callback. from control-spec:

        4.1.18. Configuration changed

          The syntax is:
             StartReplyLine *(MidReplyLine) EndReplyLine

             StartReplyLine = "650-CONF_CHANGED" CRLF
             MidReplyLine = "650-" KEYWORD ["=" VALUE] CRLF
             EndReplyLine = "650 OK"

          Tor configuration options have changed (such as via a SETCONF or
          RELOAD signal). KEYWORD and VALUE specify the configuration option
          that was changed.  Undefined configuration options contain only the
          KEYWORD.
        """

        conf = parse_keywords(arg, multiline_values=False)
        for (k, v) in conf.items():
            # v will be txtorcon.DEFAULT_VALUE already from
            # parse_keywords if it was unspecified
            real_name = self._find_real_name(k)
            if real_name in self.parsers:
                v = self.parsers[real_name].parse(v)
            self.config[real_name] = v
开发者ID:meejah,项目名称:txtorcon,代码行数:27,代码来源:torconfig.py


示例3: test_multientry_keywords_3

 def test_multientry_keywords_3(self):
     x = parse_keywords('foo=bar\nfoo=baz\nfoo=zarimba')
     self.assertEqual(len(x), 1)
     self.assertTrue(isinstance(x['foo'], list))
     self.assertEqual(len(x['foo']), 3)
     self.assertEqual(x['foo'][0], 'bar')
     self.assertEqual(x['foo'][1], 'baz')
     self.assertEqual(x['foo'][2], 'zarimba')
开发者ID:meejah,项目名称:txtorcon,代码行数:8,代码来源:test_torcontrolprotocol.py


示例4: test_multientry_keywords_2

    def test_multientry_keywords_2(self):
        x = parse_keywords('''foo=bar
foo=zarimba''')
        self.assertTrue(len(x) == 1)
        self.assertTrue(isinstance(x['foo'], types.ListType))
        self.assertTrue(len(x['foo']) == 2)
        self.assertTrue(x['foo'][0] == 'bar')
        self.assertTrue(x['foo'][1] == 'zarimba')
开发者ID:gsathya,项目名称:txtorcon,代码行数:8,代码来源:test_torcontrolprotocol.py


示例5: test_keywords

 def test_keywords(self):
     x = parse_keywords(
         "events/names=CIRC STREAM ORCONN BW DEBUG INFO NOTICE WARN ERR NEWDESC ADDRMAP AUTHDIR_NEWDESCS DESCCHANGED NS STATUS_GENERAL STATUS_CLIENT STATUS_SERVER GUARD STREAM_BW CLIENTS_SEEN NEWCONSENSUS BUILDTIMEOUT_SET\nOK"
     )
     self.assertTrue("events/names" in x)
     self.assertEqual(
         x["events/names"],
         "CIRC STREAM ORCONN BW DEBUG INFO NOTICE WARN ERR NEWDESC ADDRMAP AUTHDIR_NEWDESCS DESCCHANGED NS STATUS_GENERAL STATUS_CLIENT STATUS_SERVER GUARD STREAM_BW CLIENTS_SEEN NEWCONSENSUS BUILDTIMEOUT_SET",
     )
     self.assertEqual(len(x.keys()), 1)
开发者ID:glamrock,项目名称:txtorcon,代码行数:10,代码来源:test_torcontrolprotocol.py


示例6: test_multientry_keywords_4

    def test_multientry_keywords_4(self):
        x = parse_keywords('''foo=bar
foo=baz
foo=zarimba
foo=foo''')
        self.assertEqual(len(x), 1)
        self.assertTrue(isinstance(x['foo'], types.ListType))
        self.assertEqual(len(x['foo']), 4)
        self.assertEqual(x['foo'][0], 'bar')
        self.assertEqual(x['foo'][1], 'baz')
        self.assertEqual(x['foo'][2], 'zarimba')
        self.assertEqual(x['foo'][3], 'foo')
开发者ID:hellais,项目名称:txtorcon,代码行数:12,代码来源:test_torcontrolprotocol.py


示例7: test_multiline_keywords_with_spaces

    def test_multiline_keywords_with_spaces(self):
        x = parse_keywords('''ns/name/foo=
r foo aaaam7E7h1vY5Prk8v9/nSRCydY BBBBOfum4CtAYuOgf/D33Qq5+rk 2013-10-27 06:22:18 1.2.3.4 9001 9030
s Fast Guard HSDir Running Stable V2Dir Valid
w Bandwidth=1234
ns/name/bar=
r bar aaaaHgNYtTVPw5hHTO28J4je5i8 BBBBBUaJaBFSU/HDrTxnSh+D3+fY 2013-10-27 07:48:56 1.2.4.5 9001 9030
s Exit Fast Guard HSDir Named Running Stable V2Dir Valid
w Bandwidth=1234
OK
''')
        self.assertEqual(2, len(x))
        keys = sorted(x.keys())
        self.assertEqual(keys, ['ns/name/bar', 'ns/name/foo'])
开发者ID:meejah,项目名称:txtorcon,代码行数:14,代码来源:test_torcontrolprotocol.py


示例8: test_default_keywords

 def test_default_keywords(self):
     x = parse_keywords('foo')
     self.assertEqual(len(x), 1)
     self.assertTrue(x.has_key('foo'))
     self.assertEqual(x['foo'], DEFAULT_VALUE)
开发者ID:hellais,项目名称:txtorcon,代码行数:5,代码来源:test_torcontrolprotocol.py


示例9: test_keywords_mutli_equals

 def test_keywords_mutli_equals(self):
     x = parse_keywords('foo=something subvalue="foo"')
     self.assertTrue(len(x) == 1)
     self.assertTrue(x.has_key('foo'))
     self.assertTrue(x['foo'] == 'something subvalue="foo"')
开发者ID:hellais,项目名称:txtorcon,代码行数:5,代码来源:test_torcontrolprotocol.py


示例10: _bootstrap

    def _bootstrap(self, arg=None):
        "This takes an arg so we can use it as a callback (see __init__)."

        ## update list of routers (must be before we do the
        ## circuit-status) note that we're feeding each line
        ## incrementally to a state-machine called
        ## _network_status_parser, set up in constructor. "ns" should
        ## be the empty string, but we call _update_network_status for
        ## the de-duplication of named routers

        ns = yield self.protocol.get_info_incremental('ns/all',
                                                      self._network_status_parser.process)
        self._update_network_status(ns)

        ## update list of existing circuits
        cs = yield self.protocol.get_info_raw('circuit-status')
        self._circuit_status(cs)

        ## update list of streams
        ss = yield self.protocol.get_info_raw('stream-status')
        self._stream_status(ss)

        ## update list of existing address-maps
        key = 'address-mappings/all'
        am = yield self.protocol.get_info_raw(key)
        ## strip addressmappsings/all= and OK\n from raw data
        am = am[len(key) + 1:]
        if am.strip() != 'OK':
            for line in am.split('\n')[:-1]:
                if len(line.strip()) == 0:
                    continue            # FIXME
                self.addrmap.update(line)

        self._add_events()

        entries = yield self.protocol.get_info_raw("entry-guards")
        for line in entries.split('\n')[1:]:
            if len(line.strip()) == 0 or line.strip() == 'OK':
                continue
            args = line.split()
            (name, status) = args[:2]
            name = name[:41]

            ## this is sometimes redundant, as a missing entry guard
            ## usually means it won't be in our list of routers right
            ## now, but just being on the safe side
            if status.lower() != 'up':
                self.unusable_entry_guards.append(line)
                continue

            try:
                self.entry_guards[name] = self.router_from_id(name)
            except KeyError:
                self.unusable_entry_guards.append(line)

        ## in case process/pid doesn't exist and we don't know the PID
        ## because we own it, we just leave it as 0 (previously
        ## guessed using psutil, but that only works if there's
        ## exactly one tor running anyway)
        try:
            pid = yield self.protocol.get_info_raw("process/pid")
        except TorProtocolError:
            pid = None
        self.tor_pid = 0
        if pid:
            try:
                pid = parse_keywords(pid)['process/pid']
                self.tor_pid = int(pid)
            except KeyError:
                self.tor_pid = 0
        elif self.protocol.is_owned:
            self.tor_pid = self.protocol.is_owned

        self.post_bootstrap.callback(self)
        self.post_boostrap = None
开发者ID:enriquefynn,项目名称:txtorcon,代码行数:75,代码来源:torstate.py


示例11: test_default_keywords

 def test_default_keywords(self):
     x = parse_keywords("foo")
     self.assertEqual(len(x), 1)
     self.assertTrue("foo" in x)
     self.assertEqual(x["foo"], DEFAULT_VALUE)
开发者ID:glamrock,项目名称:txtorcon,代码行数:5,代码来源:test_torcontrolprotocol.py


示例12: test_unquoted_keywords_empty

 def test_unquoted_keywords_empty(self):
     x = parse_keywords("foo=")
     self.assertEqual(x, {"foo": ""})
开发者ID:glamrock,项目名称:txtorcon,代码行数:3,代码来源:test_torcontrolprotocol.py


示例13: test_unquoted_keywords_singlequote

 def test_unquoted_keywords_singlequote(self):
     x = parse_keywords("Tor='0.1.2.3.4-rc44'")
     self.assertEqual(x, {'Tor': '0.1.2.3.4-rc44'})
开发者ID:hellais,项目名称:txtorcon,代码行数:3,代码来源:test_torcontrolprotocol.py


示例14: _bootstrap

    def _bootstrap(self, arg=None):
        "This takes an arg so we can use it as a callback (see __init__)."

        # update list of routers (must be before we do the
        # circuit-status)

        # look out! we're depending on get_info_incremental returning
        # *lines*, which isn't documented -- but will be true because
        # TorControlProtocol is a LineReceiver...
        yield self.protocol.get_info_incremental(
            'ns/all',
            self._network_status_parser.feed_line,
        )
        self._network_status_parser.done()

        # update list of existing circuits
        cs = yield self.protocol.get_info_raw('circuit-status')
        self._circuit_status(cs)

        # update list of streams
        ss = yield self.protocol.get_info_raw('stream-status')
        self._stream_status(ss)

        # update list of existing address-maps
        key = 'address-mappings/all'
        am = yield self.protocol.get_info_raw(key)
        # strip addressmappsings/all= and OK\n from raw data
        am = am[len(key) + 1:]
        for line in am.split('\n'):
            if len(line.strip()) == 0:
                continue            # FIXME
            self.addrmap.update(line)

        yield self._add_events()

        entries = yield self.protocol.get_info_raw("entry-guards")
        for line in entries.split('\n')[1:]:
            if len(line.strip()) == 0 or line.strip() == 'OK':
                # XXX does this ever really happen?
                continue
            args = line.split()
            (name, status) = args[:2]
            name = name[:41]

            # this is sometimes redundant, as a missing entry guard
            # usually means it won't be in our list of routers right
            # now, but just being on the safe side
            if status.lower() != 'up':
                self.unusable_entry_guards.append(line)
                continue

            try:
                self.entry_guards[name] = self.router_from_id(name)
            except KeyError:
                self.unusable_entry_guards.append(line)

        # in case process/pid doesn't exist and we don't know the PID
        # because we own it, we just leave it as 0 (previously
        # guessed using psutil, but that only works if there's
        # exactly one tor running anyway)
        try:
            pid = yield self.protocol.get_info_raw("process/pid")
        except TorProtocolError:
            pid = None
        self.tor_pid = 0
        if pid:
            try:
                pid = parse_keywords(pid)['process/pid']
                self.tor_pid = int(pid)
            except Exception:  # fixme: ValueError and KeyError ..?
                self.tor_pid = 0
        if not self.tor_pid and self.protocol.is_owned:
            self.tor_pid = self.protocol.is_owned

        self.post_bootstrap.callback(self)
        self.post_boostrap = None
开发者ID:meejah,项目名称:txtorcon,代码行数:76,代码来源:torstate.py


示例15: test_multiline_keywords

    def test_multiline_keywords(self):
        x = parse_keywords('''foo=bar
baz''')
        self.assertTrue(len(x) == 1)
        self.assertTrue(x.has_key('foo'))
        self.assertTrue(x['foo'] == 'bar\nbaz')
开发者ID:gsathya,项目名称:txtorcon,代码行数:6,代码来源:test_torcontrolprotocol.py


示例16: test_default_keywords

 def test_default_keywords(self):
     x = parse_keywords('foo')
     self.assertTrue(len(x) == 1)
     self.assertTrue(x.has_key('foo'))
     self.assertTrue(x['foo'] == DEFAULT_VALUE)
开发者ID:gsathya,项目名称:txtorcon,代码行数:5,代码来源:test_torcontrolprotocol.py


示例17: test_keywords

    def test_keywords(self):
        x = parse_keywords("""events/names=CIRC STREAM ORCONN BW DEBUG INFO NOTICE WARN ERR NEWDESC ADDRMAP AUTHDIR_NEWDESCS DESCCHANGED NS STATUS_GENERAL STATUS_CLIENT STATUS_SERVER GUARD STREAM_BW CLIENTS_SEEN NEWCONSENSUS BUILDTIMEOUT_SET
OK""")
        self.assertTrue(x.has_key("events/names"))
        self.assertTrue(x['events/names'] == 'CIRC STREAM ORCONN BW DEBUG INFO NOTICE WARN ERR NEWDESC ADDRMAP AUTHDIR_NEWDESCS DESCCHANGED NS STATUS_GENERAL STATUS_CLIENT STATUS_SERVER GUARD STREAM_BW CLIENTS_SEEN NEWCONSENSUS BUILDTIMEOUT_SET')
        self.assertTrue(len(x.keys()) == 1)
开发者ID:gsathya,项目名称:txtorcon,代码行数:6,代码来源:test_torcontrolprotocol.py


示例18: test_multiline_keywords

 def test_multiline_keywords(self):
     x = parse_keywords('''Foo=bar\nBar''')
     self.assertEqual(x, {'Foo': 'bar\nBar'})
     x = parse_keywords('''Foo=bar\nBar''', multiline_values=False)
     self.assertEqual(x, {'Foo': 'bar',
                          'Bar': DEFAULT_VALUE})
开发者ID:hellais,项目名称:txtorcon,代码行数:6,代码来源:test_torcontrolprotocol.py


示例19: test_unquoted_keywords

 def test_unquoted_keywords(self):
     x = parse_keywords('''Tor="0.1.2.3.4-rc44"''')
     self.assertEqual(x, {'Tor': '0.1.2.3.4-rc44'})
开发者ID:hellais,项目名称:txtorcon,代码行数:3,代码来源:test_torcontrolprotocol.py


示例20: test_keywords_mutli_equals

 def test_keywords_mutli_equals(self):
     x = parse_keywords('foo=something subvalue="foo"')
     self.assertEqual(len(x), 1)
     self.assertTrue('foo' in x)
     self.assertEqual(x['foo'], 'something subvalue="foo"')
开发者ID:tzarskyz,项目名称:txtorcon,代码行数:5,代码来源:test_torcontrolprotocol.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python util.joinURL函数代码示例发布时间:2022-05-27
下一篇:
Python router.Router类代码示例发布时间: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