当前位置: 首页>>代码示例>>Python>>正文


Python Router.update方法代码示例

本文整理汇总了Python中txtorcon.router.Router.update方法的典型用法代码示例。如果您正苦于以下问题:Python Router.update方法的具体用法?Python Router.update怎么用?Python Router.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在txtorcon.router.Router的用法示例。


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

示例1: test_countrycode

# 需要导入模块: from txtorcon.router import Router [as 别名]
# 或者: from txtorcon.router.Router import update [as 别名]
 def test_countrycode(self):
     controller = FakeController()
     router = Router(controller)
     router.update("foo",
                   "AHhuQ8zFQJdT8l42Axxc6m6kNwI",
                   "MAANkj30tnFvmoh7FsjVFr+cmcs",
                   "2011-12-16 15:11:34",
                   "127.0.0.1",
                   "24051", "24052")
开发者ID:gsathya,项目名称:txtorcon,代码行数:11,代码来源:test_router.py

示例2: test_repr

# 需要导入模块: from txtorcon.router import Router [as 别名]
# 或者: from txtorcon.router.Router import update [as 别名]
 def test_repr(self):
     router = Router(FakeController())
     router.update("foo",
                   "AHhuQ8zFQJdT8l42Axxc6m6kNwI",
                   "MAANkj30tnFvmoh7FsjVFr+cmcs",
                   "2011-12-16 15:11:34",
                   "1.2.3.4",
                   "24051", "24052")
     router.flags = ['Named']
     repr(router)
开发者ID:arlolra,项目名称:txtorcon,代码行数:12,代码来源:test_router.py

示例3: test_flags_from_string

# 需要导入模块: from txtorcon.router import Router [as 别名]
# 或者: from txtorcon.router.Router import update [as 别名]
 def test_flags_from_string(self):
     controller = object()
     router = Router(controller)
     router.update("foo",
                   "AHhuQ8zFQJdT8l42Axxc6m6kNwI",
                   "MAANkj30tnFvmoh7FsjVFr+cmcs",
                   "2011-12-16 15:11:34",
                   "77.183.225.114",
                   "24051", "24052")
     router.flags = "Exit Fast Named Running V2Dir Valid"
     self.assertEqual(router.name_is_unique, True)
开发者ID:arlolra,项目名称:txtorcon,代码行数:13,代码来源:test_router.py

示例4: test_ctor

# 需要导入模块: from txtorcon.router import Router [as 别名]
# 或者: from txtorcon.router.Router import update [as 别名]
 def test_ctor(self):
     controller = object()
     router = Router(controller)
     router.update("foo",
                   "AHhuQ8zFQJdT8l42Axxc6m6kNwI",
                   "MAANkj30tnFvmoh7FsjVFr+cmcs",
                   "2011-12-16 15:11:34",
                   "77.183.225.114",
                   "24051", "24052")
     self.assertEqual(router.id_hex, "$00786E43CCC5409753F25E36031C5CEA6EA43702")
     self.assertEqual(router.policy, '')
开发者ID:arlolra,项目名称:txtorcon,代码行数:13,代码来源:test_router.py

示例5: test_unique_name

# 需要导入模块: from txtorcon.router import Router [as 别名]
# 或者: from txtorcon.router.Router import update [as 别名]
 def test_unique_name(self):
     controller = object()
     router = Router(controller)
     router.update("foo",
                   "AHhuQ8zFQJdT8l42Axxc6m6kNwI",
                   "MAANkj30tnFvmoh7FsjVFr+cmcs",
                   "2011-12-16 15:11:34",
                   "77.183.225.114",
                   "24051", "24052")
     self.assertTrue(router.id_hex == "$00786E43CCC5409753F25E36031C5CEA6EA43702")
     self.assertTrue(router.unique_name == "$00786E43CCC5409753F25E36031C5CEA6EA43702")
     router.flags = ['Named']
     self.assertTrue(router.unique_name == "foo")
开发者ID:gsathya,项目名称:txtorcon,代码行数:15,代码来源:test_router.py

示例6: test_get_location_something

# 需要导入模块: from txtorcon.router import Router [as 别名]
# 或者: from txtorcon.router.Router import update [as 别名]
    def test_get_location_something(self):

        class CountryCodeController(object):
            def get_info_raw(self, i):
                return defer.succeed(
                    '250-ip-to-country/8.8.8.8=US\r\n250 OK'
                )
        controller = CountryCodeController()
        r = Router(controller)
        r.update('routername', 'deadbeef', 'orhash', 'modified', '8.8.8.8', '', '')
        loc = yield r.get_location()

        self.assertNotEqual(loc.countrycode, None)
