当前位置: 首页>>代码示例>>Python>>正文


Python error.CannotListenError方法代码示例

本文整理汇总了Python中twisted.internet.error.CannotListenError方法的典型用法代码示例。如果您正苦于以下问题:Python error.CannotListenError方法的具体用法?Python error.CannotListenError怎么用?Python error.CannotListenError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在twisted.internet.error的用法示例。


在下文中一共展示了error.CannotListenError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _bindSocket

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import CannotListenError [as 别名]
def _bindSocket(self):
        try:
            skt = self.createSocket()
            skt.bind((self.interface, self.port))
        except socket.error as le:
            raise error.CannotListenError(self.interface, self.port, le)

        # Make sure that if we listened on port 0, we update that to
        # reflect what the OS actually assigned us.
        self._realPortNumber = skt.getsockname()[1]

        log.msg("%s starting on %s" % (
                self._getLogPrefix(self.protocol), self._realPortNumber))

        self.connected = True
        self.socket = skt
        self.getFileHandle = self.socket.fileno 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:19,代码来源:udp.py

示例2: test_endpointListenFailure

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import CannotListenError [as 别名]
def test_endpointListenFailure(self):
        """
        When an endpoint tries to listen on an already listening port, a
        C{CannotListenError} failure is errbacked.
        """
        factory = object()
        exception = error.CannotListenError('', 80, factory)
        mreactor = RaisingMemoryReactor(listenException=exception)

        ep, ignoredArgs, ignoredDest = self.createServerEndpoint(
            mreactor, factory)

        d = ep.listen(object())

        receivedExceptions = []

        def checkFailure(f):
            receivedExceptions.append(f.value)

        d.addErrback(checkFailure)

        self.assertEqual(receivedExceptions, [exception]) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:24,代码来源:test_endpoints.py

示例3: test_disallowedPort

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import CannotListenError [as 别名]
def test_disallowedPort(self):
        """
        If a port number is initially selected which cannot be bound, the
        L{CannotListenError} is handled and another port number is attempted.
        """
        ports = []

        class FakeReactor(object):
            def listenUDP(self, port, *args, **kwargs):
                ports.append(port)
                if len(ports) == 1:
                    raise CannotListenError(None, port, None)

        resolver = client.Resolver(servers=[('example.com', 53)])
        resolver._reactor = FakeReactor()

        resolver._connectedProtocol()
        self.assertEqual(len(set(ports)), 2) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:20,代码来源:test_client.py

示例4: test_cannotBind

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import CannotListenError [as 别名]
def test_cannotBind(self):
        """
        L{IReactorTCP.listenTCP} raises L{error.CannotListenError} if the
        address to listen on is already in use.
        """
        f = MyServerFactory()

        p1 = reactor.listenTCP(0, f, interface='127.0.0.1')
        self.addCleanup(p1.stopListening)
        n = p1.getHost().port
        dest = p1.getHost()
        self.assertEqual(dest.type, "TCP")
        self.assertEqual(dest.host, "127.0.0.1")
        self.assertEqual(dest.port, n)

        # make sure new listen raises error
        self.assertRaises(error.CannotListenError,
                          reactor.listenTCP, n, f, interface='127.0.0.1') 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:20,代码来源:test_tcp.py

示例5: test_bindError

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import CannotListenError [as 别名]
def test_bindError(self):
        """
        A L{CannotListenError} exception is raised when attempting to bind a
        second protocol instance to an already bound port
        """
        server = Server()
        d = server.startedDeferred = defer.Deferred()
        port = reactor.listenUDP(0, server, interface='127.0.0.1')

        def cbStarted(ignored):
            self.assertEqual(port.getHost(), server.transport.getHost())
            server2 = Server()
            self.assertRaises(
                error.CannotListenError,
                reactor.listenUDP, port.getHost().port, server2,
                interface='127.0.0.1')
        d.addCallback(cbStarted)

        def cbFinished(ignored):
            return port.stopListening()
        d.addCallback(cbFinished)
        return d 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:24,代码来源:test_udp.py

