當前位置: 首頁>>代碼示例>>Python>>正文


Python dns.SRV屬性代碼示例

本文整理匯總了Python中twisted.names.dns.SRV屬性的典型用法代碼示例。如果您正苦於以下問題:Python dns.SRV屬性的具體用法?Python dns.SRV怎麽用?Python dns.SRV使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在twisted.names.dns的用法示例。


在下文中一共展示了dns.SRV屬性的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _cbGotServers

# 需要導入模塊: from twisted.names import dns [as 別名]
# 或者: from twisted.names.dns import SRV [as 別名]
def _cbGotServers(self, result):
        answers, auth, add = result
        if len(answers) == 1 and answers[0].type == dns.SRV \
                             and answers[0].payload \
                             and answers[0].payload.target == dns.Name(b'.'):
            # decidedly not available
            raise error.DNSLookupError("Service %s not available for domain %s."
                                       % (repr(self.service), repr(self.domain)))

        self.servers = []
        self.orderedServers = []
        for a in answers:
            if a.type != dns.SRV or not a.payload:
                continue

            self.orderedServers.append(a.payload) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:18,代碼來源:srvconnect.py

示例2: __init__

# 需要導入模塊: from twisted.names import dns [as 別名]
# 或者: from twisted.names.dns import SRV [as 別名]
def __init__(self, reactor, service, domain, factory,
                 protocol='tcp', connectFuncName='connectTCP',
                 connectFuncArgs=(),
                 connectFuncKwArgs={},
                 defaultPort=None,
                 ):
        """
        @param domain: The domain to connect to.  If passed as a unicode
            string, it will be encoded using C{idna} encoding.
        @type domain: L{bytes} or L{unicode}

        @param defaultPort: Optional default port number to be used when SRV
            lookup fails and the service name is unknown. This should be the
            port number associated with the service name as defined by the IANA
            registry.
        @type defaultPort: L{int}
        """
        self.reactor = reactor
        self.service = service
        if isinstance(domain, unicode):
            domain = domain.encode('idna')
        self.domain = nativeString(domain)
        self.factory = factory

        self.protocol = protocol
        self.connectFuncName = connectFuncName
        self.connectFuncArgs = connectFuncArgs
        self.connectFuncKwArgs = connectFuncKwArgs
        self._defaultPort = defaultPort

        self.connector = None
        self.servers = None
        self.orderedServers = None # list of servers already used in this round 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:35,代碼來源:srvconnect.py

示例3: _ebGotServers

# 需要導入模塊: from twisted.names import dns [as 別名]
# 或者: from twisted.names.dns import SRV [as 別名]
def _ebGotServers(self, failure):
        failure.trap(DNSNameError)

        # Some DNS servers reply with NXDOMAIN when in fact there are
        # just no SRV records for that domain. Act as if we just got an
        # empty response and use fallback.

        self.servers = []
        self.orderedServers = [] 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:11,代碼來源:srvconnect.py

示例4: _ebServiceUnknown

# 需要導入模塊: from twisted.names import dns [as 別名]
# 或者: from twisted.names.dns import SRV [as 別名]
def _ebServiceUnknown(self, failure):
        """
        Connect to the default port when the service name is unknown.

        If no SRV records were found, the service name will be passed as the
        port. If resolving the name fails with
        L{error.ServiceNameUnknownError}, a final attempt is done using the
        default port.
        """
        failure.trap(error.ServiceNameUnknownError)
        self.servers = [dns.Record_SRV(0, 0, self._defaultPort, self.domain)]
        self.orderedServers = []
        self.connect() 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:15,代碼來源:srvconnect.py

示例5: test_SRVPresent

