]> code.delx.au - pymsnt/commitdiff
Partially working with new msnw
authorjamesbunton <jamesbunton@55fbd22a-6204-0410-b2f0-b6c764c7e90a>
Fri, 23 Dec 2005 09:25:14 +0000 (09:25 +0000)
committerjamesbunton <jamesbunton@55fbd22a-6204-0410-b2f0-b6c764c7e90a>
Fri, 23 Dec 2005 09:25:14 +0000 (09:25 +0000)
git-svn-id: http://delx.cjb.net/svn/pymsnt/trunk@62 55fbd22a-6204-0410-b2f0-b6c764c7e90a

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

src/ft.py
src/legacy/glue.py
src/misciq.py
src/tlib/msn/__init__.py
src/tlib/msn/msn.py
src/tlib/msn/msnw.py
src/tlib/msn/test_msnw.py

index a649be9dcee76d4f6ed9d66a024e6202d2b9bf62..c7054bddb662601f5371f0537e46897dcdd23c03 100644 (file)
--- a/src/ft.py
+++ b/src/ft.py
@@ -111,7 +111,7 @@ class FileTransferOOB(resource.Resource):
                self.isLeaf = True
                self.files = {}
                self.oobSite = server.Site(self)
-               reactor.listenTCP(int(config.ftOOBPort), oobSite)
+               reactor.listenTCP(int(config.ftOOBPort), self.oobSite)
 
        def putFile(self, file, filename):
                self.files[filename] = file
index 985d9dc723f0a60f4c3ce96fe8dc5742a2f692a2..939751f4b08bf0f1653949fc6b0412fab7593eb8 100644 (file)
@@ -6,6 +6,7 @@ from twisted.internet import task
 from tlib.xmlw import Element
 from tlib import msn
 from debug import LogEvent, INFO, WARN, ERROR
+import disco
 import sha
 import groupchat
 import ft
@@ -219,7 +220,7 @@ class LegacyConnection(msn.MSNConnection):
                self.remoteNick = ""
 
                # Init the MSN bits
-               msn.MSNConnection.__init__(self, username, password)
+               msn.MSNConnection.__init__(self, username, password, self.session.jabberID)
 
                # User typing notification stuff
                self.userTyping = dict() # Indexed by contact MSN ID, stores whether the user is typing to this contact
@@ -238,18 +239,13 @@ class LegacyConnection(msn.MSNConnection):
        
                self.userTypingSend.stop()
        
-               msn.MSNConnection.removeMe(self)
                self.legacyList.removeMe()
                self.legacyList = None
                self.session = None
-
-       def jidRes(self, resource):
-               to = self.session.jabberID
-               if resource:
-                       to += "/" + resource
-
-               return to
        
+       def resourceOffline(self, resource):
+               pass
+
        def highestResource(self):
                """ Returns highest priority resource """
                return self.session.highestResource()
@@ -259,7 +255,7 @@ class LegacyConnection(msn.MSNConnection):
                if self.userTyping.has_key(dest):
                        del self.userTyping[dest]
                try:
-                       msn.MSNConnection.sendMessage(self, dest, resource, body, noerror)
+                       msn.MSNConnection.sendMessage(self, dest, body, noerror)
                        self.session.pytrans.statistics.stats["MessageCount"] += 1
                except:
                        self.failedMessage(dest, body)
@@ -308,20 +304,20 @@ class LegacyConnection(msn.MSNConnection):
                                self.sendTypingToContact(contact)
 
                # Send any typing notification messages from contacts to the user
-               for contact, resource in self.contactTyping.keys():
-                       self.contactTyping[(contact, resource)] += 1
-                       if self.contactTyping[(contact, resource)] >= 3:
-                               self.session.sendTypingNotification(self.jidRes(resource), msn2jid(contact), False)
-                               del self.contactTyping[(contact, resource)]
+               for contact in self.contactTyping.keys():
+                       self.contactTyping[contact] += 1
+                       if self.contactTyping[contact] >= 3:
+                               self.session.sendTypingNotification(self.session.jabberID, msn2jid(contact), False)
+                               del self.contactTyping[contact]
        
-       def gotContactTyping(self, contact, resource):
+       def gotContactTyping(self, contact):
                if not self.session: return
                # Check if the contact has only just started typing
-               if not self.contactTyping.has_key((contact, resource)):
-                       self.session.sendTypingNotification(self.jidRes(resource), msn2jid(contact), True)
+               if not self.contactTyping.has_key(contact):
+                       self.session.sendTypingNotification(self.session.jabberID, msn2jid(contact), True)
 
                # Reset the counter
