本文整理汇总了Python中twisted.names.dns.IN属性的典型用法代码示例。如果您正苦于以下问题:Python dns.IN属性的具体用法?Python dns.IN怎么用?Python dns.IN使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类twisted.names.dns
的用法示例。
在下文中一共展示了dns.IN属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: bytes
# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import IN [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
)
示例2: test_cachedResultExpires
# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import IN [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)
示例3: test_expiredTTLLookup
# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import IN [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)
示例4: bytes
# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import IN [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'\x00' # QR: 0, OPCODE: 0, AA: 0, 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
)
示例5: test_constructorExpires
# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import IN [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)
示例6: _lookup
# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import IN [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)))
示例7: _additionalRecords
# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import IN [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)
示例8: lookupZone
# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import IN [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)))
示例9: class_IN
# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import IN [as 别名]
def class_IN(self, ttl, type, domain, rdata):
"""
Simulate a class IN and recurse into the actual class.
@param ttl: time to live for the record
@type ttl: L{int}
@param type: record type
@type type: str
@param domain: the domain
@type domain: bytes
@param rdata:
@type rdate: bytes
"""
record = getattr(dns, 'Record_%s' % (nativeString(type),), None)
if record:
r = record(*rdata)
r.ttl = ttl
self.records.setdefault(domain.lower(), []).append(r)
if type == 'SOA':
self.soa = (domain, r)
else:
raise NotImplementedError(
"Record type %r not supported" % (nativeString(type),)
)
示例10: lookupAddress
# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import IN [as 别名]
def lookupAddress(self, name, timeout=None):
return self._lookup(name, dns.IN, dns.A, timeout)
示例11: lookupAddress6
# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import IN [as 别名]
def lookupAddress6(self, name, timeout=None):
return self._lookup(name, dns.IN, dns.A6, timeout)
示例12: lookupMailExchange
# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import IN [as 别名]
def lookupMailExchange(self, name, timeout=None):
return self._lookup(name, dns.IN, dns.MX, timeout)
示例13: lookupNameservers
# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import IN [as 别名]
def lookupNameservers(self, name, timeout=None):
return self._lookup(name, dns.IN, dns.NS, timeout)
示例14: lookupCanonicalName
# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import IN [as 别名]
def lookupCanonicalName(self, name, timeout=None):
return self._lookup(name, dns.IN, dns.CNAME, timeout)
示例15: lookupMailBox
# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import IN [as 别名]
def lookupMailBox(self, name, timeout=None):
return self._lookup(name, dns.IN, dns.MB, timeout)