def sendLine(self, line): "hook overloading the one used by linereceiver" #print "sendLine (%s):\n%s" % (self.state, line) #escape IAC in line mode, and correctly add \r\n line += self.delimiter line = line.replace(IAC, IAC + IAC).replace('\n', '\r\n') return self.transport.write(mccp_compress(self, line))
def _write(self, data): "hook overloading the one used in plain telnet" # print "_write (%s): %s" % (self.state, " ".join(str(ord(c)) for c in data)) data = data.replace('\n', '\r\n').replace('\r\r\n', '\r\n') #data = data.replace('\n', '\r\n') super(TelnetProtocol, self)._write(mccp_compress(self, data))
#print "cmdname, args, kwargs:", cmdname, args, kwargs msdp_string = self.msdp.evennia_to_msdp(cmdname, *args, **kwargs) #print "msdp_string:", msdp_string self.msdp.data_out(msdp_string) # parse **kwargs, falling back to ttype if nothing is given explicitly ttype = self.protocol_flags.get('TTYPE', {}) xterm256 = kwargs.get("xterm256", ttype.get('256 COLORS', False) if ttype.get("init_done") else True) useansi = kwargs.get("ansi", ttype and ttype.get('ANSI', False) if ttype.get("init_done") else True) raw = kwargs.get("raw", False) nomarkup = kwargs.get("nomarkup", not (xterm256 or useansi)) prompt = kwargs.get("prompt") if prompt: # Send prompt separately prompt = ansi.parse_ansi(_RE_N.sub("", text) + "{n", strip_ansi=nomarkup, xterm256=xterm256) prompt = prompt.replace(IAC, IAC + IAC).replace('\n', '\r\n') prompt += IAC + GA self.transport.write(mccp_compress(self, prompt)) #print "telnet kwargs=%s, message=%s" % (kwargs, text) #print "xterm256=%s, useansi=%s, raw=%s, nomarkup=%s, init_done=%s" % (xterm256, useansi, raw, nomarkup, ttype.get("init_done")) if raw: # no processing whatsoever self.sendLine(text) else: # we need to make sure to kill the color at the end in order # to match the webclient output. #print "telnet data out:", self.protocol_flags, id(self.protocol_flags), id(self), "nomarkup: %s, xterm256: %s" % (nomarkup, xterm256) self.sendLine(ansi.parse_ansi(_RE_N.sub("", text) + "{n", strip_ansi=nomarkup, xterm256=xterm256))
nomarkup = kwargs.get("nomarkup", not (xterm256 or useansi)) prompt = kwargs.get("prompt") echo = kwargs.get("echo", None) #print "telnet kwargs=%s, message=%s" % (kwargs, text) #print "xterm256=%s, useansi=%s, raw=%s, nomarkup=%s, init_done=%s" % (xterm256, useansi, raw, nomarkup, ttype.get("init_done")) if raw: # no processing whatsoever self.sendLine(text) elif text: # we need to make sure to kill the color at the end in order # to match the webclient output. #print "telnet data out:", self.protocol_flags, id(self.protocol_flags), id(self), "nomarkup: %s, xterm256: %s" % (nomarkup, xterm256) self.sendLine( ansi.parse_ansi(_RE_N.sub("", text) + "{n", strip_ansi=nomarkup, xterm256=xterm256)) if prompt: # Send prompt separately prompt = ansi.parse_ansi(_RE_N.sub("", prompt) + "{n", strip_ansi=nomarkup, xterm256=xterm256) prompt = prompt.replace(IAC, IAC + IAC).replace('\n', '\r\n') prompt += IAC + GA self.transport.write(mccp_compress(self, prompt)) if echo: self.transport.write(mccp_compress(self, IAC + WONT + ECHO)) elif echo == False: self.transport.write(mccp_compress(self, IAC + WILL + ECHO))
nomarkup = kwargs.get("nomarkup", not (xterm256 or useansi)) prompt = kwargs.get("prompt") echo = kwargs.get("echo", None) mxp = kwargs.get("mxp", self.protocol_flags.get("MXP", False)) #print "telnet kwargs=%s, message=%s" % (kwargs, text) #print "xterm256=%s, useansi=%s, raw=%s, nomarkup=%s, init_done=%s" % (xterm256, useansi, raw, nomarkup, ttype.get("init_done")) if raw: # no processing whatsoever self.sendLine(text) elif text: # we need to make sure to kill the color at the end in order # to match the webclient output. #print "telnet data out:", self.protocol_flags, id(self.protocol_flags), id(self), "nomarkup: %s, xterm256: %s" % (nomarkup, xterm256) linetosend = ansi.parse_ansi(_RE_N.sub("", text) + "{n", strip_ansi=nomarkup, xterm256=xterm256, mxp=mxp) if mxp: linetosend = mxp_parse(linetosend) self.sendLine(linetosend) if prompt: # Send prompt separately prompt = ansi.parse_ansi(_RE_N.sub("", prompt) + "{n", strip_ansi=nomarkup, xterm256=xterm256) prompt = prompt.replace(IAC, IAC + IAC).replace('\n', '\r\n') prompt += IAC + GA self.transport.write(mccp_compress(self, prompt)) if echo: self.transport.write(mccp_compress(self, IAC+WONT+ECHO)) elif echo == False: self.transport.write(mccp_compress(self, IAC+WILL+ECHO))