<s> from __future__ import absolute_import , division , print_function , with_statement <EOL> import socket <EOL> from tornado . netutil import BlockingResolver , ThreadedResolver , is_valid_ip <EOL> from tornado . testing import AsyncTestCase , gen_test <EOL> from tornado . test . util import unittest <EOL> try : <EOL> from concurrent import futures <EOL> except ImportError : <EOL> futures = None <EOL> try : <EOL> import pycares <EOL> except ImportError : <EOL> pycares = None <EOL> else : <EOL> from tornado . platform . caresresolver import CaresResolver <EOL> try : <EOL> import twisted <EOL> except ImportError : <EOL> twisted = None <EOL> else : <EOL> from tornado . platform . twisted import TwistedResolver <EOL> class _ResolverTestMixin ( object ) : <EOL> def test_localhost ( self ) : <EOL> self . resolver . resolve ( '<STR_LIT:localhost>' , <NUM_LIT> , callback = self . stop ) <EOL> result = self . wait ( ) <EOL> self . assertIn ( ( socket . AF_INET , ( '<STR_LIT:127.0.0.1>' , <NUM_LIT> ) ) , result ) <EOL> @ gen_test <EOL> def test_future_interface ( self ) : <EOL> addrinfo = yield self . resolver . resolve ( '<STR_LIT:localhost>' , <NUM_LIT> , <EOL> socket . AF_UNSPEC ) <EOL> self . assertIn ( ( socket . AF_INET , ( '<STR_LIT:127.0.0.1>' , <NUM_LIT> ) ) , <EOL> addrinfo ) <EOL> class BlockingResolverTest ( AsyncTestCase , _ResolverTestMixin ) : <EOL> def setUp ( self ) : <EOL> super ( BlockingResolverTest , self ) . setUp ( ) <EOL> self . resolver = BlockingResolver ( io_loop = self . io_loop ) <EOL> @ unittest . skipIf ( futures is None , "<STR_LIT>" ) <EOL> class ThreadedResolverTest ( AsyncTestCase , _ResolverTestMixin ) : <EOL> def setUp ( self ) : <EOL> super ( ThreadedResolverTest , self ) . setUp ( ) <EOL> self . resolver = ThreadedResolver ( io_loop = self . io_loop ) <EOL> def tearDown ( self ) : <EOL> self . resolver . close ( ) <EOL> super ( ThreadedResolverTest , self ) . tearDown ( ) <EOL> @ unittest . skipIf ( pycares is None , "<STR_LIT>" ) <EOL> class CaresResolverTest ( AsyncTestCase , _ResolverTestMixin ) : <EOL> def setUp ( self ) : <EOL> super ( CaresResolverTest , self ) . setUp ( ) <EOL> self . resolver = CaresResolver ( io_loop = self . io_loop ) <EOL> @ unittest . skipIf ( twisted is None , "<STR_LIT>" ) <EOL> @ unittest . skipIf ( getattr ( twisted , '<STR_LIT>' , '<STR_LIT>' ) < "<STR_LIT>" , "<STR_LIT>" ) <EOL> class TwistedResolverTest ( AsyncTestCase , _ResolverTestMixin ) : <EOL> def setUp ( self ) : <EOL> super ( TwistedResolverTest , self ) . setUp ( ) <EOL> self . resolver = TwistedResolver ( io_loop = self . io_loop ) <EOL> class IsValidIPTest ( unittest . TestCase ) : <EOL> def test_is_valid_ip ( self ) : <EOL> self . assertTrue ( is_valid_ip ( '<STR_LIT:127.0.0.1>' ) ) <EOL> self . assertTrue ( is_valid_ip ( '<STR_LIT>' ) ) <EOL> self . assertTrue ( is_valid_ip ( '<STR_LIT>' ) ) <EOL> self . assertTrue ( is_valid_ip ( '<STR_LIT>' ) ) <EOL> self . assertTrue ( not is_valid_ip ( '<STR_LIT>' ) ) <EOL> self . assertTrue ( not is_valid_ip ( '<STR_LIT:localhost>' ) ) <EOL> self . assertTrue ( not is_valid_ip ( '<STR_LIT>' ) ) <EOL> self . assertTrue ( not is_valid_ip ( '<STR_LIT>' ) ) </s>