示例6: test_socketLocking

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import CannotListenError [as 别名]
def test_socketLocking(self):
        """
        L{IReactorUNIX.listenUNIX} raises L{error.CannotListenError} if passed
        the name of a file on which a server is already listening.
        """
        filename = self.mktemp()
        serverFactory = MyServerFactory()
        unixPort = reactor.listenUNIX(filename, serverFactory, wantPID=True)

        self.assertRaises(
            error.CannotListenError,
            reactor.listenUNIX, filename, serverFactory, wantPID=True)

        def stoppedListening(ign):
            unixPort = reactor.listenUNIX(filename, serverFactory, wantPID=True)
            return unixPort.stopListening()

        return unixPort.stopListening().addCallback(stoppedListening) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:20,代码来源:test_unix.py

示例7: test_portRange

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import CannotListenError [as 别名]
def test_portRange(self):
        """
        L{FTP.passivePortRange} should determine the ports which
        L{FTP.getDTPPort} attempts to bind. If no port from that iterator can
        be bound, L{error.CannotListenError} should be raised, otherwise the
        first successful result from L{FTP.listenFactory} should be returned.
        """
        def listenFactory(portNumber, factory):
            if portNumber in (22032, 22033, 22034):
                raise error.CannotListenError('localhost', portNumber, 'error')
            return portNumber
        self.serverProtocol.listenFactory = listenFactory

        port = self.serverProtocol.getDTPPort(protocol.Factory())
        self.assertEqual(port, 0)

        self.serverProtocol.passivePortRange = xrange(22032, 65536)
        port = self.serverProtocol.getDTPPort(protocol.Factory())
        self.assertEqual(port, 22035)

        self.serverProtocol.passivePortRange = xrange(22032, 22035)
        self.assertRaises(error.CannotListenError,
                          self.serverProtocol.getDTPPort,
                          protocol.Factory()) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:26,代码来源:test_ftp.py

示例8: _bindSocket

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import CannotListenError [as 别名]
def _bindSocket(self):
        """
        Open the tunnel.
        """
        log.msg(
            format="%(protocol)s starting on %(interface)s",
            protocol=self.protocol.__class__,
            interface=self.interface)
        try:
            fileno, interface = self._openTunnel(
                self.interface, self._mode | TunnelFlags.IFF_NO_PI)
        except (IOError, OSError) as e:
            raise error.CannotListenError(None, self.interface, e)

        self.interface = interface
        self._fileno = fileno

        self.connected = 1 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:20,代码来源:tuntap.py

示例9: test_disallowedPortRepeatedly

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import CannotListenError [as 别名]
def test_disallowedPortRepeatedly(self):
        """
        If port numbers that cannot be bound are repeatedly selected,
        L{resolver._connectedProtocol} will give up eventually.
        """
        ports = []

        class FakeReactor(object):
            def listenUDP(self, port, *args, **kwargs):
                ports.append(port)
                raise CannotListenError(None, port, None)

        resolver = client.Resolver(servers=[('example.com', 53)])
        resolver._reactor = FakeReactor()

        self.assertRaises(CannotListenError, resolver._connectedProtocol)
        # 1000 is a good round number. I like it.
        self.assertEqual(len(ports), 1000) 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:20,代码来源:test_client.py

示例10: test_runOutOfFiles

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import CannotListenError [as 别名]
def test_runOutOfFiles(self):
        """
        If the process is out of files, L{Resolver._connectedProtocol}
        will give up.
        """
        ports = []

        class FakeReactor(object):
            def listenUDP(self, port, *args, **kwargs):
                ports.append(port)
                err = OSError(errno.EMFILE, "Out of files :(")
                raise CannotListenError(None, port, err)

        resolver = client.Resolver(servers=[('example.com', 53)])
        resolver._reactor = FakeReactor()

        exc = self.assertRaises(CannotListenError, resolver._connectedProtocol)
        # The EMFILE-containing exception was raised, and it did not try
        # multiple times.
        self.assertEqual(exc.socketError.errno, errno.EMFILE)
        self.assertEqual(len(ports), 1) 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:23,代码来源:test_client.py

