• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python test_support.bind_port函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: testRecvfromTimeout

    def testRecvfromTimeout(self):
        # Test recvfrom() timeout
        _timeout = 2
        self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        self.sock.settimeout(_timeout)
        # Prevent "Address already in use" socket exceptions
        test_support.bind_port(self.sock, self.localhost)

        _t1 = time.time()
        self.assertRaises(socket.error, self.sock.recvfrom, 8192)
        _t2 = time.time()

        _delta = abs(_t1 - _t2)
        self.assertTrue(_delta < _timeout + self.fuzz,
                     "timeout (%g) is %g seconds more than expected (%g)"
                     %(_delta, self.fuzz, _timeout))
开发者ID:005,项目名称:gevent,代码行数:16,代码来源:test_timeout.py


示例2: test_send

    def test_send(self):
        self.evt = threading.Event()
        self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.sock.settimeout(3)
        self.port = test_support.bind_port(self.sock)

        cap = StringIO()
        args = (self.evt, cap, self.sock)
        threading.Thread(target=capture_server, args=args).start()

        # wait a little longer for the server to initialize (it sometimes
        # refuses connections on slow machines without this wait)
        time.sleep(0.2)

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

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

        d.send(data)
        d.send(data)
        d.send("\n")

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

        self.evt.wait()

        self.assertEqual(cap.getvalue(), data * 2)
开发者ID:Cinnz,项目名称:python,代码行数:34,代码来源:test_asyncore.py


示例3: setUp

 def setUp(self):
     self.evt = threading.Event()
     self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     self.sock.settimeout(3)
     self.port = test_support.bind_port(self.sock)
     threading.Thread(target=self.server, args=(self.evt,self.sock)).start()
     time.sleep(.1)
开发者ID:BillyboyD,项目名称:main,代码行数:7,代码来源:test_poplib.py


示例4: test_handshake_timeout

        def test_handshake_timeout(self):
            # Issue #5103: SSL handshake must respect the socket timeout
            server = socket.socket(socket.AF_INET)
            host = "127.0.0.1"
            port = test_support.bind_port(server)
            started = threading.Event()
            finish = False

            def serve():
                server.listen(5)
                started.set()
                conns = []
                while not finish:
                    r, w, e = select.select([server], [], [], 0.1)
                    if server in r:
                        # Let the socket hang around rather than having
                        # it closed by garbage collection.
                        conns.append(server.accept()[0])

            t = threading.Thread(target=serve)
            t.start()
            started.wait()

            try:
                try:
                    c = socket.socket(socket.AF_INET)
                    c.settimeout(0.2)
                    c.connect((host, port))
                    # Will attempt handshake and time out
                    try:
                        ssl.wrap_socket(c)
                    except ssl.SSLError, e:
                        self.assertTrue("timed out" in str(e), str(e))
                    else:
                        self.fail("SSLError wasn't raised")
开发者ID:exodrifter,项目名称:unity-python,代码行数:35,代码来源:test_ssl.py


示例5: listener

 def listener():
     s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     PORT[0] = test_support.bind_port(s, '', PORT[0])
     s.listen(5)
     s.accept()
     del s
     thread.exit()
开发者ID:facchinm,项目名称:SiRFLive,代码行数:7,代码来源:test_socket_ssl.py


示例6: testAcceptTimeout

    def testAcceptTimeout(self):
        # Test accept() timeout
        _timeout = 2
        self.sock.settimeout(_timeout)
        # Prevent "Address already in use" socket exceptions
        test_support.bind_port(self.sock, self.localhost)
        self.sock.listen(5)

        _t1 = time.time()
        self.assertRaises(socket.error, self.sock.accept)
        _t2 = time.time()

        _delta = abs(_t1 - _t2)
        self.assertTrue(_delta < _timeout + self.fuzz,
                     "timeout (%g) is %g seconds more than expected (%g)"
                     %(_delta, self.fuzz, _timeout))
开发者ID:005,项目名称:gevent,代码行数:16,代码来源:test_timeout.py


示例7: __init__

        def __init__(self, certificate, ssl_version=None,
                     certreqs=None, cacerts=None, expect_bad_connects=False,
                     chatty=True, connectionchatty=False, starttls_server=False,
                     wrap_accepting_socket=False):

            if ssl_version is None:
                ssl_version = ssl.PROTOCOL_TLSv1
            if certreqs is None:
                certreqs = ssl.CERT_NONE
            self.certificate = certificate
            self.protocol = ssl_version
            self.certreqs = certreqs
            self.cacerts = cacerts
            self.expect_bad_connects = expect_bad_connects
            self.chatty = chatty
            self.connectionchatty = connectionchatty
            self.starttls_server = starttls_server
            self.sock = socket.socket()
            self.flag = None
            if wrap_accepting_socket:
                self.sock = ssl.wrap_socket(self.sock, server_side=True,
                                            certfile=self.certificate,
                                            cert_reqs = self.certreqs,
                                            ca_certs = self.cacerts,
                                            ssl_version = self.protocol)
                if test_support.verbose and self.chatty:
                    sys.stdout.write(' server:  wrapped server socket as %s\n' % str(self.sock))
            self.port = test_support.bind_port(self.sock)
            self.active = False
            threading.Thread.__init__(self)
            self.daemon = True