开发者ID:meejah,项目名称:txtorcon,代码行数:15,代码来源:test_router.py

示例7: test_countrycode

# 需要导入模块: from txtorcon.router import Router [as 别名]
# 或者: from txtorcon.router.Router import update [as 别名]
    def test_countrycode(self):
        class CountryCodeController(object):
            def get_info_raw(self, i):
                return defer.succeed('250-ip-to-country/127.1.2.3=ZZ\r\n250 OK')
        controller = CountryCodeController()
        router = Router(controller)
        router.update("foo",
                      "AHhuQ8zFQJdT8l42Axxc6m6kNwI",
                      "MAANkj30tnFvmoh7FsjVFr+cmcs",
                      "2011-12-16 15:11:34",
                      "127.1.2.3",
                      "24051", "24052")

        self.assertEqual(router.location.countrycode, 'ZZ')
开发者ID:arlolra,项目名称:txtorcon,代码行数:16,代码来源:test_router.py

示例8: test_policy_accept

# 需要导入模块: from txtorcon.router import Router [as 别名]
# 或者: from txtorcon.router.Router import update [as 别名]
 def test_policy_accept(self):
     controller = object()
     router = Router(controller)
     router.update("foo",
                   "AHhuQ8zFQJdT8l42Axxc6m6kNwI",
                   "MAANkj30tnFvmoh7FsjVFr+cmcs",
                   "2011-12-16 15:11:34",
                   "77.183.225.114",
                   "24051", "24052")
     router.policy = "accept 25,128-256".split()
     self.assertTrue(router.accepts_port(25))
     for x in range(128, 256):
         self.assertTrue(router.accepts_port(x))
     self.assertTrue(not router.accepts_port(26))
     self.assertEqual(router.policy, 'accept 25,128-256')
开发者ID:arlolra,项目名称:txtorcon,代码行数:17,代码来源:test_router.py

示例9: test_get_location_private

# 需要导入模块: from txtorcon.router import Router [as 别名]
# 或者: from txtorcon.router.Router import update [as 别名]
    def test_get_location_private(self):

        class CountryCodeController(object):
            def get_info_raw(self, i):
                return defer.succeed(
                    '250-ip-to-country/192.168.0.1=ZZ\r\n250 OK'
                )
        controller = CountryCodeController()
        r = Router(controller)
        r.update('routername', 'deadbeef', 'orhash', 'modified', '192.168.0.1', '', '')
        loc0 = yield r.get_location()
        loc1 = yield r.get_location()

        self.assertEqual(loc0.countrycode, 'ZZ')
        self.assertEqual(loc1.countrycode, 'ZZ')
开发者ID:meejah,项目名称:txtorcon,代码行数:17,代码来源:test_router.py

示例10: test_policy_reject

# 需要导入模块: from txtorcon.router import Router [as 别名]
# 或者: from txtorcon.router.Router import update [as 别名]
    def test_policy_reject(self):
        controller = object()
        router = Router(controller)
        router.update("foo",
                      "AHhuQ8zFQJdT8l42Axxc6m6kNwI",
                      "MAANkj30tnFvmoh7FsjVFr+cmcs",
                      "2011-12-16 15:11:34",
                      "77.183.225.114",
                      "24051", "24052")
        router.policy = "reject 500-600,655,7766".split()
        for x in range(1, 500):
            self.assertTrue(router.accepts_port(x))
        for x in range(500, 601):
            self.assertTrue(not router.accepts_port(x))

        self.assertEqual(router.policy, 'reject 500-600,655,7766')
开发者ID:arlolra,项目名称:txtorcon,代码行数:18,代码来源:test_router.py

示例11: _create_router

