本文整理匯總了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)
示例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)
示例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)
示例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)
示例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
示例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)
示例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)
示例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, [])
示例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)
示例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)
示例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)
示例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)
示例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())]),
)
示例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
示例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)])