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


Python dns.RRHeader方法代码示例

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


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

示例1: test_mailExchangePreference

# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import RRHeader [as 别名]
def test_mailExchangePreference(self):
        """
        The MX record with the lowest preference is returned by
        L{MXCalculator.getMX}.
        """
        domain = "example.com"
        good = "good.example.com"
        bad = "bad.example.com"

        records = [
            RRHeader(name=domain,
                     type=Record_MX.TYPE,
                     payload=Record_MX(1, bad)),
            RRHeader(name=domain,
                     type=Record_MX.TYPE,
                     payload=Record_MX(0, good)),
            RRHeader(name=domain,
                     type=Record_MX.TYPE,
                     payload=Record_MX(2, bad))]
        return self._exchangeTest(domain, records, good) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:22,代码来源:test_mail.py

示例2: test_badExchangeExcluded

# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import RRHeader [as 别名]
def test_badExchangeExcluded(self):
        """
        L{MXCalculator.getMX} returns the MX record with the lowest preference
        which is not also marked as bad.
        """
        domain = "example.com"
        good = "good.example.com"
        bad = "bad.example.com"

        records = [
            RRHeader(name=domain,
                     type=Record_MX.TYPE,
                     payload=Record_MX(0, bad)),
            RRHeader(name=domain,
                     type=Record_MX.TYPE,
                     payload=Record_MX(1, good))]
        self.mx.markBad(bad)
        return self._exchangeTest(domain, records, good) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:20,代码来源:test_mail.py

示例3: test_fallbackForAllBadExchanges

# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import RRHeader [as 别名]
def test_fallbackForAllBadExchanges(self):
        """
        L{MXCalculator.getMX} returns the MX record with the lowest preference
        if all the MX records in the response have been marked bad.
        """
        domain = "example.com"
        bad = "bad.example.com"
        worse = "worse.example.com"

        records = [
            RRHeader(name=domain,
                     type=Record_MX.TYPE,
                     payload=Record_MX(0, bad)),
            RRHeader(name=domain,
                     type=Record_MX.TYPE,
                     payload=Record_MX(1, worse))]
        self.mx.markBad(bad)
        self.mx.markBad(worse)
        return self._exchangeTest(domain, records, bad) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:21,代码来源:test_mail.py

示例4: test_goodExchangeUsed

# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import RRHeader [as 别名]
def test_goodExchangeUsed(self):
        """
        L{MXCalculator.getMX} returns the MX record with the lowest preference
        if it was marked good after it was marked bad.
        """
        domain = "example.com"
        good = "good.example.com"
        previouslyBad = "bad.example.com"

        records = [
            RRHeader(name=domain,
                     type=Record_MX.TYPE,
                     payload=Record_MX(0, previouslyBad)),
            RRHeader(name=domain,
                     type=Record_MX.TYPE,
                     payload=Record_MX(1, good))]
        self.mx.markBad(previouslyBad)
        self.mx.markGood(previouslyBad)
        self.clock.advance(self.mx.timeOutBadMX)
        return self._exchangeTest(domain, records, previouslyBad) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:22,代码来源:test_mail.py

示例5: test_cnameLoopWithGlueRecords

# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import RRHeader [as 别名]
def test_cnameLoopWithGlueRecords(self):
        """
        If an MX lookup returns two CNAME records which point to each other,
        the loop should be detected and the L{Deferred} returned by
        L{MXCalculator.getMX} should be errbacked with L{CanonicalNameLoop}.
        """
        firstAlias = "cname1.example.com"
        secondAlias = "cname2.example.com"

        class DummyResolver(object):
            def lookupMailExchange(self, domain):
                return defer.succeed((
                        [RRHeader(name=firstAlias,
                                  type=Record_CNAME.TYPE,
                                  payload=Record_CNAME(secondAlias)),
                         RRHeader(name=secondAlias,
                                  type=Record_CNAME.TYPE,
                                  payload=Record_CNAME(firstAlias))],
                        [], []))

        self.mx.resolver = DummyResolver()
        d = self.mx.getMX(firstAlias)
        self.assertFailure(d, twisted.mail.relaymanager.CanonicalNameLoop)
        return d 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:26,代码来源:test_mail.py

示例6: test_gotResolverResponseCaching

# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import RRHeader [as 别名]
def test_gotResolverResponseCaching(self):
        """
        L{server.DNSServerFactory.gotResolverResponse} caches the response if at
        least one cache was provided in the constructor.
        """
        f = NoResponseDNSServerFactory(caches=[RaisingCache()])

        m = dns.Message()
        m.addQuery(b'example.com')
        expectedAnswers = [dns.RRHeader()]
        expectedAuthority = []
        expectedAdditional = []

        e = self.assertRaises(
            RaisingCache.CacheResultArguments,
            f.gotResolverResponse,
            (expectedAnswers, expectedAuthority, expectedAdditional),
            protocol=NoopProtocol(), message=m, address=None)
        (query, (answers, authority, additional)), kwargs = e.args

        self.assertEqual(query.name.name, b'example.com')
        self.assertIs(answers, expectedAnswers)
        self.assertIs(authority, expectedAuthority)
        self.assertIs(additional, expectedAdditional) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:26,代码来源:test_server.py

示例7: test_sendReplyLoggingWithAnswers

# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import RRHeader [as 别名]
def test_sendReplyLoggingWithAnswers(self):
        """
        If L{server.DNSServerFactory.sendReply} logs a message for answers,
        authority, additional if the supplied a message has records in any of
        those sections.
        """
        self.patch(server.time, 'time', lambda: 2)
        m = dns.Message()
        m.answers.append(dns.RRHeader(payload=dns.Record_A('127.0.0.1')))
        m.authority.append(dns.RRHeader(payload=dns.Record_A('127.0.0.1')))
        m.additional.append(dns.RRHeader(payload=dns.Record_A('127.0.0.1')))
        m.timeReceived = 1
        f = server.DNSServerFactory(verbose=2)
        assertLogMessage(
            self,
            ['Answers are <A address=127.0.0.1 ttl=None>',
             'Authority is <A address=127.0.0.1 ttl=None>',
             'Additional is <A address=127.0.0.1 ttl=None>',
             'Processed query in 1.000 seconds'],
            f.sendReply,
            protocol=NoopProtocol(),
            message=m,
            address=None) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:25,代码来源:test_server.py

示例8: _referralTest

# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import RRHeader [as 别名]
def _referralTest(self, method):
        """
        Create an authority and make a request against it.  Then verify that the
        result is a referral, including no records in the answers or additional
        sections, but with an I{NS} record in the authority section.
        """
        subdomain = 'example.' + str(soa_record.mname)
        nameserver = dns.Record_NS('1.2.3.4')
        authority = NoFileAuthority(
            soa=(str(soa_record.mname), soa_record),
            records={
                subdomain: [
                    nameserver,
                    ]})
        d = getattr(authority, method)(subdomain)
        answer, authority, additional = self.successResultOf(d)
        self.assertEqual(answer, [])
        self.assertEqual(
            authority, [dns.RRHeader(
                    subdomain, dns.NS, ttl=soa_record.expire,
                    payload=nameserver, auth=False)])
        self.assertEqual(additional, []) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:24,代码来源:test_names.py

示例9: _answerCNAMETest

# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import RRHeader [as 别名]
def _answerCNAMETest(self, addresses):
        """
        Verify that a response to a CNAME query has certain records in the
        I{answer} section.

        @param addresses: See C{_additionalTest}
        """
        target = b"www." + soa_record.mname.name
        d = self._lookupSomeRecords(
            "lookupCanonicalName", soa_record, dns.Record_CNAME, target,
            addresses)
        answer, authority, additional = self.successResultOf(d)

        alias = dns.RRHeader(
            soa_record.mname.name, dns.CNAME, ttl=soa_record.expire,
            payload=dns.Record_CNAME(target), auth=True)
        self.assertRecordsMatch(
            [dns.RRHeader(
                    target, address.TYPE, ttl=soa_record.expire, payload=address,
                    auth=True)
             for address in addresses] + [alias],
            answer) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:24,代码来源:test_names.py

示例10: test_NULL

# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import RRHeader [as 别名]
def test_NULL(self):
        """
        A I{NULL} record with an arbitrary payload can be encoded and decoded as
        part of a L{dns.Message}.
        """
        bytes = b''.join([dns._ord2bytes(i) for i in range(256)])
        rec = dns.Record_NULL(bytes)
        rr = dns.RRHeader(b'testname', dns.NULL, payload=rec)
        msg1 = dns.Message()
        msg1.answers.append(rr)
        s = BytesIO()
        msg1.encode(s)
        s.seek(0, 0)
        msg2 = dns.Message()
        msg2.decode(s)

        self.assertIsInstance(msg2.answers[0].payload, dns.Record_NULL)
        self.assertEqual(msg2.answers[0].payload.payload, bytes) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:20,代码来源:test_dns.py

