def test_resolves13RootServers(self): """ The L{IResolverSimple} supplied to L{root.bootstrap} is used to lookup the IP addresses of the 13 root name servers. """ stubResolver = StubResolver() root.bootstrap(stubResolver) self.assertEqual(stubResolver.calls, [((s,), {}) for s in ROOT_SERVERS])
def test_resolves13RootServers(self): """ The L{IResolverSimple} supplied to L{root.bootstrap} is used to lookup the IP addresses of the 13 root name servers. """ stubResolver = StubResolver() root.bootstrap(stubResolver) self.assertEqual( stubResolver.calls, [((s,), {}) for s in ROOT_SERVERS])
def test_returnsDeferredResolver(self): """ L{root.bootstrap} returns an object which is initially a L{root.DeferredResolver}. """ deferredResolver = root.bootstrap(StubResolver()) self.assertIsInstance(deferredResolver, root.DeferredResolver)
def test_resolverReceivesRootHints(self): """ The L{root.Resolver} which eventually replaces L{root.DeferredResolver} is supplied with the IP addresses of the 13 root servers. """ stubResolver = StubResolver() deferredResolver = root.bootstrap(stubResolver) for d in stubResolver.pendingResults: d.callback("192.0.2.101") self.assertEqual(deferredResolver.hints, ["192.0.2.101"] * 13)
def test_resolverReceivesRootHints(self): """ The L{root.Resolver} which eventually replaces L{root.DeferredResolver} is supplied with the IP addresses of the 13 root servers. """ stubResolver = StubResolver() deferredResolver = root.bootstrap(stubResolver) for d in stubResolver.pendingResults: d.callback('192.0.2.101') self.assertEqual(deferredResolver.hints, ['192.0.2.101'] * 13)
def test_becomesResolver(self): """ The L{root.DeferredResolver} initially returned by L{root.bootstrap} becomes a L{root.Resolver} when the supplied resolver has successfully looked up all root hints. """ stubResolver = StubResolver() deferredResolver = root.bootstrap(stubResolver) for d in stubResolver.pendingResults: d.callback('192.0.2.101') self.assertIsInstance(deferredResolver, Resolver)
def test_becomesResolver(self): """ The L{root.DeferredResolver} initially returned by L{root.bootstrap} becomes a L{root.Resolver} when the supplied resolver has successfully looked up all root hints. """ stubResolver = StubResolver() deferredResolver = root.bootstrap(stubResolver) for d in stubResolver.pendingResults: d.callback("192.0.2.101") self.assertIsInstance(deferredResolver, Resolver)
def test_passesResolverFactory(self): """ L{root.bootstrap} accepts a C{resolverFactory} argument which is passed as an argument to L{root.Resolver} when it has successfully looked up root hints. """ stubResolver = StubResolver() deferredResolver = root.bootstrap( stubResolver, resolverFactory=raisingResolverFactory) for d in stubResolver.pendingResults: d.callback("192.0.2.101") self.assertIs(deferredResolver._resolverFactory, raisingResolverFactory)
def test_passesResolverFactory(self): """ L{root.bootstrap} accepts a C{resolverFactory} argument which is passed as an argument to L{root.Resolver} when it has successfully looked up root hints. """ stubResolver = StubResolver() deferredResolver = root.bootstrap( stubResolver, resolverFactory=raisingResolverFactory) for d in stubResolver.pendingResults: d.callback('192.0.2.101') self.assertIs( deferredResolver._resolverFactory, raisingResolverFactory)
def test_continuesWhenSomeRootHintsFail(self): """ The L{root.Resolver} is eventually created, even if some of the root hint lookups fail. Only the working root hint IP addresses are supplied to the L{root.Resolver}. """ stubResolver = StubResolver() deferredResolver = root.bootstrap(stubResolver) results = iter(stubResolver.pendingResults) d1 = next(results) for d in results: d.callback('192.0.2.101') d1.errback(TimeoutError()) def checkHints(res): self.assertEqual(deferredResolver.hints, ['192.0.2.101'] * 12) d1.addBoth(checkHints)
def create_resolver(servers=None, resolvconf=None, hosts=None): if platform.getType() == 'posix': if resolvconf is None: resolvconf = b'/etc/resolv.conf' if hosts is None: hosts = b'/etc/hosts' the_resolver = client.Resolver(resolvconf, servers) host_resolver = Resolver(hosts) else: if hosts is None: hosts = r'c:\windows\hosts' from twisted.internet import reactor bootstrap = client._ThreadedResolverImpl(reactor) host_resolver = Resolver(hosts) the_resolver = root.bootstrap(bootstrap, resolverFactory=client.Resolver) return resolve.ResolverChain([host_resolver, cache.CacheResolver(), the_resolver])
def test_continuesWhenAllRootHintsFail(self): """ The L{root.Resolver} is eventually created, even if all of the root hint lookups fail. Pending and new lookups will then fail with AttributeError. """ stubResolver = StubResolver() deferredResolver = root.bootstrap(stubResolver) results = iter(stubResolver.pendingResults) d1 = next(results) for d in results: d.errback(TimeoutError()) d1.errback(TimeoutError()) def checkHints(res): self.assertEqual(deferredResolver.hints, []) d1.addBoth(checkHints) self.addCleanup(self.flushLoggedErrors, TimeoutError)
def createResolver(servers=None, resolvconf=None, hosts=None): from twisted.names import resolve, cache, root, hosts as hostsModule if platform.getType() == 'posix': if resolvconf is None: resolvconf = '/etc/resolv.conf' if hosts is None: hosts = '/etc/hosts' theResolver = HardcoreResolver(resolvconf, servers) hostResolver = hostsModule.Resolver(hosts) else: if hosts is None: hosts = r'c:\windows\hosts' from twisted.internet import reactor bootstrap = _ThreadedResolverImpl(reactor) hostResolver = hostsModule.Resolver(hosts) theResolver = root.bootstrap(bootstrap) L = [hostResolver, cache.CacheResolver(), theResolver] return resolve.ResolverChain(L)
def createResolver(servers=None, resolvconf=None, hosts=None): r""" Create and return a Resolver. @type servers: C{list} of C{(str, int)} or L{None} @param servers: If not L{None}, interpreted as a list of domain name servers to attempt to use. Each server is a tuple of address in C{str} dotted-quad form and C{int} port number. @type resolvconf: C{str} or L{None} @param resolvconf: If not L{None}, on posix systems will be interpreted as an alternate resolv.conf to use. Will do nothing on windows systems. If L{None}, /etc/resolv.conf will be used. @type hosts: C{str} or L{None} @param hosts: If not L{None}, an alternate hosts file to use. If L{None} on posix systems, /etc/hosts will be used. On windows, C:\windows\hosts will be used. @rtype: C{IResolver} """ if platform.getType() == "posix": if resolvconf is None: resolvconf = b"/etc/resolv.conf" if hosts is None: hosts = b"/etc/hosts" theResolver = Resolver(resolvconf, servers) hostResolver = hostsModule.Resolver(hosts) else: if hosts is None: hosts = r"c:\windows\hosts" from twisted.internet import reactor bootstrap = _ThreadedResolverImpl(reactor) hostResolver = hostsModule.Resolver(hosts) theResolver = root.bootstrap(bootstrap, resolverFactory=Resolver) L = [hostResolver, cache.CacheResolver(), theResolver] return resolve.ResolverChain(L)
def createResolver(servers=None, resolvconf=None, hosts=None): """ Create and return a Resolver. @type servers: C{list} of C{(str, int)} or C{None} @param servers: If not C{None}, interpreted as a list of domain name servers to attempt to use. Each server is a tuple of address in C{str} dotted-quad form and C{int} port number. @type resolvconf: C{str} or C{None} @param resolvconf: If not C{None}, on posix systems will be interpreted as an alternate resolv.conf to use. Will do nothing on windows systems. If C{None}, /etc/resolv.conf will be used. @type hosts: C{str} or C{None} @param hosts: If not C{None}, an alternate hosts file to use. If C{None} on posix systems, /etc/hosts will be used. On windows, C:\windows\hosts will be used. @rtype: C{IResolver} """ from twisted.names import resolve, cache, root, hosts as hostsModule if platform.getType() == 'posix': if resolvconf is None: resolvconf = b'/etc/resolv.conf' if hosts is None: hosts = b'/etc/hosts' theResolver = Resolver(resolvconf, servers) hostResolver = hostsModule.Resolver(hosts) else: if hosts is None: hosts = r'c:\windows\hosts' from twisted.internet import reactor bootstrap = _ThreadedResolverImpl(reactor) hostResolver = hostsModule.Resolver(hosts) theResolver = root.bootstrap(bootstrap) L = [hostResolver, cache.CacheResolver(), theResolver] return resolve.ResolverChain(L)
def createResolver(servers=None, resolvconf=None, hosts=None): """ Create and return a Resolver. @type servers: C{list} of C{(str, int)} or C{None} @param servers: If not C{None}, interpreted as a list of addresses of domain name servers to attempt to use. Addresses should be in dotted-quad form. @type resolvconf: C{str} or C{None} @param resolvconf: If not C{None}, on posix systems will be interpreted as an alternate resolv.conf to use. Will do nothing on windows systems. If C{None}, /etc/resolv.conf will be used. @type hosts: C{str} or C{None} @param hosts: If not C{None}, an alternate hosts file to use. If C{None} on posix systems, /etc/hosts will be used. On windows, C:\windows\hosts will be used. @rtype: C{IResolver} """ from twisted.names import resolve, cache, root, hosts as hostsModule if platform.getType() == 'posix': if resolvconf is None: resolvconf = '/etc/resolv.conf' if hosts is None: hosts = '/etc/hosts' theResolver = Resolver(resolvconf, servers) hostResolver = hostsModule.Resolver(hosts) else: if hosts is None: hosts = r'c:\windows\hosts' from twisted.internet import reactor bootstrap = _ThreadedResolverImpl(reactor) hostResolver = hostsModule.Resolver(hosts) theResolver = root.bootstrap(bootstrap) L = [hostResolver, cache.CacheResolver(), theResolver] return resolve.ResolverChain(L)