# 需要導入模塊: from twisted.names import dns [as 別名]
# 或者: from twisted.names.dns import SRV [as 別名]
def test_SRVPresent(self):
        """
        Test connectTCP gets called with the address from the SRV record.
        """
        payload = dns.Record_SRV(port=6269, target='host.example.org', ttl=60)
        client.theResolver.results = [dns.RRHeader(name='example.org',
                                                   type=dns.SRV,
                                                   cls=dns.IN, ttl=60,
                                                   payload=payload)]
        self.connector.connect()

        self.assertIsNone(self.factory.reason)
        self.assertEqual(
            self.reactor.tcpClients.pop()[:2], ('host.example.org', 6269)) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:16,代碼來源:test_srvconnect.py

示例6: test_SRVNoService

# 需要導入模塊: from twisted.names import dns [as 別名]
# 或者: from twisted.names.dns import SRV [as 別名]
def test_SRVNoService(self):
        """
        Test that connecting fails when no service is present.
        """
        payload = dns.Record_SRV(port=5269, target=b'.', ttl=60)
        client.theResolver.results = [dns.RRHeader(name='example.org',
                                                   type=dns.SRV,
                                                   cls=dns.IN, ttl=60,
                                                   payload=payload)]
        self.connector.connect()

        self.assertIsNotNone(self.factory.reason)
        self.factory.reason.trap(DNSLookupError)
        self.assertEqual(self.reactor.tcpClients, []) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:16,代碼來源:test_srvconnect.py

示例7: test_lookupService

# 需要導入模塊: from twisted.names import dns [as 別名]
# 或者: from twisted.names.dns import SRV [as 別名]
def test_lookupService(self):
        """
        See L{test_lookupAddress}
        """
        d = client.lookupService(self.hostname)
        d.addCallback(self.checkResult, dns.SRV)
        return d 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:9,代碼來源:test_client.py

示例8: lookupServerViaSRV

# 需要導入模塊: from twisted.names import dns [as 別名]
# 或者: from twisted.names.dns import SRV [as 別名]
def lookupServerViaSRV(domain, service="_ischedules"):

    _initResolver()

    lookup = "{}._tcp.{}".format(service, domain,)
    log.debug("DNS SRV: lookup: {l}", l=lookup)
    try:
        answers = (yield DebugResolver.lookupService(lookup))[0]
    except (DomainError, AuthoritativeDomainError), e:
        log.debug("DNS SRV: lookup failed: {exc}", exc=e)
        returnValue(None) 
開發者ID:apple,項目名稱:ccs-calendarserver,代碼行數:13,代碼來源:utils.py

示例9: pickServer

# 需要導入模塊: from twisted.names import dns [as 別名]
# 或者: from twisted.names.dns import SRV [as 別名]
def pickServer(self):
        assert self.servers is not None
        assert self.orderedServers is not None

        if not self.servers and not self.orderedServers:
            # no SRV record, fall back..
            return self.domain, self.service

        if not self.servers and self.orderedServers:
            # start new round
            self.servers = self.orderedServers
            self.orderedServers = []

        assert self.servers

        self.servers.sort(self._serverCmp)
        minPriority=self.servers[0][0]

        weightIndex = zip(xrange(len(self.servers)), [x[1] for x in self.servers
                                                      if x[0]==minPriority])
        weightSum = reduce(lambda x, y: (None, x[1]+y[1]), weightIndex, (None, 0))[1]
        rand = random.randint(0, weightSum)

        for index, weight in weightIndex:
            weightSum -= weight
            if weightSum <= 0:
                chosen = self.servers[index]
                del self.servers[index]
                self.orderedServers.append(chosen)

                p, w, host, port = chosen
                return host, port

        raise RuntimeError, 'Impossible %s pickServer result.' % self.__class__.__name__ 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:36,代碼來源:srvconnect.py

示例10: lookupService

# 需要導入模塊: from twisted.names import dns [as 別名]
# 或者: from twisted.names.dns import SRV [as 別名]
def lookupService(self, name, timeout = None):
        """
        @see: twisted.names.client.lookupService
        """
        return self._lookup(name, dns.IN, dns.SRV, timeout) 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:7,代碼來源:common.py

示例11: test_SRVPresent