示例11: test_portRange

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import CannotListenError [as 别名]
def test_portRange(self):
        """
        L{FTP.passivePortRange} should determine the ports which
        L{FTP.getDTPPort} attempts to bind. If no port from that iterator can
        be bound, L{error.CannotListenError} should be raised, otherwise the
        first successful result from L{FTP.listenFactory} should be returned.
        """
        def listenFactory(portNumber, factory):
            if portNumber in (22032, 22033, 22034):
                raise error.CannotListenError('localhost', portNumber, 'error')
            return portNumber
        self.serverProtocol.listenFactory = listenFactory

        port = self.serverProtocol.getDTPPort(protocol.Factory())
        self.assertEqual(port, 0)

        self.serverProtocol.passivePortRange = range(22032, 65536)
        port = self.serverProtocol.getDTPPort(protocol.Factory())
        self.assertEqual(port, 22035)

        self.serverProtocol.passivePortRange = range(22032, 22035)
        self.assertRaises(error.CannotListenError,
                          self.serverProtocol.getDTPPort,
                          protocol.Factory()) 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:26,代码来源:test_ftp.py

示例12: test_endpointListenFailure

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import CannotListenError [as 别名]
def test_endpointListenFailure(self):
        """
        When an endpoint tries to listen on an already listening port, a
        C{CannotListenError} failure is errbacked.
        """
        factory = object()
        exception = error.CannotListenError('', 80, factory)
        mreactor = RaisingMemoryReactor(listenException=exception)

        ep, ignoredArgs, ignoredDest = self.createServerEndpoint(
            mreactor, factory)

        d = ep.listen(object())

        receivedExceptions = []

        def checkFailure(f):
            receivedExceptions.append(f.value)

        d.addErrback(checkFailure)

        self.assertEquals(receivedExceptions, [exception]) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:24,代码来源:test_endpoints.py

示例13: _connectedProtocol

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import CannotListenError [as 别名]
def _connectedProtocol(self):
        """
        Return a new L{DNSDatagramProtocol} bound to a randomly selected port
        number.
        """
        if 'protocol' in self.__dict__:
            # Some code previously asked for or set the deprecated `protocol`
            # attribute, so it probably expects that object to be used for
            # queries.  Give it back and skip the super awesome source port
            # randomization logic.  This is actually a really good reason to
            # remove this deprecated backward compatibility as soon as
            # possible. -exarkun
            return self.protocol
        proto = dns.DNSDatagramProtocol(self)
        while True:
            try:
                self._reactor.listenUDP(dns.randomSource(), proto)
            except error.CannotListenError:
                pass
            else:
                return proto 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:23,代码来源:client.py

示例14: test_disallowedPort

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import CannotListenError [as 别名]
def test_disallowedPort(self):
        """
        If a port number is initially selected which cannot be bound, the
        L{CannotListenError} is handled and another port number is attempted.
        """
        ports = []

        class FakeReactor(object):
            def listenUDP(self, port, *args):
                ports.append(port)
                if len(ports) == 1:
                    raise error.CannotListenError(None, port, None)

        resolver = client.Resolver(servers=[('example.com', 53)])
        resolver._reactor = FakeReactor()

        proto = resolver._connectedProtocol()
        self.assertEqual(len(set(ports)), 2) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:20,代码来源:test_client.py

示例15: test_cannotBind

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import CannotListenError [as 别名]
def test_cannotBind(self):
        """
        L{IReactorTCP.listenTCP} raises L{error.CannotListenError} if the
        address to listen on is already in use.
        """
        f = MyServerFactory()

        p1 = reactor.listenTCP(0, f, interface='127.0.0.1')
        self.addCleanup(p1.stopListening)
        n = p1.getHost().port
        dest = p1.getHost()
        self.assertEquals(dest.type, "TCP")
        self.assertEquals(dest.host, "127.0.0.1")
        self.assertEquals(dest.port, n)

        # make sure new listen raises error
        self.assertRaises(error.CannotListenError,
                          reactor.listenTCP, n, f, interface='127.0.0.1') 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:20,代码来源:test_tcp.py


注:本文中的twisted.internet.error.CannotListenError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。