示例11: test_nonAuthoritativeMessage

# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import RRHeader [as 别名]
def test_nonAuthoritativeMessage(self):
        """
        The L{RRHeader} instances created by L{Message} from a non-authoritative
        message are marked as not authoritative.
        """
        buf = BytesIO()
        answer = dns.RRHeader(payload=dns.Record_A('1.2.3.4', ttl=0))
        answer.encode(buf)
        message = dns.Message()
        message.fromStr(
            b'\x01\x00' # Message ID
            # answer bit, opCode nibble, auth bit, trunc bit, recursive bit
            b'\x00'
            # recursion bit, empty bit, authenticData bit,
            # checkingDisabled bit, response code nibble
            b'\x00'
            b'\x00\x00' # number of queries
            b'\x00\x01' # number of answers
            b'\x00\x00' # number of authorities
            b'\x00\x00' # number of additionals
            + buf.getvalue()
            )
        self.assertEqual(message.answers, [answer])
        self.assertFalse(message.answers[0].auth) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:26,代码来源:test_dns.py

示例12: test_authoritativeMessage

# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import RRHeader [as 别名]
def test_authoritativeMessage(self):
        """
        The L{RRHeader} instances created by L{Message} from an authoritative
        message are marked as authoritative.
        """
        buf = BytesIO()
        answer = dns.RRHeader(payload=dns.Record_A('1.2.3.4', ttl=0))
        answer.encode(buf)
        message = dns.Message()
        message.fromStr(
            b'\x01\x00' # Message ID
            # answer bit, opCode nibble, auth bit, trunc bit, recursive bit
            b'\x04'
            # recursion bit, empty bit, authenticData bit,
            # checkingDisabled bit, response code nibble
            b'\x00'
            b'\x00\x00' # number of queries
            b'\x00\x01' # number of answers
            b'\x00\x00' # number of authorities
            b'\x00\x00' # number of additionals
            + buf.getvalue()
            )
        answer.auth = True
        self.assertEqual(message.answers, [answer])
        self.assertTrue(message.answers[0].auth) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:27,代码来源:test_dns.py

示例13: test_authority

# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import RRHeader [as 别名]
def test_authority(self):
        """
        Two L{dns.Message} instances compare equal if they have the same
        authority records.
        """
        self.assertNormalEqualityImplementation(
            self.messageFactory(authority=[dns.RRHeader(
                        b'example.com',
                        type=dns.SOA, payload=dns.Record_SOA())]),
            self.messageFactory(authority=[dns.RRHeader(
                        b'example.com',
                        type=dns.SOA, payload=dns.Record_SOA())]),
            self.messageFactory(authority=[dns.RRHeader(
                        b'example.org',
                        type=dns.SOA, payload=dns.Record_SOA())]),
            ) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:18,代码来源:test_dns.py

示例14: test_simpleQuery

# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import RRHeader [as 别名]
def test_simpleQuery(self):
        """
        Test content received after a query.
        """
        d = self.proto.query([dns.Query(b'foo')])
        self.assertEqual(len(self.proto.liveMessages.keys()), 1)
        m = dns.Message()
        m.id = next(iter(self.proto.liveMessages.keys()))
        m.answers = [dns.RRHeader(payload=dns.Record_A(address='1.2.3.4'))]
        def cb(result):
            self.assertEqual(result.answers[0].payload.dottedQuad(), '1.2.3.4')
        d.addCallback(cb)
        s = m.toStr()
        s = struct.pack('!H', len(s)) + s
        self.proto.dataReceived(s)
        return d 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:18,代码来源:test_dns.py

示例15: kwargs

# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import RRHeader [as 别名]
def kwargs(cls):
        """
        Keyword constructor arguments which are expected to result in an
        instance which returns C{bytes} when encoded.

        @return: A L{dict} of keyword arguments.
        """
        return dict(
            id=256,
            auth=0,
            ednsVersion=None,
            answers=[
                dns.RRHeader(
                    b'',
                    payload=dns.Record_A('1.2.3.4', ttl=0),
                    auth=False)]) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:18,代码来源:test_dns.py


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