From b3df5b44f48d868de5406cf680bba338d128a28b Mon Sep 17 00:00:00 2001 From: jamesbunton Date: Sat, 18 Mar 2006 12:33:06 +0000 Subject: [PATCH] Use vCard fullname if nickname isn't around. git-svn-id: http://delx.cjb.net/svn/pymsnt/trunk@127 55fbd22a-6204-0410-b2f0-b6c764c7e90a committer: jamesbunton --- src/avatar.py | 25 ++++++++++++++----------- src/config.py | 1 + src/contact.py | 9 +++------ src/debug.py | 1 + src/disco.py | 14 ++++++++------ src/session.py | 8 +++++++- src/tlib/msn/msnw.py | 2 +- src/xmlconfig.py | 2 +- 8 files changed, 36 insertions(+), 26 deletions(-) diff --git a/src/avatar.py b/src/avatar.py index ef47940..ab8b43f 100644 --- a/src/avatar.py +++ b/src/avatar.py @@ -1,17 +1,16 @@ # Copyright 2005 James Bunton # Licensed for distribution under the GPL version 2, check COPYING for details -import utils -import config +from debug import LogEvent, INFO, WARN, ERROR + from twisted.internet import reactor from tlib.xmlw import Element -from debug import LogEvent, INFO, WARN, ERROR + +import sha, base64, os, os.path + +import utils import config -import lang -import sha -import base64 -import os -import os.path + SPOOL_UMASK = 0077 @@ -49,8 +48,8 @@ class Avatar: def makePhotoElement(self): """ Returns an XML Element that can be put into the vCard. """ photo = Element((None, "PHOTO")) - type = photo.addElement("TYPE") - type.addContent("image/png") + cType = photo.addElement("TYPE") + cType.addContent("image/png") binval = photo.addElement("BINVAL") binval.addContent(base64.encodestring(self.getImageData())) return photo @@ -100,6 +99,8 @@ class AvatarCache: imageData = self.getAvatarData(key) if imageData: return Avatar(imageData, self) + else: + return None def getAvatarData(self, key): """ Loads the avatar with SHA1 hash of 'key' from disk and returns the data """ @@ -113,8 +114,10 @@ class AvatarCache: return data else: LogEvent(INFO, "", "Avatar not found.") - except IOError, e: + except IOError: LogEvent(WARN, "", "IOError reading avatar.") + else: + return None diff --git a/src/config.py b/src/config.py index bd513d0..dca4a70 100644 --- a/src/config.py +++ b/src/config.py @@ -33,4 +33,5 @@ background = False pid = "" debugLevel = "0" # 0->None, 1->Traceback, 2->WARN,ERROR, 3->INFO,WARN,ERROR +_debugLevel = 0 # Maintained by debug.reloadConfig as an int debugFile = "" diff --git a/src/contact.py b/src/contact.py index a4a216a..2e58902 100644 --- a/src/contact.py +++ b/src/contact.py @@ -1,16 +1,13 @@ # Copyright 2005 James Bunton # Licensed for distribution under the GPL version 2, check COPYING for details -import utils +from debug import LogEvent, INFO, WARN, ERROR + from twisted.internet import reactor from tlib.xmlw import Element -from debug import LogEvent, INFO, WARN, ERROR + import disco import legacy -import jabw -import config -import lang -import sha class Contact: diff --git a/src/debug.py b/src/debug.py index 4da2bbf..0f90522 100644 --- a/src/debug.py +++ b/src/debug.py @@ -2,6 +2,7 @@ # Licensed for distribution under the GPL version 2, check COPYING for details from twisted.python import log + import sys, time import config diff --git a/src/disco.py b/src/disco.py index 3fb2fc9..3e93a9b 100644 --- a/src/disco.py +++ b/src/disco.py @@ -1,15 +1,17 @@ # Copyright 2004-2005 James Bunton # Licensed for distribution under the GPL version 2, check COPYING for details -import utils -from tlib.xmlw import Element, jid +from debug import LogEvent, INFO, WARN, ERROR + from twisted.internet.defer import Deferred from twisted.internet import reactor -from debug import LogEvent, INFO, WARN, ERROR +from tlib.xmlw import Element, jid + import sys -import config -import legacy + import lang +import utils +import config XMPP_STANZAS = "urn:ietf:params:xml:ns:xmpp-stanzas" DISCO = "http://jabber.org/protocol/disco" @@ -113,7 +115,7 @@ class ServerDiscovery: try: # Stringprep froj = jid.intern(fro) to = jid.intern(to).full() - except Exception, e: + except Exception: LogEvent(WARN, "", "Dropping IQ because of stringprep error") # Check if it's a response to a send IQ diff --git a/src/session.py b/src/session.py index df5557e..c876fe7 100644 --- a/src/session.py +++ b/src/session.py @@ -118,9 +118,13 @@ class Session(jabw.JabberConnection): self.legacycon.updateAvatar() # Default avatar return avatarSet = False + name = "" for e in vCard.elements(): if e.name == "NICKNAME": - self.updateNickname(e.__str__()) + name = e.__str__() + if not name and e.name == "FN": + # Give priority to nickname + name = e.__str__() if e.name == "PHOTO": imageData = avatar.parsePhotoEl(e) if not imageData: @@ -128,6 +132,8 @@ class Session(jabw.JabberConnection): self.avatar = self.pytrans.avatarCache.setAvatar(imageData) self.legacycon.updateAvatar(self.avatar) avatarSet = True + if name: + self.updateNickname(e.__str__()) if not avatarSet: self.legacycon.updateAvatar() # Default avatar diff --git a/src/tlib/msn/msnw.py b/src/tlib/msn/msnw.py index 15e4783..6b58f50 100644 --- a/src/tlib/msn/msnw.py +++ b/src/tlib/msn/msnw.py @@ -7,7 +7,7 @@ from twisted.internet.defer import Deferred from twisted.internet.protocol import ClientFactory # System imports -import math, base64, binascii, math +import math, base64, binascii # Local imports from debug import LogEvent, INFO, WARN, ERROR diff --git a/src/xmlconfig.py b/src/xmlconfig.py index e8758b5..ea30655 100644 --- a/src/xmlconfig.py +++ b/src/xmlconfig.py @@ -61,7 +61,7 @@ def importOptions(options): if hasattr(config, o): setattr(config, o, options[0]) else: - print "Option %s is not a defined option. Ignoring!" % (tag) + print "Option %s is not a defined option. Ignoring!" % (o) def reloadConfig(file=None, options=None): if file: -- 2.39.2