Hi,
I had a problem where I suddenly couldn't add ICQ contacts anymore.
After quite a bit of research & a chat on #python I came up with the
following patch for oscar.py.
Could this be looked at & maybe applied to SVN?
Here is the comment from #python I got:
[02:10:56] <TFKyle> Z_God: struct.pack kind of requires bytestrings, so
you probably want to .encode your unicode strings so the results of
struct.pack don't get converted to unicode (failing of course 'cause
binary packed data tends to contain chars outside of ascii)
This would cause a variable to become a unicode string instead of a
bytestring & if a real bytestring would be appended later, it would try
to decode it as unicode resulting in a UnicodeDecoderException.
I can imagine there are even more occasions where this needs to be
fixed. I am currently running my PyICQt with only the fix on line 498
which fixes the "can't add new contacts" problem.
Thanks in advance,
Julius
--- oscar.py.old 2007-08-10 02:37:09.000000000 +0200
+++ oscar.py 2007-08-10 02:41:36.000000000 +0200
@@ -425,7 +425,7 @@
user.group = None
def oscarRep(self):
- data = struct.pack(">H", len(self.name)) +self.name
+ data = struct.pack(">H", len(self.name)) +self.name.encode("utf-8")
tlvs = TLV(0xc8, struct.pack(">H",len(self.users)))
data += struct.pack(">4H", self.groupID, self.buddyID, 1, len(tlvs))
return data+tlvs
@@ -494,7 +494,7 @@
self.firstMessage = v # unix timestamp
def oscarRep(self):
- data = struct.pack(">H", len(self.name)) + self.name
+ data = struct.pack(">H", len(self.name)) + self.name.encode("utf-8")
tlvs = ""
if not self.authorized:
tlvs += TLV(0x0066) # awaiting authorization
@@ -540,7 +540,7 @@
log.msg("icon sum is %s" % binascii.hexlify(self.iconSum))
def oscarRep(self):
- data = struct.pack(">H", len(self.name)) + self.name
+ data = struct.pack(">H", len(self.name)) + self.name.encode("utf-8")
tlvs = TLV(0x00d5,struct.pack('!BB', 0x00, len(self.iconSum))+self.iconSum)+TLV(0x0131, "")
data += struct.pack(">4H", self.groupID, self.buddyID, AIM_SSI_TYPE_ICONINFO, len(tlvs))
return data+tlvs
@@ -563,7 +563,7 @@
self.visibility = tlvs.get(0xcb, None)
def oscarRep(self):
- data = struct.pack(">H", len(self.name)) + self.name
+ data = struct.pack(">H", len(self.name)) + self.name.encode("utf-8")
tlvs = ""
if self.permitMode:
tlvs += TLV(0xca,struct.pack('!B', self.permitMode))
_______________________________________________
py-transports mailing list
py-transports@blathersource.org
http://lists.modevia.com/cgi-bin/mailman/listinfo/py-transports