| 1 |
#!/usr/bin/env python |
|---|
| 2 |
##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 3 |
##~ License |
|---|
| 4 |
##~ |
|---|
| 5 |
##- The RuneBlade Foundation library is intended to ease some |
|---|
| 6 |
##- aspects of writing intricate Jabber, XML, and User Interface (wxPython, etc.) |
|---|
| 7 |
##- applications, while providing the flexibility to modularly change the |
|---|
| 8 |
##- architecture. Enjoy. |
|---|
| 9 |
##~ |
|---|
| 10 |
##~ Copyright (C) 2002 TechGame Networks, LLC. |
|---|
| 11 |
##~ |
|---|
| 12 |
##~ This library is free software; you can redistribute it and/or |
|---|
| 13 |
##~ modify it under the terms of the BSD style License as found in the |
|---|
| 14 |
##~ LICENSE file included with this distribution. |
|---|
| 15 |
##~ |
|---|
| 16 |
##~ TechGame Networks, LLC can be reached at: |
|---|
| 17 |
##~ 3578 E. Hartsel Drive #211 |
|---|
| 18 |
##~ Colorado Springs, Colorado, USA, 80920 |
|---|
| 19 |
##~ |
|---|
| 20 |
##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 21 |
|
|---|
| 22 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 23 |
#~ Imports |
|---|
| 24 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 25 |
|
|---|
| 26 |
import weakref |
|---|
| 27 |
from xml.sax.saxutils import escape, quoteattr |
|---|
| 28 |
from RBFoundation.BindCallable import BindCallable |
|---|
| 29 |
from SubjectObserver.CategorySubject import CategorySubject |
|---|
| 30 |
from iqQuery import iqQueryBase |
|---|
| 31 |
import JID |
|---|
| 32 |
|
|---|
| 33 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 34 |
#~ Definitions |
|---|
| 35 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 36 |
|
|---|
| 37 |
class iqRosterQuery(iqQueryBase, CategorySubject): |
|---|
| 38 |
def __init__(self, JC, callback=None, BidValue=1): |
|---|
| 39 |
self.OnRosterCallback = BindCallable(callback) |
|---|
| 40 |
iqQueryBase.__init__(self, JC, self.OnRosterInfo, BidValue) |
|---|
| 41 |
CategorySubject.__init__(self) |
|---|
| 42 |
self.SendQuery('jabber:iq:roster') |
|---|
| 43 |
self.ByJID = {} |
|---|
| 44 |
|
|---|
| 45 |
def OnRosterInfo(self, stream, iq): |
|---|
| 46 |
RosterItems = getattr(iq.query[0], 'item', []) |
|---|
| 47 |
for each in RosterItems: |
|---|
| 48 |
self.ByJID[each.jid] = each |
|---|
| 49 |
self.UpdateObserversEx({('rosteritem', each.jid):each}) |
|---|
| 50 |
if RosterItems: |
|---|
| 51 |
self.UpdateObservers(roster=self.ByJID) |
|---|
| 52 |
if self.OnRosterCallback: |
|---|
| 53 |
self.OnRosterCallback(stream, iq) |
|---|
| 54 |
|
|---|
| 55 |
def Get(self, jid, default=None): |
|---|
| 56 |
return self.ByJID.get(JID.JID(jid), default) |
|---|
| 57 |
|
|---|