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


Python socketserver.StreamRequestHandler方法代码示例

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


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

示例1: _prepare_server

# 需要导入模块: import socketserver [as 别名]
# 或者: from socketserver import StreamRequestHandler [as 别名]
def _prepare_server(self, address):
        class RequestHandler(socketserver.StreamRequestHandler):
            # 打开 TCP_NODELAY
            disable_nagle_algorithm = True

            def handle(sub_self):
                if self.timeout is not None:
                    sub_self.connection.settimeout(self.timeout)

                self.connection_class(
                    self, self.stream_class(sub_self.connection), sub_self.client_address
                ).handle()

        class MyServer(self.server_class):
            request_queue_size = self.backlog
            # 主线程退出时,所有子线程结束
            daemon_threads = True
            # 必须在server_bind之前
            allow_reuse_address = True

        self.server = MyServer(address, RequestHandler) 
开发者ID:dantezhu,项目名称:haven,代码行数:23,代码来源:thread_impl.py

示例2: test_shutdown

# 需要导入模块: import socketserver [as 别名]
# 或者: from socketserver import StreamRequestHandler [as 别名]
def test_shutdown(self):
        # Issue #2302: shutdown() should always succeed in making an
        # other thread leave serve_forever().
        class MyServer(socketserver.TCPServer):
            pass

        class MyHandler(socketserver.StreamRequestHandler):
            pass

        threads = []
        for i in range(20):
            s = MyServer((HOST, 0), MyHandler)
            t = threading.Thread(
                name='MyServer serving',
                target=s.serve_forever,
                kwargs={'poll_interval':0.01})
            t.daemon = True  # In case this function raises.
            threads.append((t, s))
        for t, s in threads:
            t.start()
            s.shutdown()
        for t, s in threads:
            t.join()
            s.server_close() 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:26,代码来源:test_socketserver.py

示例3: test_shutdown_request_called_if_verify_request_false

# 需要导入模块: import socketserver [as 别名]
# 或者: from socketserver import StreamRequestHandler [as 别名]
def test_shutdown_request_called_if_verify_request_false(self):
        # Issue #26309: BaseServer should call shutdown_request even if
        # verify_request is False

        class MyServer(socketserver.TCPServer):
            def verify_request(self, request, client_address):
                return False

            shutdown_called = 0
            def shutdown_request(self, request):
                self.shutdown_called += 1
                socketserver.TCPServer.shutdown_request(self, request)

        server = MyServer((HOST, 0), socketserver.StreamRequestHandler)
        s = socket.socket(server.address_family, socket.SOCK_STREAM)
        s.connect(server.server_address)
        s.close()
        server.handle_request()
        self.assertEqual(server.shutdown_called, 1)
        server.server_close() 
开发者ID:ShikyoKira,项目名称:Project-New-Reign---Nemesis-Main,代码行数:22,代码来源:test_socketserver.py

示例4: test_basics

# 需要导入模块: import socketserver [as 别名]
# 或者: from socketserver import StreamRequestHandler [as 别名]
def test_basics(self):
        class Handler(socketserver.StreamRequestHandler):
            def handle(self):
                self.server.wfile = self.wfile
                self.server.wfile_fileno = self.wfile.fileno()
                self.server.request_fileno = self.request.fileno()

        server = socketserver.TCPServer((HOST, 0), Handler)
        self.addCleanup(server.server_close)
        s = socket.socket(
            server.address_family, socket.SOCK_STREAM, socket.IPPROTO_TCP)
        with s:
            s.connect(server.server_address)
        server.handle_request()
        self.assertIsInstance(server.wfile, io.BufferedIOBase)
        self.assertEqual(server.wfile_fileno, server.request_fileno) 
开发者ID:bkerler,项目名称:android_universal,代码行数:18,代码来源:test_socketserver.py

示例5: test_TCPServer

# 需要导入模块: import socketserver [as 别名]
# 或者: from socketserver import StreamRequestHandler [as 别名]
def test_TCPServer(self):
        self.run_server(socketserver.TCPServer,
                        socketserver.StreamRequestHandler,
                        self.stream_examine) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:6,代码来源:test_socketserver.py

示例6: test_ThreadingTCPServer

# 需要导入模块: import socketserver [as 别名]
# 或者: from socketserver import StreamRequestHandler [as 别名]
def test_ThreadingTCPServer(self):
        self.run_server(socketserver.ThreadingTCPServer,
                        socketserver.StreamRequestHandler,
                        self.stream_examine) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:6,代码来源:test_socketserver.py

示例7: test_ForkingTCPServer

# 需要导入模块: import socketserver [as 别名]
# 或者: from socketserver import StreamRequestHandler [as 别名]
def test_ForkingTCPServer(self):
        with simple_subprocess(self):
            self.run_server(socketserver.ForkingTCPServer,
                            socketserver.StreamRequestHandler,
                            self.stream_examine) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:7,代码来源:test_socketserver.py

示例8: test_UnixStreamServer

# 需要导入模块: import socketserver [as 别名]
# 或者: from socketserver import StreamRequestHandler [as 别名]
def test_UnixStreamServer(self):
        self.run_server(socketserver.UnixStreamServer,
                        socketserver.StreamRequestHandler,
                        self.stream_examine) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:6,代码来源:test_socketserver.py

