/usr/share/pyshared/twisted/names/resolve.py is in python-twisted-names 11.1.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | # Copyright (c) Twisted Matrix Laboratories.
# See LICENSE for details.
"""
Lookup a name using multiple resolvers.
Future Plans: This needs someway to specify which resolver answered
the query, or someway to specify (authority|ttl|cache behavior|more?)
@author: Jp Calderone
"""
from twisted.internet import defer, interfaces
from twisted.names import dns
from zope.interface import implements
import common
class FailureHandler:
def __init__(self, resolver, query, timeout):
self.resolver = resolver
self.query = query
self.timeout = timeout
def __call__(self, failure):
# AuthoritativeDomainErrors should halt resolution attempts
failure.trap(dns.DomainError, defer.TimeoutError, NotImplementedError)
return self.resolver(self.query, self.timeout)
class ResolverChain(common.ResolverBase):
"""Lookup an address using multiple C{IResolver}s"""
implements(interfaces.IResolver)
def __init__(self, resolvers):
common.ResolverBase.__init__(self)
self.resolvers = resolvers
def _lookup(self, name, cls, type, timeout):
q = dns.Query(name, type, cls)
d = self.resolvers[0].query(q, timeout)
for r in self.resolvers[1:]:
d = d.addErrback(
FailureHandler(r.query, q, timeout)
)
return d
def lookupAllRecords(self, name, timeout = None):
d = self.resolvers[0].lookupAllRecords(name, timeout)
for r in self.resolvers[1:]:
d = d.addErrback(
FailureHandler(r.lookupAllRecords, name, timeout)
)
return d
|