當前位置: 首頁>>代碼示例>>Python>>正文


Python base.ThreadedResolver類代碼示例

本文整理匯總了Python中twisted.internet.base.ThreadedResolver的典型用法代碼示例。如果您正苦於以下問題:Python ThreadedResolver類的具體用法?Python ThreadedResolver怎麽用?Python ThreadedResolver使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了ThreadedResolver類的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_failure

    def test_failure(self):
        """
        L{ThreadedResolver.getHostByName} returns a L{Deferred} which fires a
        L{Failure} if the call to L{socket.gethostbyname} raises an exception.
        """
        timeout = 30

        reactor = FakeReactor()
        self.addCleanup(reactor._stop)

        def fakeGetHostByName(name):
            raise IOError("ENOBUFS (this is a funny joke)")

        self.patch(socket, 'gethostbyname', fakeGetHostByName)

        failedWith = []
        resolver = ThreadedResolver(reactor)
        d = resolver.getHostByName("some.name", (timeout,))
        self.assertFailure(d, DNSLookupError)
        d.addCallback(failedWith.append)

        reactor._runThreadCalls()

        self.assertEqual(len(failedWith), 1)

        # Make sure that any timeout-related stuff gets cleaned up.
        reactor._clock.advance(timeout + 1)
        self.assertEqual(reactor._clock.calls, [])
開發者ID:Almad,項目名稱:twisted,代碼行數:28,代碼來源:test_base.py

示例2: test_timeout

    def test_timeout(self):
        """
        If L{socket.gethostbyname} does not complete before the specified
        timeout elapsed, the L{Deferred} returned by
        L{ThreadedResolver.getHostByBame} fails with L{DNSLookupError}.
        """
        timeout = 10

        reactor = FakeReactor()
        self.addCleanup(reactor._stop)

        result = Queue()
        def fakeGetHostByName(name):
            raise result.get()

        self.patch(socket, 'gethostbyname', fakeGetHostByName)

        failedWith = []
        resolver = ThreadedResolver(reactor)
        d = resolver.getHostByName("some.name", (timeout,))
        self.assertFailure(d, DNSLookupError)
        d.addCallback(failedWith.append)

        reactor._clock.advance(timeout - 1)
        self.assertEqual(failedWith, [])
        reactor._clock.advance(1)
        self.assertEqual(len(failedWith), 1)

        # Eventually the socket.gethostbyname does finish - in this case, with
        # an exception.  Nobody cares, though.
        result.put(IOError("The I/O was errorful"))
開發者ID:Almad,項目名稱:twisted,代碼行數:31,代碼來源:test_base.py

示例3: test_success

    def test_success(self):
        """
        L{ThreadedResolver.getHostByName} returns a L{Deferred} which fires
        with the value returned by the call to L{socket.gethostbyname} in the
        threadpool of the reactor passed to L{ThreadedResolver.__init__}.
        """
        ip = "10.0.0.17"
        name = "foo.bar.example.com"
        timeout = 30

        reactor = FakeReactor()
        self.addCleanup(reactor._stop)

        lookedUp = []
        resolvedTo = []
        def fakeGetHostByName(name):
            lookedUp.append(name)
            return ip

        self.patch(socket, 'gethostbyname', fakeGetHostByName)

        resolver = ThreadedResolver(reactor)
        d = resolver.getHostByName(name, (timeout,))
        d.addCallback(resolvedTo.append)

        reactor._runThreadCalls()

        self.assertEqual(lookedUp, [name])
        self.assertEqual(resolvedTo, [ip])

        # Make sure that any timeout-related stuff gets cleaned up.
        reactor._clock.advance(timeout + 1)
        self.assertEqual(reactor._clock.calls, [])
開發者ID:Almad,項目名稱:twisted,代碼行數:33,代碼來源:test_base.py

示例4: test_success

    def test_success(self):
        """
        L{ThreadedResolver.getHostByName} returns a L{Deferred} which fires
        with the value returned by the call to L{socket.getaddrinfo} in the
        threadpool of the reactor passed to L{ThreadedResolver.__init__}.
        """
        ip = "213.180.204.3"
        name = "ya.ru"
        timeout = 30

        reactor = FakeReactor()
        self.addCleanup(reactor._stop)

        lookedUp = []
        resolvedTo = []
        def fakeGetHostByName(name, service):
            lookedUp.append(name)
            return (2, 1, 6, '', ('213.180.204.3', 0)), (2, 2, 17, '', ('213.180.204.3', 0)), (2, 3, 0, '', ('213.180.204.3', 0))

        self.patch(socket, 'getaddrinfo', fakeGetHostByName)

        resolver = ThreadedResolver(reactor)
        d = resolver.getHostByName(name, (timeout,))
        d.addCallback(resolvedTo.append)

        reactor._runThreadCalls()

        self.assertEqual(lookedUp, [name])
        self.assertEqual(resolvedTo, [ip])

        # Make sure that any timeout-related stuff gets cleaned up.
        reactor._clock.advance(timeout + 1)
        self.assertEqual(reactor._clock.calls, [])
開發者ID:smira,項目名稱:twisted,代碼行數:33,代碼來源:test_base.py

示例5: __init__

 def __init__(self, reactor=None):
     if reactor is None:
         from twisted.internet import reactor
     _ThreadedResolverImpl.__init__(self, reactor)
     warnings.warn(
         "twisted.names.client.ThreadedResolver is deprecated since "
         "Twisted 9.0, use twisted.internet.base.ThreadedResolver "
         "instead.",
         category=DeprecationWarning, stacklevel=2)
開發者ID:JohnDoes95,項目名稱:project_parser,代碼行數:9,代碼來源:client.py

示例6: test_real

    def test_real(self):
        name = "ya.ru"
        timeout = 30

        reactor = FakeReactor()
        self.addCleanup(reactor._stop)

        resolvedTo = []
        resolver = ThreadedResolver(reactor)
        d = resolver.getHostByName(name, (timeout,))
        d.addCallback(resolvedTo.append)

        reactor._runThreadCalls()

        self.assertTrue(resolvedTo[0].startswith('77.') or
                        resolvedTo[0].startswith('87.') or
                        resolvedTo[0].startswith('93.') or
                        resolvedTo[0].startswith('213.'))

        # Make sure that any timeout-related stuff gets cleaned up.
        reactor._clock.advance(timeout + 1)
        self.assertEqual(reactor._clock.calls, [])
開發者ID:smira,項目名稱:twisted,代碼行數:22,代碼來源:test_base.py

示例7: getHostByName

 def getHostByName(self, name, timeout=(1, 3, 11, 45)):
     if name in dnscache:
         return defer.succeed(dnscache[name])
     d = ThreadedResolver.getHostByName(self, name, timeout)
     d.addCallback(self._cache_result, name)
     return d
開發者ID:dreamfrog,項目名稱:jophiel,代碼行數:6,代碼來源:resolver.py

示例8: __init__

 def __init__(self, *args, **kwargs):
     ThreadedResolver.__init__(self, *args, **kwargs)
     self._cache = {}
開發者ID:kenzouyeh,項目名稱:scrapy,代碼行數:3,代碼來源:resolver.py

示例9: __init__

 def __init__(self, reactor=None):
     if reactor is None:
         from twisted.internet import reactor
     _ThreadedResolverImpl.__init__(self, reactor)
開發者ID:galaxysd,項目名稱:BitTorrent,代碼行數:4,代碼來源:client.py


注:本文中的twisted.internet.base.ThreadedResolver類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。