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


Python dns.DomainError方法代码示例

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


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

示例1: test_constructorExpires

# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import DomainError [as 别名]
def test_constructorExpires(self):
        """
        Cache entries passed into L{cache.CacheResolver.__init__} get
        cancelled just like entries added with cacheResult
        """
        r = ([dns.RRHeader(b"example.com", dns.A, dns.IN, 60,
                           dns.Record_A("127.0.0.1", 60))],
             [dns.RRHeader(b"example.com", dns.A, dns.IN, 50,
                           dns.Record_A("127.0.0.1", 50))],
             [dns.RRHeader(b"example.com", dns.A, dns.IN, 40,
                           dns.Record_A("127.0.0.1", 40))])

        clock = task.Clock()
        query = dns.Query(name=b"example.com", type=dns.A, cls=dns.IN)

        c = cache.CacheResolver({ query : (clock.seconds(), r)}, reactor=clock)

        # 40 seconds is enough to expire the entry because expiration is based
        # on the minimum TTL.
        clock.advance(40)

        self.assertNotIn(query, c.cache)

        return self.assertFailure(
            c.lookupAddress(b"example.com"), dns.DomainError) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:27,代码来源:test_cache.py

示例2: test_cachedResultExpires

# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import DomainError [as 别名]
def test_cachedResultExpires(self):
        """
        Once the TTL has been exceeded, the result is removed from the cache.
        """
        r = ([dns.RRHeader(b"example.com", dns.A, dns.IN, 60,
                           dns.Record_A("127.0.0.1", 60))],
             [dns.RRHeader(b"example.com", dns.A, dns.IN, 50,
                           dns.Record_A("127.0.0.1", 50))],
             [dns.RRHeader(b"example.com", dns.A, dns.IN, 40,
                           dns.Record_A("127.0.0.1", 40))])

        clock = task.Clock()

        c = cache.CacheResolver(reactor=clock)
        query = dns.Query(name=b"example.com", type=dns.A, cls=dns.IN)
        c.cacheResult(query, r)

        clock.advance(40)

        self.assertNotIn(query, c.cache)

        return self.assertFailure(
            c.lookupAddress(b"example.com"), dns.DomainError) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:25,代码来源:test_cache.py

示例3: test_expiredTTLLookup

# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import DomainError [as 别名]
def test_expiredTTLLookup(self):
        """
        When the cache is queried exactly as the cached entry should expire but
        before it has actually been cleared, the cache does not return the
        expired entry.
        """
        r = ([dns.RRHeader(b"example.com", dns.A, dns.IN, 60,
                           dns.Record_A("127.0.0.1", 60))],
             [dns.RRHeader(b"example.com", dns.A, dns.IN, 50,
                           dns.Record_A("127.0.0.1", 50))],
             [dns.RRHeader(b"example.com", dns.A, dns.IN, 40,
                           dns.Record_A("127.0.0.1", 40))])

        clock = task.Clock()
        # Make sure timeouts never happen, so entries won't get cleared:
        clock.callLater = lambda *args, **kwargs: None

        c = cache.CacheResolver({
            dns.Query(name=b"example.com", type=dns.A, cls=dns.IN) :
                (clock.seconds(), r)}, reactor=clock)

        clock.advance(60.1)

        return self.assertFailure(
            c.lookupAddress(b"example.com"), dns.DomainError) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:27,代码来源:test_cache.py

示例4: _respond

# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import DomainError [as 别名]
def _respond(self, name, records):
        """
        Generate a response for the given name containing the given result
        records, or a failure if there are no result records.

        @param name: The DNS name the response is for.
        @type name: C{str}

        @param records: A tuple of L{dns.RRHeader} instances giving the results
            that will go into the response.

        @return: A L{Deferred} which will fire with a three-tuple of result
            records, authority records, and additional records, or which will
            fail with L{dns.DomainError} if there are no result records.
        """
        if records:
            return defer.succeed((records, (), ()))
        return defer.fail(failure.Failure(dns.DomainError(name))) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:20,代码来源:hosts.py

示例5: lookupZone

# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import DomainError [as 别名]
def lookupZone(self, name, timeout = 10):
        if self.soa[0].lower() == name.lower():
            # Wee hee hee hooo yea
            default_ttl = max(self.soa[1].minimum, self.soa[1].expire)
            if self.soa[1].ttl is not None:
                soa_ttl = self.soa[1].ttl
            else:
                soa_ttl = default_ttl
            results = [dns.RRHeader(self.soa[0], dns.SOA, dns.IN, soa_ttl, self.soa[1], auth=True)]
            for (k, r) in self.records.items():
                for rec in r:
                    if rec.ttl is not None:
                        ttl = rec.ttl
                    else:
                        ttl = default_ttl
                    if rec.TYPE != dns.SOA:
                        results.append(dns.RRHeader(k, rec.TYPE, dns.IN, ttl, rec, auth=True))
            results.append(results[0])
            return defer.succeed((results, (), ()))
        return defer.fail(failure.Failure(dns.DomainError(name))) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:22,代码来源:authority.py

示例6: _lookup

# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import DomainError [as 别名]
def _lookup(self, name, cls, type, timeout = None):
        if name in self.addresses and type == dns.MX:
            results = []
            for a in self.addresses[name]:
                hdr = dns.RRHeader(
                    name, dns.MX, dns.IN, 60, dns.Record_MX(0, a)
                )
                results.append(hdr)
            return defer.succeed((results, [], []))
        return defer.fail(failure.Failure(dns.DomainError(name))) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:12,代码来源:test_mail.py

示例7: gotResolverError

# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import DomainError [as 别名]
def gotResolverError(self, failure, protocol, message, address):
        """
        A callback used by L{DNSServerFactory.handleQuery} for handling deferred
        errors from C{self.resolver.query}.

        Constructs a response message from the original query message by
        assigning a suitable error code to C{rCode}.

        An error message will be logged if C{DNSServerFactory.verbose} is C{>1}.

        @param failure: The reason for the failed resolution (as reported by
            C{self.resolver.query}).
        @type failure: L{Failure<twisted.python.failure.Failure>}

        @param protocol: The DNS protocol instance to which to send a response
            message.
        @type protocol: L{dns.DNSDatagramProtocol} or L{dns.DNSProtocol}

        @param message: The original DNS query message for which a response
            message will be constructed.
        @type message: L{dns.Message}

        @param address: The address to which the response message will be sent
            or L{None} if C{protocol} is a stream protocol.
        @type address: L{tuple} or L{None}
        """
        if failure.check(dns.DomainError, dns.AuthoritativeDomainError):
            rCode = dns.ENAME
        else:
            rCode = dns.ESERVER
            log.err(failure)

        response = self._responseFromMessage(message=message, rCode=rCode)

        self.sendReply(protocol, response, address)
        self._verboseLog("Lookup failed") 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:38,代码来源:server.py

示例8: lookupZone

# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import DomainError [as 别名]
def lookupZone(self, name, timeout=10):
        if self.soa[0].lower() == name.lower():
            # Wee hee hee hooo yea
            default_ttl = max(self.soa[1].minimum, self.soa[1].expire)
            if self.soa[1].ttl is not None:
                soa_ttl = self.soa[1].ttl
            else:
                soa_ttl = default_ttl
            results = [
                dns.RRHeader(
                    self.soa[0], dns.SOA, dns.IN, soa_ttl, self.soa[1],
                    auth=True
                )
            ]
            for (k, r) in self.records.items():
                for rec in r:
                    if rec.ttl is not None:
                        ttl = rec.ttl
                    else:
                        ttl = default_ttl
                    if rec.TYPE != dns.SOA:
                        results.append(
                            dns.RRHeader(
                                k, rec.TYPE, dns.IN, ttl, rec, auth=True
                            )
                        )
            results.append(results[0])
            return defer.succeed((results, (), ()))
        return defer.fail(failure.Failure(dns.DomainError(name))) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:31,代码来源:authority.py

示例9: _lookup

# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import DomainError [as 别名]
def _lookup(self, name, cls, type, timeout=None):
        if not self.soa or not self.records:
            return defer.fail(failure.Failure(dns.DomainError(name)))
        return FileAuthority._lookup(self, name, cls, type, timeout) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:6,代码来源:secondary.py

