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


Python support.bind_port方法代码示例

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


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

示例1: test_bind_port

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import bind_port [as 别名]
def test_bind_port(self):
        s = socket.socket()
        support.bind_port(s)
        s.listen(5)
        s.close()

    # Tests for temp_dir() 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:9,代码来源:test_test_support.py

示例2: setUp

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import bind_port [as 别名]
def setUp(self):
        self.serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.port = support.bind_port(self.serv)
        self.serv.listen() 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:6,代码来源:test_socket.py

示例3: bindSock

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import bind_port [as 别名]
def bindSock(self, sock):
        support.bind_port(sock, host=self.host) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:4,代码来源:test_socket.py

示例4: testInitNonBlocking

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import bind_port [as 别名]
def testInitNonBlocking(self):
        # reinit server socket
        self.serv.close()
        self.serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM |
                                                  socket.SOCK_NONBLOCK)
        self.port = support.bind_port(self.serv)
        self.serv.listen()
        # actual testing
        start = time.time()
        try:
            self.serv.accept()
        except OSError:
            pass
        end = time.time()
        self.assertTrue((end - start) < 1.0, "Error creating with non-blocking mode.") 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:17,代码来源:test_socket.py

示例5: setUp

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import bind_port [as 别名]
def setUp(self):
        self.old_stdout = sys.stdout
        self.output = io.StringIO()
        sys.stdout = self.output

        self.evt = threading.Event()
        self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.sock.settimeout(15)
        self.port = support.bind_port(self.sock)
        servargs = (self.evt, self.respdata, self.sock)
        threading.Thread(target=server, args=servargs).start()
        self.evt.wait()
        self.evt.clear() 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:15,代码来源:test_smtplib.py

示例6: test_bind_port

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import bind_port [as 别名]
def test_bind_port(self):
        s = socket.socket()
        support.bind_port(s)
        s.listen()
        s.close()

    # Tests for temp_dir() 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:9,代码来源:test_support.py

示例7: setUp

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import bind_port [as 别名]
def setUp(self):
        self.evt = threading.Event()
        self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.sock.settimeout(60)  # Safety net. Look issue 11812
        self.port = support.bind_port(self.sock)
        self.thread = threading.Thread(target=server, args=(self.evt,self.sock))
        self.thread.setDaemon(True)
        self.thread.start()
        self.evt.wait() 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:11,代码来源:test_telnetlib.py

示例8: setUp

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import bind_port [as 别名]
def setUp(self):
        self.serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.port = support.bind_port(self.serv)
        self.source_port = support.find_unused_port()
        self.serv.listen()
        self.conn = None 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:8,代码来源:test_httplib.py

示例9: __init__

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import bind_port [as 别名]
def __init__(self, certfile):
                self.certfile = certfile
                sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
                self.port = support.bind_port(sock, '')
                asyncore.dispatcher.__init__(self, sock)
                self.listen(5) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:8,代码来源:test_ssl.py

示例10: test_rude_shutdown

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import bind_port [as 别名]
def test_rude_shutdown(self):
            """A brutal shutdown of an SSL server should raise an OSError
            in the client when attempting handshake.
            """
            listener_ready = threading.Event()
            listener_gone = threading.Event()

            s = socket.socket()
            port = support.bind_port(s, HOST)

            # `listener` runs in a thread.  It sits in an accept() until
            # the main thread connects.  Then it rudely closes the socket,
            # and sets Event `listener_gone` to let the main thread know
            # the socket is gone.
            def listener():
                s.listen()
                listener_ready.set()
                newsock, addr = s.accept()
                newsock.close()
                s.close()
                listener_gone.set()

            def connector():
                listener_ready.wait()
                with socket.socket() as c:
                    c.connect((HOST, port))
                    listener_gone.wait()
                    try:
                        ssl_sock = ssl.wrap_socket(c)
                    except OSError:
                        pass
                    else:
                        self.fail('connecting to closed SSL socket should have failed')

            t = threading.Thread(target=listener)
            t.start()
            try:
                connector()
            finally:
                t.join() 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:42,代码来源:test_ssl.py

示例11: test_server_accept

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import bind_port [as 别名]
def test_server_accept(self):
            # Issue #16357: accept() on a SSLSocket created through
            # SSLContext.wrap_socket().
            context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
            context.verify_mode = ssl.CERT_REQUIRED
            context.load_verify_locations(CERTFILE)
            context.load_cert_chain(CERTFILE)
            server = socket.socket(socket.AF_INET)
            host = "127.0.0.1"
            port = support.bind_port(server)
            server = context.wrap_socket(server, server_side=True)

            evt = threading.Event()
            remote = None
            peer = None
            def serve():
                nonlocal remote, peer
                server.listen()
                # Block on the accept and wait on the connection to close.
                evt.set()
                remote, peer = server.accept()
                remote.recv(1)

            t = threading.Thread(target=serve)
            t.start()
            # Client wait until server setup and perform a connect.
            evt.wait()
            client = context.wrap_socket(socket.socket())
            client.connect((host, port))
            client_addr = client.getsockname()
            client.close()
            t.join()
            remote.close()
            server.close()
            # Sanity checks.
            self.assertIsInstance(remote, ssl.SSLSocket)
            self.assertEqual(peer, client_addr) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:39,代码来源:test_ssl.py

示例12: test_send

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import bind_port [as 别名]
def test_send(self):
        evt = threading.Event()
        sock = socket.socket()
        sock.settimeout(3)
        port = support.bind_port(sock)

        cap = BytesIO()
        args = (evt, cap, sock)
        t = threading.Thread(target=capture_server, args=args)
        t.start()
        try:
            # wait a little longer for the server to initialize (it sometimes
            # refuses connections on slow machines without this wait)
            time.sleep(0.2)

            data = b"Suppose there isn't a 16-ton weight?"
            d = dispatcherwithsend_noread()
            d.create_socket()
            d.connect((support.HOST, port))

            # give time for socket to connect
            time.sleep(0.1)

            d.send(data)
            d.send(data)
            d.send(b'\n')

            n = 1000
            while d.out_buffer and n > 0:
                asyncore.poll()
                n -= 1

            evt.wait()

            self.assertEqual(cap.getvalue(), data*2)
        finally:
            t.join(timeout=TIMEOUT)
            if t.is_alive():
                self.fail("join() timed out") 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:41,代码来源:test_asyncore.py

示例13: __init__

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import bind_port [as 别名]
def __init__(self, event):
            threading.Thread.__init__(self)
            self.event = event
            self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            self.port = support.bind_port(self.sock)
            # This will be set if the client wants us to wait before echoing
            # data back.
            self.start_resend_event = None 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:10,代码来源:test_asynchat.py

示例14: testAcceptTimeout

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import bind_port [as 别名]
def testAcceptTimeout(self):
        # Test accept() timeout
        support.bind_port(self.sock, self.localhost)
        self.sock.listen()
        self._sock_operation(1, 1.5, 'accept') 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:7,代码来源:test_timeout.py

示例15: testSend

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import bind_port [as 别名]
def testSend(self):
        # Test send() timeout
        with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as serv:
            support.bind_port(serv, self.localhost)
            serv.listen()
            self.sock.connect(serv.getsockname())
            # Send a lot of data in order to bypass buffering in the TCP stack.
            self._sock_operation(100, 1.5, 'send', b"X" * 200000) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:10,代码来源:test_timeout.py


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