Issue1755096

classification
Title: Problems with telnetlib
Type: Severity: normal
Components: None Versions:
Milestone:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: amak Nosy List: amak, cgroves, pekka.klarck
Priority: normal Keywords:

Created on 2007-07-16.20:39:39 by pekka.klarck, last changed 2007-07-23.06:28:46 by pekka.klarck.

Messages
msg1720 (view) Author: Pekka Klärck (pekka.klarck) Date: 2007-07-16.20:39:39
Python's telnetlib hasn't worked earlier because select module has been missing. I now tried it but got following pretty weird looking error. The code I run is below the stacktrace and it's mostly copied from http://docs.python.org/lib/telnet-example.html. I was using developer build created from revision 3319 (i.e. trunk HEAD).


peke@porkkana:~/workspace/jython$ ./jytip telnet_test.py peke ********
Traceback (innermost last):
  File "telnet_test.py", line 8, in ?
  File "/home/peke/workspace/jython/dist/Lib/telnetlib.py", line 294, in read_until
  File "/home/peke/workspace/jython/dist/Lib/select.py", line 179, in select
  File "/home/peke/workspace/jython/dist/Lib/select.py", line 94, in register
  File "/home/peke/workspace/jython/dist/Lib/select.py", line 65, in _getselectable
error: ("Object '<telnetlib.Telnet instance 2>' is not watchable", 88)

----------8<-------------------8<----------------

import sys
import telnetlib

username, password = sys.argv[1:3]

tn = telnetlib.Telnet("localhost")

tn.read_until("login: ")
tn.write(username + "\n")
tn.read_until("Password: ")
tn.write(password + "\n")

tn.write("ls\n")
tn.write("exit\n")

print tn.read_all()
msg1721 (view) Author: Alan Kennedy (amak) Date: 2007-07-19.18:33:15
Have checked in some fixes at revision 3332.

1. Now support the fileno() method as well as the getchannel() method for retrieving the SelectableChannels.

2. Added a cpython compatible select function which puts in all sockets into non-blocking mode before selection, as required by jython/java, and then restores the blocking mode afterwards.

However, there are still some modifications required for telnetlib to work, namely changing the import of select so that it imports the cpython compatible select.

Therefore, I am leaving this bug open for now, until telnetlib is truly fixed.
msg1722 (view) Author: Charlie Groves (cgroves) Date: 2007-07-21.05:46:39
Committed a version of telnetlib that uses cpython_compatible_select in r3334.  I don't have a telnet server running locally(actually, I'd never used telnet before tonight), so I used the following code to test:

import telnetlib

tn = telnetlib.Telnet("scn.org")
print tn.read_until('login:')
tn.write("visitor\r\n")
print tn.read_until('Press RETURN to Continue')

It definitely broke without the modifications to telnetlib, but you might want to your own test to make sure I didn't miss anything.
msg1723 (view) Author: Pekka Klärck (pekka.klarck) Date: 2007-07-23.06:28:46
I can confirm that the original example I presented here works without modifications when using latest revision (3351) from svn. Thanks a lot Alan and Charlie!
History
Date User Action Args
2007-07-16 20:39:39pekka.klarckcreate