示例10: _lookup

# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import DomainError [as 别名]
def _lookup(self, name, cls, type, timeout):
        now = self._reactor.seconds()
        q = dns.Query(name, type, cls)
        try:
            when, (ans, auth, add) = self.cache[q]
        except KeyError:
            if self.verbose > 1:
                log.msg('Cache miss for ' + repr(name))
            return defer.fail(failure.Failure(dns.DomainError(name)))
        else:
            if self.verbose:
                log.msg('Cache hit for ' + repr(name))
            diff = now - when

            try:
                result = (
                    [dns.RRHeader(r.name.name, r.type, r.cls, r.ttl - diff,
                                  r.payload) for r in ans],
                    [dns.RRHeader(r.name.name, r.type, r.cls, r.ttl - diff,
                                  r.payload) for r in auth],
                    [dns.RRHeader(r.name.name, r.type, r.cls, r.ttl - diff,
                                  r.payload) for r in add])
            except ValueError:
                return defer.fail(failure.Failure(dns.DomainError(name)))
            else:
                return defer.succeed(result) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:28,代码来源:cache.py

示例11: __call__

# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import DomainError [as 别名]
def __call__(self, failure):
        # AuthoritativeDomainErrors should halt resolution attempts
        failure.trap(dns.DomainError, defer.TimeoutError, NotImplementedError)
        return self.resolver(self.query, self.timeout) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:6,代码来源:resolve.py

示例12: _lookup

# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import DomainError [as 别名]
def _lookup(self, name, cls, type, timeout):
        """
        Build a L{dns.Query} for the given parameters and dispatch it
        to each L{IResolver} in C{self.resolvers} until an answer or
        L{error.AuthoritativeDomainError} is returned.

        @type name: C{str}
        @param name: DNS name to resolve.

        @type type: C{int}
        @param type: DNS record type.

        @type cls: C{int}
        @param cls: DNS record class.

        @type timeout: Sequence of C{int}
        @param timeout: Number of seconds after which to reissue the query.
            When the last timeout expires, the query is considered failed.

        @rtype: L{Deferred}
        @return: A L{Deferred} which fires with a three-tuple of lists of
            L{twisted.names.dns.RRHeader} instances.  The first element of the
            tuple gives answers.  The second element of the tuple gives
            authorities.  The third element of the tuple gives additional
            information.  The L{Deferred} may instead fail with one of the
            exceptions defined in L{twisted.names.error} or with
            C{NotImplementedError}.
        """
        if not self.resolvers:
            return defer.fail(error.DomainError())
        q = dns.Query(name, type, cls)
        d = self.resolvers[0].query(q, timeout)
        for r in self.resolvers[1:]:
            d = d.addErrback(
                FailureHandler(r.query, q, timeout)
            )
        return d 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:39,代码来源:resolve.py

示例13: lookupAllRecords

# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import DomainError [as 别名]
def lookupAllRecords(self, name, timeout = None):
        return defer.fail(failure.Failure(dns.DomainError(name))) 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:4,代码来源:cache.py

示例14: lookupAllRecords

# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import DomainError [as 别名]
def lookupAllRecords(self, name, timeout=None):
        # XXX: Why is this necessary? dns.ALL_RECORDS queries should
        # be handled just the same as any other type by _lookup
        # above. If I remove this method all names tests still
        # pass. See #6604 -rwall
        if not self.resolvers:
            return defer.fail(error.DomainError())
        d = self.resolvers[0].lookupAllRecords(name, timeout)
        for r in self.resolvers[1:]:
            d = d.addErrback(
                FailureHandler(r.lookupAllRecords, name, timeout)
            )
        return d 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:15,代码来源:resolve.py

示例15: gotResolverError

# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import DomainError [as 别名]
def gotResolverError(self, failure, protocol, message, address):
        if failure.check(dns.DomainError, dns.AuthoritativeDomainError):
            message.rCode = dns.ENAME
        else:
            message.rCode = dns.ESERVER
            log.err(failure)

        self.sendReply(protocol, message, address)
        if self.verbose:
            log.msg("Lookup failed") 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:12,代码来源:server.py


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