本文整理汇总了Python中SocketServer.StreamRequestHandler方法的典型用法代码示例。如果您正苦于以下问题:Python SocketServer.StreamRequestHandler方法的具体用法?Python SocketServer.StreamRequestHandler怎么用?Python SocketServer.StreamRequestHandler使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SocketServer
的用法示例。
在下文中一共展示了SocketServer.StreamRequestHandler方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: 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()
close_server(s)
示例2: 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)
close_server(server)
示例3: 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()
示例4: setup
# 需要导入模块: import SocketServer [as 别名]
# 或者: from SocketServer import StreamRequestHandler [as 别名]
def setup(self):
"""Override SocketServer.StreamRequestHandler.setup to wrap rfile
with MemorizingFile.
This method will be called by BaseRequestHandler's constructor
before calling BaseHTTPRequestHandler.handle.
BaseHTTPRequestHandler.handle will call
BaseHTTPRequestHandler.handle_one_request and it will call
WebSocketRequestHandler.parse_request.
"""
# Call superclass's setup to prepare rfile, wfile, etc. See setup
# definition on the root class SocketServer.StreamRequestHandler to
# understand what this does.
CGIHTTPServer.CGIHTTPRequestHandler.setup(self)
self.rfile = memorizingfile.MemorizingFile(
self.rfile,
max_memorized_lines=_MAX_MEMORIZED_LINES)
示例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)
示例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)
示例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)
示例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)
示例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)
示例10: 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)
示例11: 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)
示例12: 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('* OK')
with self.reaped_server(EOFHandler) as server:
self.assertRaises(imaplib.IMAP4.abort,
self.imap_class, *server.server_address)
示例13: 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)
示例14: test_UnixStreamServer
# 需要导入模块: import SocketServer [as 别名]
# 或者: from SocketServer import StreamRequestHandler [as 别名]
def test_UnixStreamServer(self):
self.run_server(SocketServer.UnixStreamServer,
SocketServer.StreamRequestHandler,
self.stream_examine)
示例15: test_ForkingUnixStreamServer
# 需要导入模块: import SocketServer [as 别名]
# 或者: from SocketServer import StreamRequestHandler [as 别名]
def test_ForkingUnixStreamServer(self):
with simple_subprocess(self):
self.run_server(ForkingUnixStreamServer,
SocketServer.StreamRequestHandler,
self.stream_examine)