python网站发布
2021-04-14 09:27
标签:网页 import set etc bind soft none sof app python网站发布 标签:网页 import set etc bind soft none sof app 原文地址:https://www.cnblogs.com/yongqi-wang/p/13336790.html"""
/etc/python3
@File : IO_HTTP.py
@Time : 2020/7/18 下午3:26
@Author : wangyongqi
@Email : 92644827@qq.com
@SOftware : PyCharm
"""
from socket import *
from select import *
import re
class WebServer:
def __init__(self,host=‘0.0.0.0‘,port=8000,html=None):
self.host=host
self.port=port
self.html=html
#做IO多路复用的并发模型
self.__rlist=[]
self.__wlist=[]
self.__xlist=[]
self.create_socket()
self.bind()
def create_socket(self):
self.sock=socket()
self.sock.setblocking(False)
def bind(self):
self.address=(self.host,self.port)
self.sock.bind(self.address)
def start(self):
self.sock.listen(5)
print(‘Listen the port %d‘%self.port)
self.__rlist.append(self.sock)
while True:
rs,ws,xs=select(self.__rlist,self.__wlist,self.__xlist)
for r in rs:
if r is self.sock:
connfd,addr=self.sock.accept()
connfd.setblocking(False)
self.__rlist.append(connfd)
else:
self.handle(r)
#处理客户请求
def handle(self,connfd):
request=connfd.recv(1024*1024).decode(‘utf8‘)
pattern=‘[A-Z]+\s+(?P
下一篇:python面向对象,类