classBaseRequestHandler:"""Base class for request handler classes.
This class is instantiated for each request to be handled. The
constructor sets the instance variables request, client_address
and server, and then calls the handle() method. To implement a
specific service, all you need to do is to derive a class which
defines a handle() method.
The handle() method can find the request as self.request, the
client address as self.client_address, and the server (in case it
needs access to per-server information) as self.server. Since a
separate instance is created for each request, the handle() method
can define other arbitrary instance variables.
"""def__init__(self, request, client_address, server):
self.request = request # conn
self.client_address = client_address # 客户端地址+端口号
self.server = server # 服务端的ip+端口号
self.setup()try:
self.handle()# myserver的实例, 所以必须自定义一个同名的方法finally:
self.finish()defsetup(self):passdefhandle(self):passdeffinish(self):pass