-               self.contactTyping[(contact, resource)] = 0
+               self.contactTyping[contact] = 0
        
        def userTypingNotification(self, dest, resource, composing):
                if not self.session: return
@@ -337,10 +333,10 @@ class LegacyConnection(msn.MSNConnection):
                self.listSynced = True
                #self.legacyList.flushSubscriptionBuffer()
        
-       def gotMessage(self, remoteUser, resource, text):
+       def gotMessage(self, remoteUser, text):
                if not self.session: return
                source = msn2jid(remoteUser)
-               self.session.sendMessage(self.jidRes(resource), fro=source, body=text, mtype="chat")
+               self.session.sendMessage(self.session.jabberID, fro=source, body=text, mtype="chat")
                self.session.pytrans.statistics.stats["MessageCount"] += 1
        
        def avatarHashChanged(self, userHandle, hash):
@@ -382,7 +378,7 @@ class LegacyConnection(msn.MSNConnection):
                LogEvent(INFO, self.session.jabberID)
                self.session.ready = True
        
-       def contactStatusChanged(self, remoteUser):
+       def contactStatusChanged(self, remoteUser, statusCode, screenName):
                if not (self.session and self.getContacts()): return
                LogEvent(INFO, self.session.jabberID)
                
index c2b180b5101de58ea6864ef1146b6b530ef7b68a..aaf4703bc84e884bf6db06baa7d27a53c90f6966 100644 (file)
@@ -3,6 +3,7 @@
 
 import utils
 from twisted.internet import reactor, task
+from tlib.xmlw import Element, jid
 from debug import LogEvent, INFO, WARN, ERROR
 import jabw
 import legacy
index 72656911734b02844baa9b6ad1d0db7fd66ed7ba..f9928c34563206a71c4e9ec098fa1eb3a593b93e 100644 (file)
@@ -1,2 +1,4 @@
 from msnw import MSNConnection
-import msn
+from msn import FORWARD_LIST, ALLOW_LIST, BLOCK_LIST, REVERSE_LIST, PENDING_LIST
+from msn import STATUS_ONLINE, STATUS_OFFLINE, STATUS_HIDDEN, STATUS_IDLE, STATUS_AWAY, STATUS_BUSY, STATUS_BRB, STATUS_PHONE, STATUS_LUNCH
+from msn import MSNContact, MSNContactList
index 6dc7f1636ab98623f4604c7c6f6bb75aa6062733..b0d37b87b2a7d020e6d24dc7e916cee801d1eda8 100644 (file)
@@ -190,6 +190,10 @@ def getVals(params):
 
     return userHandle, screenName, userGuid, lists, groups
 
+def ljust(s, n, c):
+    """ Needed for Python 2.3 compatibility """
+    return s + (n-len(s))*c
+
 def b64enc(s):
     return base64.encodestring(s).replace("\n", "")
 
@@ -2478,9 +2482,9 @@ class FileContext:
         data = struct.pack("<LLQL", 638, 0x03, self.filesize, 0x01)
         data = data[:-1] # Uck, weird, but it works
         data += self.filename.encode("utf-16")[2:] # Strip off the utf16 BOM
-        data = data.ljust(570, '\0')
+        data = ljust(data, 570, '\0')
         data += struct.pack("<L", 0xFFFFFFFF)
-        data = data.ljust(638, '\0')
+        data = ljust(data, 638, '\0')
         return data
 
     def parse(self, packet):
index 1da75ee70be8fc72ae20692d1d5fa557b614ff14..202b94057c744809362b154f432b2d487d23af7d 100644 (file)
@@ -13,9 +13,6 @@ import math, base64, binascii, math
 from debug import LogEvent, INFO, WARN, ERROR
 from tlib.msn import msn
 
-# Imports from msn
-from msn import FORWARD_LIST, ALLOW_LIST, BLOCK_LIST, REVERSE_LIST, PENDING_LIST
-from msn import STATUS_ONLINE, STATUS_OFFLINE, STATUS_HIDDEN, STATUS_IDLE, STATUS_AWAY, STATUS_BUSY, STATUS_BRB, STATUS_PHONE, STATUS_LUNCH
 
 MAXMESSAGESIZE     = 1400
 SWITCHBOARDTIMEOUT = 30.0*60.0
@@ -39,6 +36,7 @@ class MSNConnection:
                self.password = password
                self.ident = ident
                self.timeout = None
+               self.notificationClient = None
                self.connect()
                LogEvent(INFO, self.ident)
        
@@ -189,7 +187,7 @@ class MSNConnection:
 
                if self.notificationClient:
                        count = 0
