[Python-Dev] Patch to telnetlib.py (original) (raw)

gregory dudek dudek at cim.mcgill.ca
Sat Mar 13 18:24:27 CET 2010


The Telnet module telnetlib.py can be very slow -- unusably slow -- for large automated data transfers. There are typically done in raw mode.

The attached patch greatly increased the speed of telnet interactions in raw mode. I submitted this a couple of year ago, but it was for an older branch of python.

There are 2 key things being done:

  1. concatenations string with string.join instead of '+' (which is probably a minor issue)
  2. wholesale appending the raw and processed buffers when the IAC character is not found. The should be examined carefully since I am not an expert in the Telnet protocol, but it seems to work very well giving me a 5x speedup.

--- installed/telnetlib.py 2010-02-02 22:57:58.000000000 -0500 +++ telnetlib.py 2010-03-13 12:17:02.000000000 -0500 @@ -30,6 +30,7 @@

+Modified by G. Dudek for greater efficiency. """

@@ -420,6 +421,14 @@ """ buf = ['', ''] try:

@@ -428,7 +437,7 @@ if c == "\021": continue if c != IAC:

@@ -480,8 +489,14 @@ self.iacseq = '' # Reset on EOF self.sb = 0 pass

@@ -516,7 +531,7 @@ buf = self.sock.recv(50) self.msg("recv %r", buf) self.eof = (not buf)



More information about the Python-Dev mailing list