]> code.delx.au - pymsnt/commitdiff
Read/write avatars with the 'b' option to fix Windows support.
authorjamesbunton <jamesbunton@55fbd22a-6204-0410-b2f0-b6c764c7e90a>
Tue, 7 Feb 2006 02:03:13 +0000 (02:03 +0000)
committerjamesbunton <jamesbunton@55fbd22a-6204-0410-b2f0-b6c764c7e90a>
Tue, 7 Feb 2006 02:03:13 +0000 (02:03 +0000)
Fix problem retrieving avatars with the new '/msn' code.
Default file transfer mode is 'tcp' for socks5 bytestreams.

git-svn-id: http://delx.cjb.net/svn/pymsnt/trunk@119 55fbd22a-6204-0410-b2f0-b6c764c7e90a

committer: jamesbunton <jamesbunton@55fbd22a-6204-0410-b2f0-b6c764c7e90a>

src/avatar.py
src/legacy/glue.py
src/misciq.py

index 4339d7fa6c85390636d82a061ea94e2188c3b3bd..ef479400f9229147a122b3f78c58757d71014997 100644 (file)
@@ -87,7 +87,7 @@ class AvatarCache:
                LogEvent(INFO, "", "Setting avatar %s" % (key))
                prev_umask = os.umask(SPOOL_UMASK)
                try:
-                       f = open(self.dir(key) + key, 'w')
+                       f = open(self.dir(key) + key, 'wb')
                        f.write(imageData)
                        f.close()
                except IOError, e:
@@ -107,7 +107,7 @@ class AvatarCache:
                        filename = self.dir(key) + key
                        if os.path.isfile(filename):
                                LogEvent(INFO, "Getting avatar.")
-                               f = open(filename)
+                               f = open(filename, "rb")
                                data = f.read()
                                f.close()
                                return data
index 4616261ce5b84e45d7ea1c0f2b25649b2ca5ad1a..0bc39ebb0fc6908435884366a1e3a902490ca062 100644 (file)
@@ -25,11 +25,11 @@ id = "msn"               # The transport identifier
 
 
 # Load the default avatars
-f = open(os.path.join("data", "defaultJabberAvatar.png"))
+f = open(os.path.join("data", "defaultJabberAvatar.png"), "rb")
 defaultJabberAvatarData = f.read()
 f.close()
 
-f = open(os.path.join("data", "defaultMSNAvatar.png"))
+f = open(os.path.join("data", "defaultMSNAvatar.png"), "rb")
 defaultAvatarData = f.read()
 f.close()
 defaultAvatar = avatar.AvatarCache().setAvatar(defaultAvatarData)
index a565755251c1b3bc86e33d5b0ad5b7ed86f582f1..1056cc8d5ebb172b449686950742ad80c28b2ef6 100644 (file)
@@ -220,8 +220,9 @@ class VCardFactory:
                fro = el.getAttribute("from")
                froj = jid.intern(fro)
                to = el.getAttribute("to")
+               toj = jid.intern(to)
                ID = el.getAttribute("id")
-               if(itype != "get" and itype != "error"):
+               if itype != "get" and itype != "error":
                        self.pytrans.discovery.sendIqError(to=fro, fro=config.jid, ID=ID, xmlns="vcard-temp", etype="cancel", condition="feature-not-implemented")
                        return
 
@@ -229,17 +230,17 @@ class VCardFactory:
 
                toGateway = not (to.find('@') > 0)
 
-               if(not toGateway):
-                       if(not self.pytrans.sessions.has_key(froj.userhost())):
+               if not toGateway:
+                       if not self.pytrans.sessions.has_key(froj.userhost()):
                                self.pytrans.discovery.sendIqError(to=fro, fro=config.jid, ID=ID, xmlns="vcard-temp", etype="auth", condition="not-authorized")
                                return
                        s = self.pytrans.sessions[froj.userhost()]
-                       if(not s.ready):
+                       if not s.ready:
                                self.pytrans.discovery.sendIqError(to=fro, fro=config.jid, ID=ID, xmlns="vcard-temp", etype="auth", condition="not-authorized")
                                return
                
-                       c = s.contactList.findContact(to)
-                       if(not c):
+                       c = s.contactList.findContact(toj.userhost())
+                       if not c:
                                self.pytrans.discovery.sendIqError(to=fro, fro=config.jid, ID=ID, xmlns="vcard-temp", etype="cancel", condition="recipient-unavailable")
                                return
 
@@ -252,7 +253,7 @@ class VCardFactory:
                iq.attributes["type"] = "result"
                vCard = iq.addElement("vCard")
                vCard.attributes["xmlns"] = "vcard-temp"
-               if(toGateway):
+               if toGateway:
                        FN = vCard.addElement("FN")
                        FN.addContent(legacy.name)
                        DESC = vCard.addElement("DESC")
@@ -260,10 +261,10 @@ class VCardFactory:
                        URL = vCard.addElement("URL")
                        URL.addContent(legacy.url)
                else:
-                       if(c.nickname):
+                       if c.nickname:
                                NICKNAME = vCard.addElement("NICKNAME")
                                NICKNAME.addContent(c.nickname)
-                       if(c.avatar):
+                       if c.avatar:
                                PHOTO = c.avatar.makePhotoElement()
                                vCard.addChild(PHOTO)
 
@@ -280,6 +281,7 @@ class IqAvatarFactory:
                fro = el.getAttribute("from")
                froj = jid.intern(fro)
                to = el.getAttribute("to")
+               toj = jid.intern(to)
                ID = el.getAttribute("id")
 
                if(itype != "get" and itype != "error"):
@@ -296,7 +298,7 @@ class IqAvatarFactory:
                        self.pytrans.discovery.sendIqError(to=fro, fro=config.jid, ID=ID, xmlns=disco.IQAVATAR, etype="auth", condition="not-authorized")
                        return
 
-               c = s.contactList.findContact(to)
+               c = s.contactList.findContact(toj.userhost())
                if(not c):
                        self.pytrans.discovery.sendIqError(to=fro, fro=config.jid, ID=ID, xmlns=disco.IQAVATAR, etype="cancel", condition="recipient-unavailable")
                        return
@@ -616,7 +618,7 @@ class Socks5FileTransfer:
                froj = jid.intern(el.getAttribute("from"))
 
                query = el.query
-               if not (query and query.getAttribute("mode") == "tcp"):
+               if not (query and query.getAttribute("mode", "tcp") == "tcp"):
                        return errOut()
                sid = query.getAttribute("sid")
                consumer = self.sessions.pop((froj.full(), sid), None)