Hello everyone, I couldn't find an implementation of MCCP (Mud Client Compression Protocol) using Twisted so I made my own, which I'm sharing if anyone else has a use for it.
You can find a description of MCCP here: http://www.mudstandards.org/MCCP_Specification Since I'm fairly new to Twisted I would appreciate any input about how to improve this if you find a better/cleaner way to do it. import zlib from twisted.conch.telnet import TelnetTransport from twisted.conch.telnet import DO, DONT COMPRESS2 = chr(86) class MCCPTelnetTransport(TelnetTransport): def connectionMade(self): self.zlib = None TelnetTransport.connectionMade(self) self.will(COMPRESS2) def commandReceived(self, command, argument): if argument == COMPRESS2: if command == DO: self.requestNegotiation(COMPRESS2, "") self.zlib = zlib.compressobj() elif command == DONT: pass else: TelnetTransport.commandReceived(self, command, argument) def write(self, data): data = data.replace('\n', '\r\n') if self.zlib: data = self.zlib.compress(data) data += self.zlib.flush(zlib.Z_SYNC_FLUSH) self.transport.write(data) -- Simon Vermeersch _______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python