# 需要导入模块: from txtorcon.router import Router [as 别名]
# 或者: from txtorcon.router.Router import update [as 别名]
    def _create_router(self, **kw):
        id_hex = hexIdFromHash(kw['idhash'])
        try:
            router = self.routers[id_hex]
        except KeyError:
            router = Router(self.protocol)
            self.routers[router.id_hex] = router
        router.from_consensus = True
        router.update(
            kw['nickname'],
            kw['idhash'],
            kw['orhash'],
            kw['modified'],
            kw['ip'],
            kw['orport'],
            kw['dirport'],
        )
        router.flags = kw.get('flags', [])
        if 'bandwidth' in kw:
            router.bandwidth = kw['bandwidth']
        if 'ip_v6' in kw:
            router.ip_v6.extend(kw['ip_v6'])

        if 'guard' in router.flags:
            self.guards[router.id_hex] = router
        if 'authority' in router.flags:
            self.authorities[router.name] = router

        if router.id_hex in self.routers:
            # FIXME should I do an update() on this one??
            router = self.routers[router.id_hex]
        else:
            if router.name in self.routers:
                self.routers[router.name] = None

            else:
                self.routers[router.name] = router

        if router.name in self.routers_by_name:
            self.routers_by_name[router.name].append(router)

        else:
            self.routers_by_name[router.name] = [router]

        self.routers[router.id_hex] = router
        self.routers_by_hash[router.id_hex] = router
        self.all_routers.add(router)
开发者ID:felipedau,项目名称:txtorcon,代码行数:49,代码来源:torstate.py

示例12: test_ctor

# 需要导入模块: from txtorcon.router import Router [as 别名]
# 或者: from txtorcon.router.Router import update [as 别名]
    def test_ctor(self):
        controller = object()
        router = Router(controller)
        router.update("foo",
                      "AHhuQ8zFQJdT8l42Axxc6m6kNwI",
                      "MAANkj30tnFvmoh7FsjVFr+cmcs",
                      "2011-12-16 15:11:34",
                      "77.183.225.114",
                      "24051", "24052")
        self.assertEqual(
            router.id_hex,
            "$00786E43CCC5409753F25E36031C5CEA6EA43702"
        )

        # we assert this twice to cover the cached + uncached cases
        self.assertTrue(isinstance(router.modified, datetime))
        self.assertTrue(isinstance(router.modified, datetime))
        self.assertEqual(router.policy, '')
开发者ID:felipedau,项目名称:txtorcon,代码行数:20,代码来源:test_router.py

示例13: router_from_id

# 需要导入模块: from txtorcon.router import Router [as 别名]
# 或者: from txtorcon.router.Router import update [as 别名]
    def router_from_id(self, routerid):
        """IRouterContainer API"""

        try:
            return self.routers[routerid]

        except KeyError:
            router = Router(self.protocol)
            if routerid[0] != '$':
                raise                   # just re-raise the KeyError

            idhash = routerid[1:41]
            nick = ''
            is_named = False
            if len(routerid) > 41:
                nick = routerid[42:]
                is_named = routerid[42] is '='
            router.update(nick, hashFromHexId(idhash), '0'*27, 'unknown', 'unknown', '0', '0')
            return router
开发者ID:narastabbocchi,项目名称:txtorcon,代码行数:21,代码来源:torstate.py

示例14: router_from_id

# 需要导入模块: from txtorcon.router import Router [as 别名]
# 或者: from txtorcon.router.Router import update [as 别名]
    def router_from_id(self, routerid):
        """IRouterContainer API"""

        try:
            return self.routers[routerid]

        except KeyError:
            router = Router(self.protocol)
            if routerid[0] != "$":
                raise  # just re-raise the KeyError

            idhash = routerid[1:41]
            nick = ""
            is_named = False
            if len(routerid) > 41:
                nick = routerid[42:]
                is_named = routerid[41] is "="
            router.update(nick, hashFromHexId(idhash), "0" * 27, "unknown", "unknown", "0", "0")
            router.name_is_unique = is_named
            return router
开发者ID:aagbsn,项目名称:txtorcon,代码行数:22,代码来源:torstate.py

示例15: TorState

