本文整理汇总了Python中twisted.names.dns.A属性的典型用法代码示例。如果您正苦于以下问题:Python dns.A属性的具体用法?Python dns.A怎么用?Python dns.A使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类twisted.names.dns
的用法示例。
在下文中一共展示了dns.A属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: namesTest
# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import A [as 别名]
def namesTest(self, querying, expectedRecords):
"""
Assert that the DNS response C{querying} will eventually fire with
contains exactly a certain collection of records.
@param querying: A L{Deferred} returned from one of the DNS client
I{lookup} methods.
@param expectedRecords: A L{list} of L{IRecord} providers which must be
in the response or the test will be failed.
@return: A L{Deferred} that fires when the assertion has been made. It
fires with a success result if the assertion succeeds and with a
L{Failure} if it fails.
"""
def checkResults(response):
receivedRecords = justPayload(response)
self.assertEqual(set(expectedRecords), set(receivedRecords))
querying.addCallback(checkResults)
return querying
示例2: assertRecordsMatch
# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import A [as 别名]
def assertRecordsMatch(self, expected, computed):
"""
Assert that the L{RRHeader} instances given by C{expected} and
C{computed} carry all the same information but without requiring the
records appear in the same order.
@param expected: A L{list} of L{RRHeader} instances giving the expected
records.
@param computed: A L{list} of L{RRHeader} instances giving the records
computed by the scenario under test.
@raise self.failureException: If the two collections of records
disagree.
"""
# RRHeader instances aren't inherently ordered. Impose an ordering
# that's good enough for the purposes of these tests - in which we
# never have more than one record of a particular type.
key = lambda rr: rr.type
self.assertEqual(sorted(expected, key=key), sorted(computed, key=key))
示例3: test_aRecords
# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import 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,
)
示例4: test_NULL
# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import A [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)
示例5: _simpleEqualityTest
# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import A [as 别名]
def _simpleEqualityTest(self, cls):
"""
Assert that instances of C{cls} with the same attributes compare equal
to each other and instances with different attributes compare as not
equal.
@param cls: A L{dns.SimpleRecord} subclass.
"""
# Vary the TTL
self._equalityTest(
cls(b'example.com', 123),
cls(b'example.com', 123),
cls(b'example.com', 321))
# Vary the name
self._equalityTest(
cls(b'example.com', 123),
cls(b'example.com', 123),
cls(b'example.org', 123))
示例6: kwargs
# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import 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,
answer=True,
opCode=dns.OP_STATUS,
auth=True,
trunc=True,
recDes=True,
recAv=True,
rCode=15,
ednsVersion=None,
)
示例7: bytes
# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import A [as 别名]
def bytes(cls):
"""
Bytes which are expected when encoding an instance constructed using
C{kwargs} and which are expected to result in an identical instance when
decoded.
@return: The L{bytes} of a wire encoded message.
"""
return (
b'\x01\x00' # ID: 256
b'\x04' # QR: 0, OPCODE: 0, AA: 1, TC: 0, RD: 0
b'\x00' # RA: 0, Z, RCODE: 0
b'\x00\x00' # Query count
b'\x00\x01' # Answer count
b'\x00\x00' # Authorities count
b'\x00\x00' # Additionals count
# Answer
b'\x00' # RR NAME (root)
b'\x00\x01' # RR TYPE 1 (A)
b'\x00\x01' # RR CLASS 1 (IN)
b'\x00\x00\x00\x00' # RR TTL
b'\x00\x04' # RDLENGTH 4
b'\x01\x02\x03\x04' # IPv4 1.2.3.4
)
示例8: test_constructorExpires
# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import 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)
示例9: test_cachedResultExpires
# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import 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)
示例10: test_expiredTTLLookup
# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import 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)
示例11: _lookup
# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import 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))
示例12: test_multipleSequentialRequests
# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import A [as 别名]
def test_multipleSequentialRequests(self):
"""
After a response is received to a query issued with
L{client.Resolver.query}, another query with the same parameters
results in a new network request.
"""
protocol = StubDNSDatagramProtocol()
resolver = client.Resolver(servers=[('example.com', 53)])
resolver._connectedProtocol = lambda: protocol
queries = protocol.queries
query = dns.Query(b'foo.example.com', dns.A)
# The first query should be passed to the underlying protocol.
resolver.query(query)
self.assertEqual(len(queries), 1)
# Deliver the response.
queries.pop()[-1].callback(dns.Message())
# Repeating the first query should touch the protocol again.
resolver.query(query)
self.assertEqual(len(queries), 1)
示例13: test_multipleConcurrentFailure
# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import A [as 别名]
def test_multipleConcurrentFailure(self):
"""
If the result of a request is an error response, the Deferreds for all
concurrently issued requests associated with that result fire with the
L{Failure}.
"""
protocol = StubDNSDatagramProtocol()
resolver = client.Resolver(servers=[('example.com', 53)])
resolver._connectedProtocol = lambda: protocol
queries = protocol.queries
query = dns.Query(b'foo.example.com', dns.A)
firstResult = resolver.query(query)
secondResult = resolver.query(query)
class ExpectedException(Exception):
pass
queries.pop()[-1].errback(failure.Failure(ExpectedException()))
return defer.gatherResults([
self.assertFailure(firstResult, ExpectedException),
self.assertFailure(secondResult, ExpectedException)])
示例14: _respond
# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import A [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)))
示例15: _additionalRecords
# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import A [as 别名]
def _additionalRecords(self, answer, authority, ttl):
"""
Find locally known information that could be useful to the consumer of
the response and construct appropriate records to include in the
I{additional} section of that response.
Essentially, implement RFC 1034 section 4.3.2 step 6.
@param answer: A L{list} of the records which will be included in the
I{answer} section of the response.
@param authority: A L{list} of the records which will be included in
the I{authority} section of the response.
@param ttl: The default TTL for records for which this is not otherwise
specified.
@return: A generator of L{dns.RRHeader} instances for inclusion in the
I{additional} section. These instances represent extra information
about the records in C{answer} and C{authority}.
"""
for record in answer + authority:
if record.type in self._ADDITIONAL_PROCESSING_TYPES:
name = record.payload.name.name
for rec in self.records.get(name.lower(), ()):
if rec.TYPE in self._ADDRESS_TYPES:
yield dns.RRHeader(
name, rec.TYPE, dns.IN,
rec.ttl or ttl, rec, auth=True)