| 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 Client |
|---|
| 27 |
import iqTimeResponse |
|---|
| 28 |
import iqVersionResponse |
|---|
| 29 |
import iqBrowseResponse |
|---|
| 30 |
import SubscribeApproveResponse |
|---|
| 31 |
import PresenceMap |
|---|
| 32 |
import sys,socket |
|---|
| 33 |
|
|---|
| 34 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 35 |
#~ Definitions |
|---|
| 36 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 37 |
|
|---|
| 38 |
def _test(server, username, password, resource='Foundation.Jabber.Test'): |
|---|
| 39 |
def PrintMe(*args, **kw): |
|---|
| 40 |
print "PrintMe:", args, kw |
|---|
| 41 |
try: |
|---|
| 42 |
jc = Client.Client(server) |
|---|
| 43 |
jc._SetDebug(sys.stdout, sys.stdout) |
|---|
| 44 |
|
|---|
| 45 |
#jc.Register(username, password) |
|---|
| 46 |
jc.Authenticate(username, password, resource, callback=PrintMe) |
|---|
| 47 |
|
|---|
| 48 |
pm = PresenceMap.PresenceMap(jc) |
|---|
| 49 |
|
|---|
| 50 |
jc.BrowseJID('cvs-holloways', None) |
|---|
| 51 |
jc.BrowseJID('sholloway@cvs-holloways', None) |
|---|
| 52 |
|
|---|
| 53 |
jc.Presence() |
|---|
| 54 |
|
|---|
| 55 |
jc.Roster = jc.QueryRoster() |
|---|
| 56 |
|
|---|
| 57 |
jc.Responses = [] |
|---|
| 58 |
jc.Responses.append(iqTimeResponse.iqTimeResponse(jc)) |
|---|
| 59 |
jc.Responses.append(iqVersionResponse.iqVersionResponse(jc, 'RuneBlade Foundation Jabber Test', '0.2')) |
|---|
| 60 |
jc.Responses.append(iqBrowseResponse.iqBrowseResponse(jc)) |
|---|
| 61 |
jc.Responses.append(SubscribeApproveResponse.SubscribeApproveResponse(jc)) |
|---|
| 62 |
|
|---|
| 63 |
while 1: |
|---|
| 64 |
jc.Process(0.5) |
|---|
| 65 |
except KeyboardInterrupt: |
|---|
| 66 |
jc.SendXML('''<presence type="unavailable" />''') |
|---|
| 67 |
|
|---|
| 68 |
# Print out the roster |
|---|
| 69 |
print |
|---|
| 70 |
print "Roster" |
|---|
| 71 |
print "~"*10 |
|---|
| 72 |
for jid, rosteritem in jc.Roster.ByJID.iteritems(): |
|---|
| 73 |
print jid, rosteritem.subscription |
|---|
| 74 |
print " ", ''.join([x() for x in getattr(rosteritem, 'group', [])]) |
|---|
| 75 |
print "~"*10 |
|---|
| 76 |
print |
|---|
| 77 |
|
|---|
| 78 |
# Print out the presence map |
|---|
| 79 |
print |
|---|
| 80 |
print "Presence Map" |
|---|
| 81 |
print "~"*10 |
|---|
| 82 |
for jid, resouces in pm.ByResource.iteritems(): |
|---|
| 83 |
print jid |
|---|
| 84 |
for resource, presence in resouces.iteritems(): |
|---|
| 85 |
print " %s: %s (%s)" % (resource, getattr(presence, 'status', [''])[0], getattr(presence, 'show', [''])[0]) |
|---|
| 86 |
print "~"*10 |
|---|
| 87 |
print |
|---|
| 88 |
|
|---|
| 89 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 90 |
|
|---|
| 91 |
if __name__ == '__main__': |
|---|
| 92 |
import sys |
|---|
| 93 |
dictLogin = {'server':'cvs-holloways', 'username':'shane.test1', 'password':'testing'} |
|---|
| 94 |
strEval = ('","'.join(sys.argv[1:])).replace('=','":"') |
|---|
| 95 |
if strEval: |
|---|
| 96 |
strEval = ('{"%s"}'%strEval) |
|---|
| 97 |
dictLogin.update(eval(strEval, {}, {})) |
|---|
| 98 |
|
|---|
| 99 |
import time |
|---|
| 100 |
while 1: |
|---|
| 101 |
try: |
|---|
| 102 |
_test(**dictLogin) |
|---|
| 103 |
break |
|---|
| 104 |
except socket.error, info: |
|---|
| 105 |
print "Socket Error:", info |
|---|
| 106 |
time.sleep(5.0) |
|---|
| 107 |
print "Attempting Reconnect..." |
|---|
| 108 |
except KeyboardInterrupt: |
|---|
| 109 |
break |
|---|
| 110 |
|
|---|