예제 #1
0
 def test_failure(self):
     """
     L{SimpleResolverComplexifier} translates a known error result from
     L{IResolverSimple.resolveHostName} into an empty result.
     """
     simple = SillyResolverSimple()
     complex = SimpleResolverComplexifier(simple)
     receiver = ResultHolder(self)
     self.assertEqual(receiver._started, False)
     complex.resolveHostName(receiver, u"example.com")
     self.assertEqual(receiver._started, True)
     self.assertEqual(receiver._ended, False)
     self.assertEqual(receiver._addresses, [])
     simple._requests[0].errback(DNSLookupError("nope"))
     self.assertEqual(receiver._ended, True)
     self.assertEqual(receiver._addresses, [])
예제 #2
0
 def test_portNumber(self):
     """
     L{SimpleResolverComplexifier} preserves the C{port} argument passed to
     C{resolveHostName} in its returned addresses.
     """
     simple = SillyResolverSimple()
     complex = SimpleResolverComplexifier(simple)
     receiver = ResultHolder(self)
     complex.resolveHostName(receiver, u"example.com", 4321)
     self.assertEqual(receiver._started, True)
     self.assertEqual(receiver._ended, False)
     self.assertEqual(receiver._addresses, [])
     simple._requests[0].callback("192.168.1.1")
     self.assertEqual(receiver._addresses,
                      [IPv4Address('TCP', '192.168.1.1', 4321)])
     self.assertEqual(receiver._ended, True)
예제 #3
0
 def test_portNumber(self):
     """
     L{SimpleResolverComplexifier} preserves the C{port} argument passed to
     C{resolveHostName} in its returned addresses.
     """
     simple = SillyResolverSimple()
     complex = SimpleResolverComplexifier(simple)
     receiver = ResultHolder(self)
     complex.resolveHostName(receiver, u"example.com", 4321)
     self.assertEqual(receiver._started, True)
     self.assertEqual(receiver._ended, False)
     self.assertEqual(receiver._addresses, [])
     simple._requests[0].callback("192.168.1.1")
     self.assertEqual(receiver._addresses,
                      [IPv4Address('TCP', '192.168.1.1', 4321)])
     self.assertEqual(receiver._ended, True)
예제 #4
0
 def test_failure(self):
     """
     L{SimpleResolverComplexifier} translates a known error result from
     L{IResolverSimple.resolveHostName} into an empty result.
     """
     simple = SillyResolverSimple()
     complex = SimpleResolverComplexifier(simple)
     receiver = ResultHolder(self)
     self.assertEqual(receiver._started, False)
     complex.resolveHostName(receiver, u"example.com")
     self.assertEqual(receiver._started, True)
     self.assertEqual(receiver._ended, False)
     self.assertEqual(receiver._addresses, [])
     simple._requests[0].errback(DNSLookupError("nope"))
     self.assertEqual(receiver._ended, True)
     self.assertEqual(receiver._addresses, [])
예제 #5
0
 def test_success(self):
     """
     L{SimpleResolverComplexifier} translates C{resolveHostName} into
     L{IResolutionReceiver.addressResolved}.
     """
     simple = SillyResolverSimple()
     complex = SimpleResolverComplexifier(simple)
     receiver = ResultHolder(self)
     self.assertEqual(receiver._started, False)
     complex.resolveHostName(receiver, u"example.com")
     self.assertEqual(receiver._started, True)
     self.assertEqual(receiver._ended, False)
     self.assertEqual(receiver._addresses, [])
     simple._requests[0].callback("192.168.1.1")
     self.assertEqual(receiver._addresses,
                      [IPv4Address('TCP', '192.168.1.1', 0)])
     self.assertEqual(receiver._ended, True)
예제 #6
0
 def test_success(self):
     """
     L{SimpleResolverComplexifier} translates C{resolveHostName} into
     L{IResolutionReceiver.addressResolved}.
     """
     simple = SillyResolverSimple()
     complex = SimpleResolverComplexifier(simple)
     receiver = ResultHolder(self)
     self.assertEqual(receiver._started, False)
     complex.resolveHostName(receiver, u"example.com")
     self.assertEqual(receiver._started, True)
     self.assertEqual(receiver._ended, False)
     self.assertEqual(receiver._addresses, [])
     simple._requests[0].callback("192.168.1.1")
     self.assertEqual(receiver._addresses,
                      [IPv4Address('TCP', '192.168.1.1', 0)])
     self.assertEqual(receiver._ended, True)