-                       def cb():
+                       def cb(ignored=None):
                                if count == 3:
                                        self.ourStatusChanged(statusCode, screenName, personal)
                        LogEvent(INFO, self.ident)
@@ -328,6 +326,7 @@ class NotificationClient(msn.NotificationClient):
                LogEvent(INFO, self.factory.msncon.ident)
                msn.NotificationClient.loggedIn(self, userHandle, verified)
                self.factory.msncon._notificationClientReady(self)
+               self.factory.msncon.loggedIn()
                if not verified:
                        self.factory.msncon.accountNotVerified()
        
@@ -511,7 +510,7 @@ class OneSwitchboardSession(SwitchboardSessionBase, msn.SwitchboardClient):
        def __init__(self, msncon, remoteUser):
                SwitchboardSessionBase.__init__(self, msncon)
                msn.SwitchboardClient.__init__(self)
-               self.remoteUser = remoteUser
+               self.remoteUser = str(remoteUser)
                self.ident = (self.msncon, self.remoteUser)
                self.chattingUsers = []
                self.timeout = None
@@ -575,7 +574,7 @@ class OneSwitchboardSession(SwitchboardSessionBase, msn.SwitchboardClient):
        def sendTypingNotification(self):
                LogEvent(INFO, self.ident)
                if self.ready:
-                       msn.SwitchboaldClient.sendTypingNotification(self)
+                       msn.SwitchboardClient.sendTypingNotification(self)
        
        CAPS = msn.MSNContact.MSNC1 | msn.MSNContact.MSNC2 | msn.MSNContact.MSNC3 | msn.MSNContact.MSNC4
        def sendAvatarRequest(self):
index e039f9caa3a5b82d095cf4283773a1511e4dba5b..feb78203ea0c656172cac8778923ac4756637663 100644 (file)
@@ -49,7 +49,7 @@ def clearAccount(msncon):
                        d.callback(None)
 
        for msnContact in msncon.getContacts().contacts.values():
-               for list in [msnw.FORWARD_LIST, msnw.BLOCK_LIST, msnw.ALLOW_LIST, msnw.PENDING_LIST]:
+               for list in [msn.FORWARD_LIST, msn.BLOCK_LIST, msn.ALLOW_LIST, msn.PENDING_LIST]:
                        if msnContact.lists & list:
                                msncon.remContact(list, msnContact.userHandle).addCallback(cb)
                                count += 1
@@ -116,14 +116,14 @@ class TestsUtil:
 
        def doAddContacts(self, both=True):
                # Adding users to each other's lists
-               self.user1.addContact(msnw.FORWARD_LIST, USER2).addCallback(self.cb)
+               self.user1.addContact(msn.FORWARD_LIST, USER2).addCallback(self.cb)
                self.loop("Adding user2 to user1's forward list.")
-               self.user1.addContact(msnw.ALLOW_LIST, USER2).addCallback(self.cb)
+               self.user1.addContact(msn.ALLOW_LIST, USER2).addCallback(self.cb)
                self.loop("Adding user2 to user1's allow list.")
                if both:
-                       self.user2.addContact(msnw.FORWARD_LIST, USER1).addCallback(self.cb)
+                       self.user2.addContact(msn.FORWARD_LIST, USER1).addCallback(self.cb)
                        self.loop("Adding user1 to user2's forward list.")
-                       self.user2.addContact(msnw.ALLOW_LIST, USER1).addCallback(self.cb)
+                       self.user2.addContact(msn.ALLOW_LIST, USER1).addCallback(self.cb)
                        self.loop("Adding user1 to user2's allow list.")
 
                        # Check the contacts have seen each other
@@ -212,7 +212,7 @@ class BasicTests(unittest.TestCase, TestsUtil):
                d = self.user1.sendFile(USER2, "myfile.txt", len(data))
                d.addCallback(gotFileSend)
                self.loop("Sending file.", cond="GOTMESSAGE", timeout=60*60)
-#      testFileSend.skip = "True"
+       testFileSend.skip = "True"
 
        def testFileReceive(self):
                if raw_input("\n\nALERT!!!\n\nPlease connect to account %s and send a file transfer to %s.\nType ok when you are ready: " % (USER2, USER1)).lower() != "ok":
@@ -241,5 +241,5 @@ class BasicTests(unittest.TestCase, TestsUtil):
                self.doPurgeContacts(both=False)
                self.doAddContacts(both=False)
                self.loop("Receiving file.", cond="GOTFILE", timeout=60*60)
-#      testFileReceive.skip = "True"
+       testFileReceive.skip = "True"