network programming and sockets this class plugs into the asyncore module and merely handles accept events class async_http(asyncore dispatcher)def _init_ (self,port)asyncore dispatcher _init_ (selfself create_socket(socket af_inet,socket sock_streamself setsockopt(socket sol_socketsocket so_reuseaddr self bind(('',port)self listen( def handle_accept(self)client,addr self accept(return async_http_handler(clientclass that handles asynchronous http requests class async_http_handler(asynchat async_chat)def _init_ (self,conn=none)asynchat async_chat _init_ (self,connself data [self got_header false self set_terminator( "\ \ \ \ "get incoming data and append to data buffer def collect_incoming_data(self,data)if not self got_headerself data append(datagot terminator (the blank linedef found_terminator(self)self got_header true header_data "join(self datadecode header data (binaryinto text for further processing header_text header_data decode('latin- 'header_lines header_text splitlines(request header_lines[ split(op request[ url request[ ][ :self process_request(op,urlpush text onto the outgoing streambut encode it first def push_text(self,text)self push(text encode('latin- ')process the request def process_request(selfopurl)if op ="get"if not os path exists(url)self send_error( ,"file % not found\ \ "elsetypeencoding mimetypes guess_type(urlsize os path getsize(urlself push_text("http/ ok\ \ "self push_text("content-length% \ \nsizeself push_text("content-type% \ \ntypeself push_text("\ \ "self push_with_producer(file_producer(url)elseself send_error( ,"% method not implementedopself close_when_done( lib fl ff