]> code.delx.au - pymsnt/commitdiff
Use vCard fullname if nickname isn't around.
authorjamesbunton <jamesbunton@55fbd22a-6204-0410-b2f0-b6c764c7e90a>
Sat, 18 Mar 2006 12:33:06 +0000 (12:33 +0000)
committerjamesbunton <jamesbunton@55fbd22a-6204-0410-b2f0-b6c764c7e90a>
Sat, 18 Mar 2006 12:33:06 +0000 (12:33 +0000)
git-svn-id: http://delx.cjb.net/svn/pymsnt/trunk@127 55fbd22a-6204-0410-b2f0-b6c764c7e90a

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

src/avatar.py
src/config.py
src/contact.py
src/debug.py
src/disco.py
src/session.py
src/tlib/msn/msnw.py
src/xmlconfig.py

index ef479400f9229147a122b3f78c58757d71014997..ab8b43f38b7536bc1c280c2dd87793407c97f143 100644 (file)
@@ -1,17 +1,16 @@
 # Copyright 2005 James Bunton <james@delx.cjb.net>
 # 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
 
 
 
index bd513d0a1dbe7db30b0533a2d67166c769dc25a8..dca4a70ea8c105decd87fe8d2530175bd21bf59a 100644 (file)
@@ -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 = ""
index a4a216a900156b7b6cbed71e0897f2d53b2d8ca6..2e58902e7a410553eb5ce3c5f610086d0189e4e9 100644 (file)
@@ -1,16 +1,13 @@
 # Copyright 2005 James Bunton <james@delx.cjb.net>
 # 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:
index 4da2bbf14d484c435408f62bf24b50924e8d6eaa..0f90522e631b8e37bb2c8be0ef7eb076bdbc4ffd 100644 (file)
@@ -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
index 3fb2fc90d4d4efe7a45933c0f3625e4fc5ff74d6..3e93a9b017750cc2d298e91edc78ee57970bf081 100644 (file)
@@ -1,15 +1,17 @@
 # Copyright 2004-2005 James Bunton <james@delx.cjb.net>
 # 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
index df5557e08dc958aac871a82b91daf92395cfc489..c876fe7a3658721ec60287ba8128eb87fd7b0799 100644 (file)
@@ -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
 
index 15e47836d38ff6a81fd7e7568a78cda48369d758..6b58f50ed0097698ccb2621451218dc5bce07e87 100644 (file)
@@ -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
index e8758b529edfe81e6c2a6433dd5d8c438dc419ca..ea3065520af91794143e9c6bccc8cf14823ad42a 100644 (file)
@@ -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: