Message32633
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)
|
|
Date |
User |
Action |
Args |
2007-08-23 14:59:12 | admin | link | issue1772794 messages |
2007-08-23 14:59:12 | admin | create | |
|