*** /usr/lib/python2.3/telnetlib.py Wed Oct 16 03:45:13 2002 --- telnetlib.py Wed Oct 30 09:13:51 2002 *************** *** 26,32 **** when it is closed). Bugs: ! - may hang when connection is slow in the middle of an IAC sequence To do: - option negotiation --- 26,32 ---- when it is closed). Bugs: ! - may hang when connection is slow in the middle of an IAC sequence (FIXED!) To do: - option negotiation *************** *** 117,122 **** --- 117,123 ---- SSPI_LOGON = chr(139) # TELOPT SSPI LOGON PRAGMA_HEARTBEAT = chr(140) # TELOPT PRAGMA HEARTBEAT EXOPL = chr(255) # Extended-Options-List + MAXOPT = 255 # Upper limit (1byte) for options class Telnet: *************** *** 164,170 **** set_option_negotiation_callback(callback) Each time a telnet option is read on the input flow, this callback (if set) is called with the following parameters : ! callback(telnet socket, command (DO/DONT/WILL/WONT), option) No other action is done afterwards by telnetlib. """ --- 165,172 ---- set_option_negotiation_callback(callback) Each time a telnet option is read on the input flow, this callback (if set) is called with the following parameters : ! callback(telnet socket, command, option) ! option will be MAXOPT+1 when there is no option. No other action is done afterwards by telnetlib. """ *************** *** 185,190 **** --- 187,193 ---- self.irawq = 0 self.cookedq = '' self.eof = 0 + self.iacseq = '' # Buffer for IAC sequence. self.option_callback = None if host is not None: self.open(host, port) *************** *** 395,427 **** try: while self.rawq: c = self.rawq_getchar() ! if c == theNULL: ! continue ! if c == "\021": ! continue ! if c != IAC: ! buf = buf + c ! continue ! c = self.rawq_getchar() ! if c == IAC: ! buf = buf + c ! elif c in (DO, DONT): ! opt = self.rawq_getchar() ! self.msg('IAC %s %d', c == DO and 'DO' or 'DONT', ord(opt)) ! if self.option_callback: ! self.option_callback(self.sock, c, opt) else: ! self.sock.sendall(IAC + WONT + opt) ! elif c in (WILL, WONT): ! opt = self.rawq_getchar() ! self.msg('IAC %s %d', ! c == WILL and 'WILL' or 'WONT', ord(opt)) ! if self.option_callback: ! self.option_callback(self.sock, c, opt) else: ! self.sock.sendall(IAC + DONT + opt) ! else: ! self.msg('IAC %d not recognized' % ord(c)) except EOFError: # raised by self.rawq_getchar() pass self.cookedq = self.cookedq + buf --- 398,446 ---- try: while self.rawq: c = self.rawq_getchar() ! if not self.iacseq: ! if c == theNULL: ! continue ! if c == "\021": ! continue ! if c != IAC: ! buf = buf + c ! continue else: ! self.iacseq += c ! elif len(self.iacseq) == 1: ! 'IAC: IAC CMD [OPTION only for WILL/WONT/DO/DONT]' ! if c in (DO, DONT, WILL, WONT): ! self.iacseq += c ! continue ! ! self.iacseq = '' ! if c == IAC: ! buf = buf + c else: ! if self.option_callback: ! 'Actually need this one. opt = MAXOPT+1' ! self.option_callback(self.sock, c, MAXOPT+1) ! else: ! self.msg('IAC %d not recognized' % ord(c)) ! elif len(self.iacseq) == 2: ! cmd = self.iacseq[1] ! self.iacseq = '' ! opt = c ! if cmd in (DO, DONT): ! self.msg('IAC %s %d', ! cmd == DO and 'DO' or 'DONT', ord(opt)) ! if self.option_callback: ! self.option_callback(self.sock, cmd, opt) ! else: ! self.sock.sendall(IAC + WONT + opt) ! elif cmd in (WILL, WONT): ! self.msg('IAC %s %d', ! cmd == WILL and 'WILL' or 'WONT', ord(opt)) ! if self.option_callback: ! self.option_callback(self.sock, cmd, opt) ! else: ! self.sock.sendall(IAC + DONT + opt) except EOFError: # raised by self.rawq_getchar() pass self.cookedq = self.cookedq + buf