From 7cbd2961a00825475f7f94f842fd2a1612d8f2e2 Mon Sep 17 00:00:00 2001 From: jamesbunton Date: Fri, 23 Dec 2005 09:25:14 +0000 Subject: [PATCH] Partially working with new msnw git-svn-id: http://delx.cjb.net/svn/pymsnt/trunk@62 55fbd22a-6204-0410-b2f0-b6c764c7e90a committer: jamesbunton --- src/ft.py | 2 +- src/legacy/glue.py | 40 ++++++++++++++++++--------------------- src/misciq.py | 1 + src/tlib/msn/__init__.py | 4 +++- src/tlib/msn/msn.py | 8 ++++++-- src/tlib/msn/msnw.py | 11 +++++------ src/tlib/msn/test_msnw.py | 14 +++++++------- 7 files changed, 41 insertions(+), 39 deletions(-) diff --git a/src/ft.py b/src/ft.py index a649be9..c7054bd 100644 --- 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 diff --git a/src/legacy/glue.py b/src/legacy/glue.py index 985d9dc..939751f 100644 --- a/src/legacy/glue.py +++ b/src/legacy/glue.py @@ -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) diff --git a/src/misciq.py b/src/misciq.py index c2b180b..aaf4703 100644 --- a/src/misciq.py +++ b/src/misciq.py @@ -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 diff --git a/src/tlib/msn/__init__.py b/src/tlib/msn/__init__.py index 7265691..f9928c3 100644 --- a/src/tlib/msn/__init__.py +++ b/src/tlib/msn/__init__.py @@ -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 diff --git a/src/tlib/msn/msn.py b/src/tlib/msn/msn.py index 6dc7f16..b0d37b8 100644 --- a/src/tlib/msn/msn.py +++ b/src/tlib/msn/msn.py @@ -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("