From ddcb2729611f3501fd7a1c97d8897b7175411a4c Mon Sep 17 00:00:00 2001 From: jamesbunton Date: Tue, 7 Feb 2006 02:03:13 +0000 Subject: [PATCH] Read/write avatars with the 'b' option to fix Windows support. 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 --- src/avatar.py | 4 ++-- src/legacy/glue.py | 4 ++-- src/misciq.py | 24 +++++++++++++----------- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/avatar.py b/src/avatar.py index 4339d7f..ef47940 100644 --- a/src/avatar.py +++ b/src/avatar.py @@ -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 diff --git a/src/legacy/glue.py b/src/legacy/glue.py index 4616261..0bc39eb 100644 --- a/src/legacy/glue.py +++ b/src/legacy/glue.py @@ -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) diff --git a/src/misciq.py b/src/misciq.py index a565755..1056cc8 100644 --- a/src/misciq.py +++ b/src/misciq.py @@ -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) -- 2.39.2