开发者ID:Richardlxc,项目名称:python2.6,代码行数:31,代码来源:test_ssl.py


示例8: listener

 def listener():
     s = socket.socket()
     PORT[0] = test_support.bind_port(s, '', PORT[0])
     s.listen(5)
     listener_ready.set()
     s1, addr = s.accept()
     s1.close()
     listener_gone.set()
开发者ID:alkorzt,项目名称:pypy,代码行数:8,代码来源:test_socket_ssl.py


示例9: __init__

 def __init__(self, event):
     threading.Thread.__init__(self)
     self.event = event
     self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     self.port = test_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:2uller,项目名称:LotF,代码行数:8,代码来源:test_asynchat.py


示例10: _read_setUp

def _read_setUp(self):
    self.evt = threading.Event()
    self.dataq = Queue.Queue()
    self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    self.sock.settimeout(10)
    self.port = test_support.bind_port(self.sock)
    self.thread = threading.Thread(target=server, args=(self.evt,self.sock, self.dataq))
    self.thread.start()
    self.evt.wait()
开发者ID:2uller,项目名称:LotF,代码行数:9,代码来源:test_telnetlib.py


示例11: setUp

 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 = test_support.bind_port(self.sock)
     self.thread = threading.Thread(target=self.server, args=(self.evt, self.sock))
     self.thread.setDaemon(True)
     self.thread.start()
     self.evt.wait()
开发者ID:cimarieta,项目名称:usp,代码行数:9,代码来源:test_poplib.py


示例12: setUp

 def setUp(self):
     self.evt = threading.Event()
     self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     self.sock.settimeout(3)
     self.port = test_support.bind_port(self.sock)
     threading.Thread(target=self.server, args=(self.evt,self.sock)).start()
     # Wait for the server to be ready.
     self.evt.wait()
     self.evt.clear()
     ftplib.FTP.port = self.port
开发者ID:carlosrcjunior,项目名称:BCC-2s13-PI4-WebCrawler,代码行数:10,代码来源:test_ftplib.py


示例13: setUp

    def setUp(self):
        self.old_stdout = sys.stdout
        self.output = StringIO.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 = test_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:billtsay,项目名称:win-demo-opcua,代码行数:13,代码来源:test_smtplib.py


示例14: run

 def run(self):
     sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
     global PORT
     PORT = test_support.bind_port(sock, HOST, PORT)
     sock.listen(1)
     conn, client = sock.accept()
     buffer = ""
     while "\n" not in buffer:
         data = conn.recv(1)
         if not data:
             break
         buffer = buffer + data
     while buffer:
         n = conn.send(buffer)
         buffer = buffer[n:]
     conn.close()
     sock.close()
开发者ID:Alex-CS,项目名称:sonify,代码行数:18,代码来源:test_asynchat.py


示例15: test_rude_shutdown

        def test_rude_shutdown(self):
            """A brutal shutdown of an SSL server should raise an IOError
            in the client when attempting handshake.
            """
            listener_ready = threading.Event()
            listener_gone = threading.Event()

            s = socket.socket()
            port = test_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(5)
                listener_ready.set()
                s.accept()
                s.close()
                listener_gone.set()

            def connector():
                listener_ready.wait()
                c = socket.socket()
                c.connect((HOST, port))
                listener_gone.wait()
                try:
                    ssl_sock = ssl.wrap_socket(c)
                except IOError:
                    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:exodrifter,项目名称:unity-python,代码行数:39,代码来源:test_ssl.py


示例16: setUp

 def setUp(self):
     self.serv = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
     self.serv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
     global PORT
     PORT = test_support.bind_port(self.serv, HOST, PORT)
开发者ID:249550148,项目名称:gevent,代码行数:5,代码来源:test_socket.py


示例17: setUp

 def setUp(self):
     self.serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     TimeoutTest.PORT = test_support.bind_port(self.serv)
     self.serv.listen(5)
开发者ID:Kelauni22,项目名称:Meeple,代码行数:4,代码来源:test_httplib.py


示例18: setUp

 def setUp(self):
     self.serv = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
     self.port = test_support.bind_port(self.serv)
开发者ID:1310701102,项目名称:sl4a,代码行数:3,代码来源:test_socket.py


示例19: __init__

 def __init__(self, event):
     threading.Thread.__init__(self)
     self.event = event
     self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     self.port = test_support.bind_port(self.sock)
开发者ID:Cinnz,项目名称:python,代码行数:5,代码来源:test_asynchat.py


示例20: __init__

 def __init__(self, certfile):
     self.certfile = certfile
     asyncore.dispatcher.__init__(self)
     self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
     self.port = test_support.bind_port(self.socket)
     self.listen(5)
开发者ID:Cinnz,项目名称:python,代码行数:6,代码来源:test_ssl.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python test_support.bytes函数代码示例发布时间:2022-05-27
下一篇:
Python test_support._check_py3k_warnings函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap