改正了msnp.py的两个bug
颜黎昕
2023-12-01
msnp.py最“新”的版本是“Version 0.4.1 - January 15, 2004”, 现在来用会有bug,我改正了两个。
1.
在文件command.py line 35-36, 原是:
def parse(self, str):
s = split(str)
在文件session.py line 339-340, 原是:
buf = self.conn.receive_data_line()
self.__process_command_buf(buf)
但现在msn server会发如下命令:
<NOTIFICATION ver="2" id="2" siteid="0" siteurl="http://g.live.com/"><TO name="*******@hotmail.com" pid="0x0:0x0"/><MSG pri="1" id="2"><ACTION url="5mezh_cn/80"/><SUBSCR url="5mezh_cn/80"/><BODY lang="1033" icon=""><TEXT>To see your offline messages, get the latest version of Windows Live™ Messenger.
</TEXT></BODY></MSG></NOTIFICATION>ILN
NOT
但所调用函数 self.__process_command_buf(buf) 中无对上述命令的处理,所以我加入如下代码:
command.py中改为:
def parse(self, str):
if str[0] == '<' or str[0:3] == 'NOT':
return
s = split(str)
session.py中改为:
if (buf == None ):
return
elif(buf[0] != '<' and buf[:3] != 'NOT'):
self.__process_command_buf(buf)
第二:
在 chat.py line 222-224, as follows:
def __process_bye(self, buf):
bye = split(buf)
self.callbacks.friend_left(bye[1])
但类 Callbacks的方法friend_left(self, passport_id) 为空,所以,当命令 "BYE" 来到时(即一方关闭聊天窗口时,server发送“BYE"给另一方), 会继续从 socket读取数据, 然后会发生如下错误:
File "msnp_myhowie.py", line 101, in go
self._session.process(chats = True)
File "/usr/lib/python2.4/site-packages/msnp/session.py", line 348, in process
self.__process_command_buf(buf)
File "/usr/lib/python2.4/site-packages/msnp/session.py", line 376, in __process_command_buf
self.__process_rng(buf)
File "/usr/lib/python2.4/site-packages/msnp/session.py", line 451, in __process_rng
display_name, session_id)
File "/usr/lib/python2.4/site-packages/msnp/chat.py", line 105, in __init__
resp = self._receive_cmd(conn)
File "/usr/lib/python2.4/site-packages/msnp/session.py", line 65, in _receive_cmd
buf = conn.receive_data_line()
File "/usr/lib/python2.4/site-packages/msnp/net.py", line 79, in receive_data_line
in_byte = self.receive_data(1)
File "/usr/lib/python2.4/site-packages/msnp/net.py", line 44, in receive_data
return self.socket.recv(bufsize)
socket.error: (104, 'Connection reset by peer')
我将其改为
def __process_bye(self, buf):
del self.session.active_chats[self.session_id]
这样改正以后,就可以正常工作了。
将这俩个bug提交给msnp.py的开发者Manish Jethani (manish_jethani -@- yahoo.com),没有收到回复,看来其已不维护了。
因为msnp.py只是MSNP8, 下一步研究下高版本的协议,使支持发送离线消息。