#! /usr/bin/python import asynchat,asyncore,socket class fake_asynchat(asynchat.async_chat): def __init__(self, host, port): asynchat.async_chat.__init__(self) self.create_socket(socket.AF_INET,socket.SOCK_STREAM) self.set_terminator('\r\n') #not bytes :-( self.data='' #not bytes :-( self.remote=(host,port) self.connect(self.remote) def handle_connect(self): self.push('A unicode string\r\n' 'That is not a byte string.\r\n') #not bytes :-( def get_data(self): r=self.data self.data='' #not bytes return r def collect_incoming_data(self, data): self.data += data def found_terminator(self): data=self.get_data() self.push(data) if __name__ == '__main__': fake_asynchat('127.0.0.1',8000) asyncore.loop()