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


Python dns.Record_A方法代码示例

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


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

示例1: test_sendReplyLoggingWithAnswers

# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import Record_A [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

示例2: test_aRecords

# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import Record_A [as 别名]
def test_aRecords(self):
        """
        A records are loaded.
        """
        for dom, ip in [(b"example.com", u"10.0.0.1"),
                        (b"no-in.example.com", u"10.0.0.2")]:
            rr = self.successResultOf(
                self.auth.lookupAddress(dom)
            )[0][0]
            self.assertEqual(
                dns.Record_A(
                    ip,
                    604800,
                ),
                rr.payload,
            ) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:18,代码来源:test_names.py

示例3: test_nonAuthoritativeMessage

# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import Record_A [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

示例4: test_authoritativeMessage

# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import Record_A [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

示例5: test_simpleQuery

# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import Record_A [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

示例6: kwargs

# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import Record_A [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

示例7: test_constructorExpires

# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import Record_A [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

示例8: test_cachedResultExpires

# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import Record_A [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

示例9: _lookup

# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import Record_A [as 别名]
def _lookup(self, name, cls, qtype, timeout):
        """
        The getHostByNameTest does a different type of query that requires it
        return an A record from an ALL_RECORDS lookup, so we accommodate that
        here.
        """
        if name == b'getHostByNameTest':
            rr = dns.RRHeader(name=name, type=dns.A, cls=cls, ttl=60,
                    payload=dns.Record_A(address='127.0.0.1', ttl=60))
        else:
            rr = dns.RRHeader(name=name, type=qtype, cls=cls, ttl=60)

        results = [rr]
        authority = []
        additional = []
        return defer.succeed((results, authority, additional)) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:18,代码来源:test_client.py

示例10: test_sendReplyLoggingWithAnswers

# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import Record_A [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: 86402)
        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 = 86401
        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:wistbean,项目名称:learn_python3_spider,代码行数:25,代码来源:test_server.py

示例11: test_expiredTTLLookup

# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import Record_A [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:wistbean,项目名称:learn_python3_spider,代码行数:27,代码来源:test_cache.py

示例12: test_lookupAddress

# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import Record_A [as 别名]
def test_lookupAddress(self):
        """
        L{root.Resolver.lookupAddress} looks up the I{A} records for the
        specified hostname by first querying one of the root servers the
        resolver was created with and then following the authority delegations
        until a result is received.
        """
        servers = {
            ('1.1.2.3', 53): {
                ('foo.example.com', A): {
                    'authority': [('foo.example.com', Record_NS('ns1.example.com'))],
                    'additional': [('ns1.example.com', Record_A('34.55.89.144'))],
                    },
                },
            ('34.55.89.144', 53): {
                ('foo.example.com', A): {
                    'answers': [('foo.example.com', Record_A('10.0.0.1'))],
                    }
                },
            }
        resolver = self._getResolver(servers)
        d = resolver.lookupAddress('foo.example.com')
        d.addCallback(lambda (ans, auth, add): ans[0].payload.dottedQuad())
        d.addCallback(self.assertEquals, '10.0.0.1')
        return d 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:27,代码来源:test_rootresolve.py

示例13: test_returnCanonicalName

# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import Record_A [as 别名]
def test_returnCanonicalName(self):
        """
        If a I{CNAME} record is encountered as the answer to a query for
        another record type, that record is returned as the answer.
        """
        servers = {
            ('1.1.2.3', 53): {
                ('example.com', A): {
                    'answers': [('example.com', Record_CNAME('example.net')),
                                ('example.net', Record_A('10.0.0.7'))],
                    },
                },
            }
        resolver = self._getResolver(servers)
        d = resolver.lookupAddress('example.com')
        d.addCallback(lambda (ans, auth, add): ans)
        d.addCallback(
            self.assertEquals,
            [RRHeader('example.com', CNAME, payload=Record_CNAME('example.net')),
             RRHeader('example.net', A, payload=Record_A('10.0.0.7'))])
        return d 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:23,代码来源:test_rootresolve.py

示例14: test_followCanonicalName

# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import Record_A [as 别名]
def test_followCanonicalName(self):
        """
        If no record of the requested type is included in a response, but a
        I{CNAME} record for the query name is included, queries are made to
        resolve the value of the I{CNAME}.
        """
        servers = {
            ('1.1.2.3', 53): {
                ('example.com', A): {
                    'answers': [('example.com', Record_CNAME('example.net'))],
                },
                ('example.net', A): {
                    'answers': [('example.net', Record_A('10.0.0.5'))],
                },
            },
        }
        resolver = self._getResolver(servers)
        d = resolver.lookupAddress('example.com')
        d.addCallback(lambda (ans, auth, add): ans)
        d.addCallback(
            self.assertEquals,
            [RRHeader('example.com', CNAME, payload=Record_CNAME('example.net')),
             RRHeader('example.net', A, payload=Record_A('10.0.0.5'))])
        return d 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:26,代码来源:test_rootresolve.py

示例15: test_addressRecord1

# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import Record_A [as 别名]
def test_addressRecord1(self):
        """Test simple DNS 'A' record queries"""
        return self.namesTest(
            self.resolver.lookupAddress('test-domain.com'),
            [dns.Record_A('127.0.0.1', ttl=19283784)]
        ) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:8,代码来源:test_names.py


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