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


Python reactor.resolve函数代码示例

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


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

示例1: startAudio

 def startAudio(self, sdp):
     md = sdp.getMediaDescription('audio')
     addr = md.ipaddr or sdp.ipaddr
     def go(ipaddr):
         remoteAddr = (ipaddr, md.port)
         return RTPStart(cookie=self.cookie, targethost=remoteAddr[0], targetport=remoteAddr[1]).do(self.rtp)
     reactor.resolve(addr).addCallback(go)
开发者ID:habnabit,项目名称:divmod-sine,代码行数:7,代码来源:useragent.py

示例2: startProtocol

    def startProtocol(self):

        print "1. Start protocol"

        # Come prima cosa risolvo il nome
        # TODO: devo unserire una cache nella risoluzione
        reactor.resolve(self.server_address).addCallbacks(self.got_ip, self.no_ip)
        self.start_tout(CtrlUnitDatagramProtocol.ERR_NO_DNS_RESOLUTION, "IP resolution")
开发者ID:henry-spinitalia,项目名称:Fuelcheck,代码行数:8,代码来源:fc_sender.py

示例3: startProtocol

 def startProtocol(self):
   #==============================
   def _start_protocol(ip):
     """This is called once the host is resolved."""
     
     self.host = ip
     self.transport.connect(self.host, self.port)
     self.authenticate()
   
   reactor.resolve(self.host).addCallback(_start_protocol)
开发者ID:adrianlee,项目名称:rcon-cs,代码行数:10,代码来源:client.py

示例4: __init__

	def __init__(self, host):
		self.clientFactory = SnarlNetworkProtocolClientFactory()
		self.serverFactory = SnarlNetworkProtocolServerFactory()

		if host.enable_outgoing.value:
			reactor.resolve(host.address.value).addCallback(self.gotIP).addErrback(self.noIP)

		if host.enable_incoming.value:
			self.serverPort = reactor.listenTCP(SNP_TCP_PORT, self.serverFactory)
			self.pending += 1
开发者ID:13K-OMAR,项目名称:enigma2-plugins-sh4,代码行数:10,代码来源:SNP.py

示例5: add_device

    def add_device(self, device):
        """ Add a single device to the list of devices that we have
        """
        def really_add_device(addr):
            device.host = addr
            reactor.connectTCP(device.host, device.port, self.client_factory)
            self.devices[device.name] = device
            self.addr_mapping[(device.host, device.port)] = device
            device.add_proxy(self)

        reactor.resolve(device.host).addCallback(really_add_device)
开发者ID:braamotto,项目名称:katcp-python,代码行数:11,代码来源:proxy.py

示例6: get

    def get(self):
        host = self.config.get('destination', self.hostname)

        try:
            ip = yield reactor.resolve(host)
        except:
            ip = None

        if ip:
            try:
                loss, latency = yield icmp.ping(ip, 5)
            except: 
                loss, latency = 100, None

            event = [self.createEvent('ok', '%s%% loss to %s' % (loss,host), loss,
                prefix="loss")]

            if latency:
                event.append(self.createEvent('ok', 'Latency to %s' % host, latency,
                            prefix="latency"))
        else:
            event = [self.createEvent('critical', 'Unable to resolve %s' % host, 100,
                prefix="loss")]

        defer.returnValue(event)
开发者ID:DKrul,项目名称:tensor,代码行数:25,代码来源:network.py

示例7: resolve

def resolve(parsedPath):
    arguments = urlparse.parse_qs(parsedPath.query)
    hostname = arguments["hostname"][0]
    try:
        ip = yield reactor.resolve(hostname)
    except Exception, e:
        message = str(e)
开发者ID:keithel,项目名称:twisted-tdd-httpserver,代码行数:7,代码来源:demo2.py

示例8: initialize

    def initialize(self):
        self.clean()

        def resolveCb(result):
            self.mangle.createChain(chain="cattivo")

            entry = self._createAuthenticatorEntry(result)
            self.mangle.appendEntry(entry, chain="cattivo")

            entry = self._createLocalTrafficEntry()
            self.mangle.appendEntry(entry, chain="cattivo")

            entry = self._createDefaultTproxyEntry()
            self.mangle.appendEntry(entry, chain="cattivo")
            self.mangle.commit()

            entry = self._createJumpInCattivoEntry()
            self.mangle.appendEntry(entry, chain="PREROUTING")
            self.mangle.commit()

        authenticator = cattivo.config.get("authenticator", "host")
        url = URLPath.fromString(authenticator)
        address = url.netloc
        dfr = reactor.resolve(address)
        dfr.addCallback(resolveCb)

        return dfr
开发者ID:alessandrod,项目名称:cattivo,代码行数:27,代码来源:base.py

示例9: __init__

 def __init__(self, torrent, url, verbose=None):
     self._torrent = torrent
     self._verbose = verbose
     self.status = "Connecting..."
     self._connection_id = None
     self._msngr = None
     self.seeders = -1 #negative means not connected yet
     self.leechers = -1
     if not url.startswith('udp://'):
         raise ValueError("URL should be udp")
     else:
         u, p = url.split('/')[2].split(':')
         if self._verbose > 10: print("Trying to resolve ip for %s"%u)
         self._url  = url
         self._port = int(p)
         reactor.resolve(u).addCallbacks(self._ip_resolved, self._ip_failed)
开发者ID:DhruvPatel01,项目名称:dtoc,代码行数:16,代码来源:Tracker.py

示例10: get_deferred_host_ip

def get_deferred_host_ip():
    global _host_ip
    global _host_ip_callbacks
    global _host_ip_cachetime
    assert reactor.ident == thread.get_ident()

    if _host_ip is not "unknown" and _host_ip_cachetime + CACHE_TIME > bttime():
        return defer.succeed(_host_ip)

    df = defer.Deferred()

    if not _host_ip_callbacks:

        def connect(ip):
            factory = RecorderFactory()
            factory.protocol = RecorderProtocol
            if hasattr(reactor, "limiter"):
                reactor.connectTCP(ip, 80, factory, urgent=True)
            else:
                reactor.connectTCP(ip, 80, factory)

        rdf = reactor.resolve("ip.bittorrent.com")
        rdf.addCallback(connect)
        rdf.addErrback(lambda e: _got_result(None))

    _host_ip_callbacks.append(df)

    return df
开发者ID:BackupTheBerlios,项目名称:tf-b4rt-svn,代码行数:28,代码来源:HostIP.py

示例11: get_local_ip

def get_local_ip():
    """
    Returns a deferred which will be called with a
    2-uple (lan_flag, ip_address) :
        - lan_flag:
            - True if it's a local network (RFC1918)
            - False if it's a WAN address

        - ip_address is the actual ip address

    @return: A deferred called with the above defined tuple
    @rtype: L{twisted.internet.defer.Deferred}
    """
    # first we try a connected udp socket, then via multicast
    logging.debug("Resolving dns to get udp ip")
    try:
        ipaddr = yield reactor.resolve('A.ROOT-SERVERS.NET')
    except:
        pass
    else:
        udpprot = DatagramProtocol()
        port = reactor.listenUDP(0, udpprot)
        udpprot.transport.connect(ipaddr, 7)
        localip = udpprot.transport.getHost().host
        port.stopListening()

        if is_bogus_ip(localip):
            raise RuntimeError("Invalid IP address returned")
        else:
            defer.returnValue((is_rfc1918_ip(localip), localip))

    logging.debug("Multicast ping to retrieve local IP")
    ipaddr = yield _discover_multicast()
    defer.returnValue((is_rfc1918_ip(ipaddr), ipaddr))
开发者ID:llazzaro,项目名称:p2pool,代码行数:34,代码来源:ipdiscover.py

示例12: announce

 def announce(self, torrent):
     self.torrent = torrent
     host = yield reactor.resolve(self.host, timeout=(1, 3))
     self.host = host
     reactor.listenUDP(self.factory.track_port, self)
     peers = yield self.deferred
     defer.returnValue(peers)
开发者ID:jschneier,项目名称:TwistedTorrent,代码行数:7,代码来源:tracker.py

示例13: create

    def create(host, port, connect_callback=None, disconnect_callback=None,
               resolver_errback=None):
        """Create an instance that resolves the host to an IP asynchronously.

        Will queue all messages while the host is not yet resolved.

        Build a connection that reports to the endpoint (on C{host} and
        C{port}) using UDP.

        @param host: The StatsD server host.
        @param port: The StatsD server port.
        @param resolver_errback: The errback to invoke should
            issues occur resolving the supplied C{host}.
        @param connect_callback: The callback to invoke on connection.
        @param disconnect_callback: The callback to invoke on disconnection."""
        from twisted.internet import reactor

        instance = TwistedStatsDClient(
            host=host, port=port, connect_callback=connect_callback,
            disconnect_callback=disconnect_callback)

        if resolver_errback is None:
            resolver_errback = log.err

        instance.resolve_later = reactor.resolve(host)
        instance.resolve_later.addCallbacks(instance.host_resolved,
                                            resolver_errback)

        return instance
开发者ID:depop,项目名称:txstatsd,代码行数:29,代码来源:protocol.py

示例14: _resolveStunServers

 def _resolveStunServers(self, localAddress):
     self.localAddress = localAddress
     # reactor.resolve the hosts!
     for host, port in self.servers:
         d = reactor.resolve(host)
         #添加向stun server发送消息的函数
         d.addCallback(lambda x,p=port: self.initialStunRequest((x, p)))
开发者ID:db005,项目名称:stunclient,代码行数:7,代码来源:stun.py

示例15: resolve

    def resolve(self, hostname):
        """Asynchronously resolve a hostname, with caching."""
        ip = self.dns_cache.get(hostname, None)
        if ip is None:
            ip = yield reactor.resolve(hostname)
            self.dns_cache[hostname] = ip

        defer.returnValue(ip)
开发者ID:zenoss,项目名称:ZenPacks.zenoss.AWS,代码行数:8,代码来源:utils.py


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