# 需要导入模块: from txtorcon.router import Router [as 别名]
# 或者: from txtorcon.router.Router import update [as 别名]
class TorState(object):
    """
    This tracks the current state of Tor using a TorControlProtocol.

    On setup it first queries the initial state of streams and
    circuits. It then asks for updates via the listeners. It requires
    an ITorControlProtocol instance. The control protocol doesn't need
    to be bootstrapped yet. The Deferred .post_boostrap is driggered
    when the TorState instance is fully ready to go.  The easiest way
    is to use the helper method
    :func:`txtorcon.build_tor_connection`. For details, see the
    implementation of that.

    You may add an :class:`txtorcon.interface.IStreamAttacher` to
    provide a custom mapping for Strams to Circuits (by default Tor
    picks by itself).

    This is also a good example of the various listeners, and acts as
    an :class:`txtorcon.interface.ICircuitContainer` and
    :class:`txtorcon.interface.IRouterContainer`.
    """

    implements(ICircuitListener, ICircuitContainer, IRouterContainer,
               IStreamListener)

    def __init__(self, protocol, bootstrap=True, write_state_diagram=False):
        self.protocol = ITorControlProtocol(protocol)
        ## fixme could use protocol.on_disconnect to re-connect; see issue #3

        ## could override these to get your own Circuit/Stream subclasses
        ## to track these things
        self.circuit_factory = Circuit
        self.stream_factory = Stream

        self.attacher = None
        """If set, provides
        :class:`txtorcon.interface.IStreamAttacher` to attach new
        streams we hear about."""

        self.tor_binary = 'tor'

        self.circuit_listeners = []
        self.stream_listeners = []

        self.addrmap = AddrMap()
        self.circuits = {}               # keys on id (integer)
        self.streams = {}                # keys on id (integer)

        self.routers = {}                # keys by hexid (string) and by unique names
        self.routers_by_name = {}        # keys on name, value always list (many duplicate "Unnamed" routers, for example)
        self.guards = {}                 # potentially-usable as entry guards, I think? (any router with 'Guard' flag)
        self.entry_guards = {}           # from GETINFO entry-guards, our current entry guards
        self.unusable_entry_guards = []  # list of entry guards we didn't parse out
        self.authorities = {}            # keys by name

        self.cleanup = None              # see set_attacher

        class die(object):
            __name__ = 'die'             # FIXME? just to ease spagetti.py:82's pain

            def __init__(self, msg):
                self.msg = msg

            def __call__(self, *args):
                raise RuntimeError(self.msg % tuple(args))

        def nothing(*args):
            pass

        waiting_r = State("waiting_r")
        waiting_w = State("waiting_w")
        waiting_p = State("waiting_p")
        waiting_s = State("waiting_s")

        def ignorable_line(x):
            return x.strip() == '.' or x.strip() == 'OK' or x[:3] == 'ns/' or x.strip() == ''

        waiting_r.add_transition(Transition(waiting_r, ignorable_line, nothing))
        waiting_r.add_transition(Transition(waiting_s, lambda x: x[:2] == 'r ', self._router_begin))
        ## FIXME use better method/func than die!!
        waiting_r.add_transition(Transition(waiting_r, lambda x: x[:2] != 'r ', die('Expected "r " while parsing routers not "%s"')))

        waiting_s.add_transition(Transition(waiting_w, lambda x: x[:2] == 's ', self._router_flags))
        waiting_s.add_transition(Transition(waiting_s, lambda x: x[:2] == 'a ', self._router_address))
        waiting_s.add_transition(Transition(waiting_r, ignorable_line, nothing))
        waiting_s.add_transition(Transition(waiting_r, lambda x: x[:2] != 's ' and x[:2] != 'a ', die('Expected "s " while parsing routers not "%s"')))
        waiting_s.add_transition(Transition(waiting_r, lambda x: x.strip() == '.', nothing))

        waiting_w.add_transition(Transition(waiting_p, lambda x: x[:2] == 'w ', self._router_bandwidth))
        waiting_w.add_transition(Transition(waiting_r, ignorable_line, nothing))
        waiting_w.add_transition(Transition(waiting_s, lambda x: x[:2] == 'r ', self._router_begin))  # "w" lines are optional
        waiting_w.add_transition(Transition(waiting_r, lambda x: x[:2] != 'w ', die('Expected "w " while parsing routers not "%s"')))
        waiting_w.add_transition(Transition(waiting_r, lambda x: x.strip() == '.', nothing))

        waiting_p.add_transition(Transition(waiting_r, lambda x: x[:2] == 'p ', self._router_policy))
        waiting_p.add_transition(Transition(waiting_r, ignorable_line, nothing))
        waiting_p.add_transition(Transition(waiting_s, lambda x: x[:2] == 'r ', self._router_begin))  # "p" lines are optional
        waiting_p.add_transition(Transition(waiting_r, lambda x: x[:2] != 'p ', die('Expected "p " while parsing routers not "%s"')))
        waiting_p.add_transition(Transition(waiting_r, lambda x: x.strip() == '.', nothing))

#.........这里部分代码省略.........
开发者ID:enriquefynn,项目名称:txtorcon,代码行数:103,代码来源:torstate.py


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