Ticket #6095: 6095_v1.diff

File 6095_v1.diff, 3.0 KB (added by borko, 22 months ago)
  • twisted/names/client.py

    diff --git a/twisted/names/client.py b/twisted/names/client.py
    index 27e4828..24e57f5 100644
    a b def createResolver(servers=None, resolvconf=None, hosts=None): 
    536536    else: 
    537537        if hosts is None: 
    538538            hosts = r'c:\windows\hosts' 
     539        hostResolver = hostsModule.Resolver(hosts) 
     540 
    539541        from twisted.internet import reactor 
    540542        bootstrap = _ThreadedResolverImpl(reactor) 
    541         hostResolver = hostsModule.Resolver(hosts) 
    542         theResolver = root.bootstrap(bootstrap) 
     543        clresolver = Resolver(servers, reactor) 
     544        theResolver = root.bootstrap(bootstrap, clresolver) 
    543545 
    544546    L = [hostResolver, cache.CacheResolver(), theResolver] 
    545547    return resolve.ResolverChain(L) 
  • twisted/names/root.py

    diff --git a/twisted/names/root.py b/twisted/names/root.py
    index a6a5eb3..fe366a3 100644
    a b class Resolver(common.ResolverBase): 
    6666    @ivar hints: A C{list} of C{str} giving the dotted quad representation 
    6767        of IP addresses of root servers at which to begin resolving names. 
    6868 
     69    @ivar clresolver: auxiliary resolver for making a query 
     70 
    6971    @ivar _maximumQueries: A C{int} giving the maximum number of queries 
    7072        which will be attempted to resolve a single name. 
    7173 
    7274    @ivar _reactor: A L{IReactorTime} and L{IReactorUDP} provider to use to 
    7375        bind UDP ports and manage timeouts. 
    7476    """ 
    75     def __init__(self, hints, maximumQueries=10, reactor=None): 
     77    def __init__(self, hints, clresolver, maximumQueries=10, reactor=None): 
    7678        common.ResolverBase.__init__(self) 
    7779        self.hints = hints 
    7880        self._maximumQueries = maximumQueries 
    7981        self._reactor = reactor 
     82        self.clresolver = clresolver 
    8083 
    8184 
    8285    def _roots(self): 
    class Resolver(common.ResolverBase): 
    112115            error. 
    113116        @rtype: L{Deferred} 
    114117        """ 
    115         from twisted.names import client 
    116         r = client.Resolver(servers=servers, reactor=self._reactor) 
    117         d = r.queryUDP([query], timeout) 
     118        self.clresolver.servers = servers 
     119        self.clresolver.reactor = self._reactor 
     120 
     121        d = self.clresolver.queryUDP([query], timeout) 
    118122        if filter: 
    119             d.addCallback(r.filterAnswers) 
     123            d.addCallback(self.clresolver.filterAnswers) 
    120124        return d 
    121125 
    122126 
    class DeferredResolver: 
    432436            return makePlaceholder(self.waiting[-1], name) 
    433437        raise AttributeError(name) 
    434438 
    435 def bootstrap(resolver): 
     439def bootstrap(resolver, clresolver): 
    436440    """Lookup the root nameserver addresses using the given resolver 
    437441 
    438442    Return a Resolver which will eventually become a C{root.Resolver} 
    def bootstrap(resolver): 
    444448    f = lambda r: r 
    445449    L = [resolver.getHostByName('%s.root-servers.net' % d).addCallback(f) for d in domains] 
    446450    d = defer.DeferredList(L) 
    447     d.addCallback(lambda r: Resolver([e[1] for e in r if e[0]])) 
     451    d.addCallback(lambda r: Resolver([e[1] for e in r if e[0]], clresolver)) 
    448452    return DeferredResolver(d)