[py-transports] PyMSNt: Fix avatars in Google Talk
Lars T. Mikkelsen
ltm at mulm.dk
Mon Apr 10 17:00:21 GMT 2006
As you might know, Google Talk recently got support for vCard-Based
Avatars. Unfortunately, the avatars won't work with PyMSNt. I've
attached two patches to fix the issue.
gtalk-avatars-receiving.patch (receiving avatars from MSN users):
While PyMSNt breaks the base64 encoded avatar data into lines of 76
characters as recommended by JEP-0153, Section 4.6, Google Talk doesn't
ignore the whitespace characters as required by the JEP - and thus the
avatars in Google Talk will be all black. This is clearly a bug in
Google Talk and I've reported it to Google. This patch is a simple
workaround that encodes the avatar data without line breaks.
gtalk-avatars-sending.patch (sending avatars to MSN users):
Google Talk uses XML namespaces for vCard updates, that is:
<presence>...<upd:x xmlns:upd='vcard-temp:x:update'>...</presence>
To make PyMSNt correctly detect the namespace, it seems that the
Element.uri attribute has to be used (and not Element.defaultUri) - I
don't know the exact difference between uri and defaultUri, but perhaps
defaultUri should just be replaced with uri throughout the entire source
code. Furthermore, the Google Talk server won't allow retrieval of the
vCard, unless the requesting entity has a resource (otherwise a
resource-constraint error is returned). This patch fixes both issues.
Finally, the Google Talk server seems to do some kind of rate limiting
on vCard requests. Currently, PyMSNt will make a lot of requests for the
same vCard. I don't have an exact solution for this, however, I'm
thinking that it's sufficient to only process presence stanzas to the
transport itself in jabw.JabberConnection.onPresence() - that is add a
"if to.find('@') < 0" somewhere in this function. I think it's a general
(and important) issue if PyMSNt makes more vCard requests than
necessary, as this requires a lot of bandwith.
Best regards,
Lars
-------------- next part --------------
Index: src/avatar.py
===================================================================
--- src/avatar.py (revision 133)
+++ src/avatar.py (working copy)
@@ -51,14 +51,14 @@
cType = photo.addElement("TYPE")
cType.addContent("image/png")
binval = photo.addElement("BINVAL")
- binval.addContent(base64.encodestring(self.getImageData()))
+ binval.addContent(base64.b64encode(self.getImageData()))
return photo
def makeDataElement(self):
""" Returns an XML Element that can be put into a jabber:x:avatar IQ stanza. """
data = Element((None, "data"))
data["mimetype"] = "image/png"
- data.addContent(base64.encodestring(self.getImageData()))
+ data.addContent(base64.b64encode(self.getImageData()))
return data
def __eq__(self, other):
-------------- next part --------------
Index: src/jabw.py
===================================================================
--- src/jabw.py (revision 133)
+++ src/jabw.py (working copy)
@@ -267,7 +267,7 @@
show = child.__str__()
elif(child.name == "priority"):
priority = child.__str__()
- elif(child.defaultUri == disco.XVCARDUPDATE):
+ elif(child.uri == disco.XVCARDUPDATE):
avatarHash = " "
for child2 in child.elements():
if(child2.name == "photo"):
Index: src/session.py
===================================================================
--- src/session.py (revision 133)
+++ src/session.py (working copy)
@@ -143,7 +143,7 @@
self.legacycon.updateAvatar()
LogEvent(INFO, self.jabberID, "Fetching avatar.")
- d = self.sendVCardRequest(to=self.jabberID, fro=config.jid)
+ d = self.sendVCardRequest(to=self.jabberID, fro=config.jid + "/msn")
d.addCallback(vCardReceived)
d.addErrback(errback)
More information about the py-transports
mailing list