示例9: test_ThreadingUnixStreamServer

# 需要导入模块: import socketserver [as 别名]
# 或者: from socketserver import StreamRequestHandler [as 别名]
def test_ThreadingUnixStreamServer(self):
        self.run_server(socketserver.ThreadingUnixStreamServer,
                        socketserver.StreamRequestHandler,
                        self.stream_examine) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:6,代码来源:test_socketserver.py

示例10: test_tcpserver_bind_leak

# 需要导入模块: import socketserver [as 别名]
# 或者: from socketserver import StreamRequestHandler [as 别名]
def test_tcpserver_bind_leak(self):
        # Issue #22435: the server socket wouldn't be closed if bind()/listen()
        # failed.
        # Create many servers for which bind() will fail, to see if this result
        # in FD exhaustion.
        for i in range(1024):
            with self.assertRaises(OverflowError):
                socketserver.TCPServer((HOST, -1),
                                       socketserver.StreamRequestHandler) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:11,代码来源:test_socketserver.py

示例11: test_issue5949

# 需要导入模块: import socketserver [as 别名]
# 或者: from socketserver import StreamRequestHandler [as 别名]
def test_issue5949(self):

        class EOFHandler(socketserver.StreamRequestHandler):
            def handle(self):
                # EOF without sending a complete welcome message.
                self.wfile.write(b'* OK')

        with self.reaped_server(EOFHandler) as server:
            self.assertRaises(imaplib.IMAP4.abort,
                              self.imap_class, *server.server_address) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:12,代码来源:test_imaplib.py

示例12: test_InterruptServerSelectCall

# 需要导入模块: import socketserver [as 别名]
# 或者: from socketserver import StreamRequestHandler [as 别名]
def test_InterruptServerSelectCall(self):
        with self.mocked_select_module() as mock_select:
            pid = self.run_server(socketserver.TCPServer,
                                  socketserver.StreamRequestHandler,
                                  self.stream_examine)
            # Make sure select was called again:
            self.assertGreater(mock_select.called, 1)

    # Alas, on Linux (at least) recvfrom() doesn't return a meaningful
    # client address so this cannot work:

    # @requires_unix_sockets
    # def test_UnixDatagramServer(self):
    #     self.run_server(socketserver.UnixDatagramServer,
    #                     socketserver.DatagramRequestHandler,
    #                     self.dgram_examine)
    #
    # @requires_unix_sockets
    # def test_ThreadingUnixDatagramServer(self):
    #     self.run_server(socketserver.ThreadingUnixDatagramServer,
    #                     socketserver.DatagramRequestHandler,
    #                     self.dgram_examine)
    #
    # @requires_unix_sockets
    # @requires_forking
    # def test_ForkingUnixDatagramServer(self):
    #     self.run_server(socketserver.ForkingUnixDatagramServer,
    #                     socketserver.DatagramRequestHandler,
    #                     self.dgram_examine) 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:31,代码来源:test_socketserver.py

示例13: _setup

# 需要导入模块: import socketserver [as 别名]
# 或者: from socketserver import StreamRequestHandler [as 别名]
def _setup(self, imap_handler, connect=True):
        """
        Sets up imap_handler for tests. imap_handler should inherit from either:
        - SimpleIMAPHandler - for testing IMAP commands,
        - socketserver.StreamRequestHandler - if raw access to stream is needed.
        Returns (client, server).
        """
        class TestTCPServer(self.server_class):
            def handle_error(self, request, client_address):
                """
                End request and raise the error if one occurs.
                """
                self.close_request(request)
                self.server_close()
                raise

        self.addCleanup(self._cleanup)
        self.server = self.server_class((support.HOST, 0), imap_handler)
        self.thread = threading.Thread(
            name=self._testMethodName+'-server',
            target=self.server.serve_forever,
            # Short poll interval to make the test finish quickly.
            # Time between requests is short enough that we won't wake
            # up spuriously too many times.
            kwargs={'poll_interval': 0.01})
        self.thread.daemon = True  # In case this function raises.
        self.thread.start()

        if connect:
            self.client = self.imap_class(*self.server.server_address)

        return self.client, self.server 
开发者ID:ShikyoKira,项目名称:Project-New-Reign---Nemesis-Main,代码行数:34,代码来源:test_imaplib.py

示例14: test_EOF_without_complete_welcome_message

# 需要导入模块: import socketserver [as 别名]
# 或者: from socketserver import StreamRequestHandler [as 别名]
def test_EOF_without_complete_welcome_message(self):
        # http://bugs.python.org/issue5949
        class EOFHandler(socketserver.StreamRequestHandler):
            def handle(self):
                self.wfile.write(b'* OK')
        _, server = self._setup(EOFHandler, connect=False)
        self.assertRaises(imaplib.IMAP4.abort, self.imap_class,
                          *server.server_address) 
开发者ID:ShikyoKira,项目名称:Project-New-Reign---Nemesis-Main,代码行数:10,代码来源:test_imaplib.py


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