# 需要導入模塊: from twisted.names import dns [as 別名]
# 或者: from twisted.names.dns import SRV [as 別名]
def test_SRVPresent(self):
        """
        Test connectTCP gets called with the address from the SRV record.
        """
        payload = dns.Record_SRV(port=6269, target='host.example.org', ttl=60)
        client.theResolver.results = [dns.RRHeader(name='example.org',
                                                   type=dns.SRV,
                                                   cls=dns.IN, ttl=60,
                                                   payload=payload)]
        self.connector.connect()

        self.assertIdentical(None, self.factory.reason)
        self.assertEquals(
            self.reactor.tcpClients.pop()[:2], ('host.example.org', 6269)) 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:16,代碼來源:test_srvconnect.py

示例12: test_SRVNoService

# 需要導入模塊: from twisted.names import dns [as 別名]
# 或者: from twisted.names.dns import SRV [as 別名]
def test_SRVNoService(self):
        """
        Test that connecting fails when no service is present.
        """
        payload = dns.Record_SRV(port=5269, target='.', ttl=60)
        client.theResolver.results = [dns.RRHeader(name='example.org',
                                                   type=dns.SRV,
                                                   cls=dns.IN, ttl=60,
                                                   payload=payload)]
        self.connector.connect()

        self.assertNotIdentical(None, self.factory.reason)
        self.factory.reason.trap(DNSLookupError)
        self.assertEquals(self.reactor.tcpClients, []) 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:16,代碼來源:test_srvconnect.py

示例13: lookupService

# 需要導入模塊: from twisted.names import dns [as 別名]
# 或者: from twisted.names.dns import SRV [as 別名]
def lookupService(self, name, timeout = None):
        return self._lookup(name, dns.IN, dns.SRV, timeout) 
開發者ID:kenorb-contrib,項目名稱:BitTorrent,代碼行數:4,代碼來源:common.py

示例14: pickServer

# 需要導入模塊: from twisted.names import dns [as 別名]
# 或者: from twisted.names.dns import SRV [as 別名]
def pickServer(self):
        """
        Pick the next server.

        This selects the next server from the list of SRV records according
        to their priority and weight values, as set out by the default
        algorithm specified in RFC 2782.

        At the beginning of a round, L{servers} is populated with
        L{orderedServers}, and the latter is made empty. L{servers}
        is the list of candidates, and L{orderedServers} is the list of servers
        that have already been tried.

        First, all records are ordered by priority and weight in ascending
        order. Then for each priority level, a running sum is calculated
        over the sorted list of records for that priority. Then a random value
        between 0 and the final sum is compared to each record in order. The
        first record that is greater than or equal to that random value is
        chosen and removed from the list of candidates for this round.

        @return: A tuple of target hostname and port from the chosen DNS SRV
            record.
        @rtype: L{tuple} of native L{str} and L{int}
        """
        assert self.servers is not None
        assert self.orderedServers is not None

        if not self.servers and not self.orderedServers:
            # no SRV record, fall back..
            return self.domain, self.service

        if not self.servers and self.orderedServers:
            # start new round
            self.servers = self.orderedServers
            self.orderedServers = []

        assert self.servers

        self.servers.sort(key=lambda record: (record.priority, record.weight))
        minPriority = self.servers[0].priority

        index = 0
        weightSum = 0
        weightIndex = []
        for x in self.servers:
            if x.priority == minPriority:
                weightSum += x.weight
                weightIndex.append((index, weightSum))
                index += 1

        rand = random.randint(0, weightSum)
        for index, weight in weightIndex:
            if weight >= rand:
                chosen = self.servers[index]
                del self.servers[index]
                self.orderedServers.append(chosen)

                return str(chosen.target), chosen.port

        raise RuntimeError(
            'Impossible %s pickServer result.' % (self.__class__.__name__,)) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:63,代碼來源:srvconnect.py


注:本文中的twisted.names.dns.SRV屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。