Mailing List Archive

[ python-Bugs-1772794 ] Using telnetlib fails with unicode strings containing only a
Bugs item #1772794, was opened at 2007-08-13 02:17
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1772794&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: None
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Pekka Laukkanen (laukpe)
Assigned to: Nobody/Anonymous (nobody)
Summary: Using telnetlib fails with unicode strings containing only a

Initial Comment:
It is not possible to use unicode strings with telnetlib even if these strings used only ascii characters. Example below demonstrates this.

Type "help", "copyright", "credits" or "license" for more information.
>>> import telnetlib
>>> telnetlib.Telnet().write(u'hi')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.5/telnetlib.py", line 289, in write
if IAC in buffer:
TypeError: 'in <string>' requires string as left operand


This problem is caused by bug #1772788 "chr(128) in u'only ascii' -> TypeError with misleading msg". The relevant code is following and IAC is chr(255).

def write(self, buffer):
if IAC in buffer:
buffer = buffer.replace(IAC, IAC+IAC)
self.msg("send %r", buffer)
self.sock.sendall(buffer)


There are many pretty obvious ways to have a workaround for the issue. I suggest something like follows assuming that accepting unicode data is ok in general. If unicode is not ok then "pass" can be replaced with something like "raise TypeError('Unicode data no accepted')" to at least have a better error message.

def write(self, buffer):
try:
buffer = buffer.replace(IAC, IAC+IAC)
except UnicodeError:
pass
self.msg("send %r", buffer)
self.sock.sendall(buffer)



----------------------------------------------------------------------

You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1772794&group_id=5470
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com