예제 #7
0
 def test_error(self):
     """
     L{SimpleResolverComplexifier} translates an unknown error result from
     L{IResolverSimple.resolveHostName} into an empty result and a logged
     error.
     """
     simple = SillyResolverSimple()
     complex = SimpleResolverComplexifier(simple)
     receiver = ResultHolder(self)
     self.assertEqual(receiver._started, False)
     complex.resolveHostName(receiver, u"example.com")
     self.assertEqual(receiver._started, True)
     self.assertEqual(receiver._ended, False)
     self.assertEqual(receiver._addresses, [])
     simple._requests[0].errback(ZeroDivisionError("zow"))
     self.assertEqual(len(self.flushLoggedErrors(ZeroDivisionError)), 1)
     self.assertEqual(receiver._ended, True)
     self.assertEqual(receiver._addresses, [])
예제 #8
0
 def test_error(self):
     """
     L{SimpleResolverComplexifier} translates an unknown error result from
     L{IResolverSimple.resolveHostName} into an empty result and a logged
     error.
     """
     simple = SillyResolverSimple()
     complex = SimpleResolverComplexifier(simple)
     receiver = ResultHolder(self)
     self.assertEqual(receiver._started, False)
     complex.resolveHostName(receiver, u"example.com")
     self.assertEqual(receiver._started, True)
     self.assertEqual(receiver._ended, False)
     self.assertEqual(receiver._addresses, [])
     simple._requests[0].errback(ZeroDivisionError("zow"))
     self.assertEqual(len(self.flushLoggedErrors(ZeroDivisionError)), 1)
     self.assertEqual(receiver._ended, True)
     self.assertEqual(receiver._addresses, [])
예제 #9
0
    def __init__(self):
        lookups = self.lookups = {}  # type: Dict[str, str]

        @implementer(IResolverSimple)
        class FakeResolver:
            def getHostByName(self, name, timeout=None):
                if name not in lookups:
                    return fail(DNSLookupError("OH NO: unknown %s" % (name,)))
                return succeed(lookups[name])

        self.nameResolver = SimpleResolverComplexifier(FakeResolver())
        super().__init__()
예제 #10
0
    def __init__(self):
        self._udp = []
        lookups = self.lookups = {}

        @implementer(IResolverSimple)
        class FakeResolver(object):
            def getHostByName(self, name, timeout=None):
                if name not in lookups:
                    return fail(DNSLookupError("OH NO: unknown %s" % (name, )))
                return succeed(lookups[name])

        self.nameResolver = SimpleResolverComplexifier(FakeResolver())
        super(ThreadedMemoryReactorClock, self).__init__()
예제 #11
0
    def __init__(self):
        super().__init__()
        self.work_notifier = Condition()

        self.lookups: Dict[str, str] = {}

        @implementer(IResolverSimple)
        class FakeResolver(object):
            @staticmethod
            def getHostByName(name, timeout=None):
                if name not in self.lookups:
                    return fail(DNSLookupError("OH NO: unknown %s" % (name, )))
                return succeed(self.lookups[name])

        self.nameResolver = SimpleResolverComplexifier(FakeResolver())
예제 #12
0
    def __init__(self):
        self.threadpool = ThreadPool(self)

        self._tcp_callbacks = {}
        self._udp = []
        lookups = self.lookups = {}

        @implementer(IResolverSimple)
        class FakeResolver:
            def getHostByName(self, name, timeout=None):
                if name not in lookups:
                    return fail(DNSLookupError("OH NO: unknown %s" % (name, )))
                return succeed(lookups[name])

        self.nameResolver = SimpleResolverComplexifier(FakeResolver())
        super().__init__()
예제 #13
0
    def __init__(self):
        self.threadpool = ThreadPool(self)

        self._tcp_callbacks: Dict[Tuple[str, int], Callable] = {}
        self._udp = []
        self.lookups: Dict[str, str] = {}
        self._thread_callbacks: Deque[Callable[[], None]] = deque()

        lookups = self.lookups

        @implementer(IResolverSimple)
        class FakeResolver:
            def getHostByName(self, name, timeout=None):
                if name not in lookups:
                    return fail(DNSLookupError("OH NO: unknown %s" % (name, )))
                return succeed(lookups[name])

        self.nameResolver = SimpleResolverComplexifier(FakeResolver())
        super().__init__()