Making it easier to distinguish whether my test code is covering backend or frontend
authorEd Page <eopage@byu.net>
Wed, 13 Oct 2010 02:39:27 +0000 (21:39 -0500)
committerEd Page <eopage@byu.net>
Wed, 13 Oct 2010 02:39:27 +0000 (21:39 -0500)
16 files changed:
hand_tests/account.py [deleted file]
hand_tests/accountmgr.py [deleted file]
hand_tests/call.py [deleted file]
hand_tests/conv.py [deleted file]
hand_tests/generic.py [deleted file]
hand_tests/gv_call.py [new file with mode: 0755]
hand_tests/gv_conv.py [new file with mode: 0755]
hand_tests/gv_multisms.py [new file with mode: 0755]
hand_tests/multi_sms.py [deleted file]
hand_tests/params.py [deleted file]
hand_tests/presence.py [deleted file]
hand_tests/tp_account.py [new file with mode: 0755]
hand_tests/tp_accountmgr.py [new file with mode: 0755]
hand_tests/tp_generic.py [new file with mode: 0755]
hand_tests/tp_params.py [new file with mode: 0755]
hand_tests/tp_presence.py [new file with mode: 0755]

diff --git a/hand_tests/account.py b/hand_tests/account.py
deleted file mode 100755 (executable)
index 8b56500..0000000
+++ /dev/null
@@ -1,85 +0,0 @@
-#!/usr/bin/env python
-
-import logging
-
-import dbus
-import telepathy
-
-
-_moduleLogger = logging.getLogger(__name__)
-
-
-DBUS_PROPERTIES = 'org.freedesktop.DBus.Properties'
-
-
-class Account(telepathy.client.interfacefactory.InterfaceFactory):
-
-       def __init__(self, object_path, bus=None):
-               if not bus:
-                       bus = dbus.Bus()
-               service_name = 'org.freedesktop.Telepathy.AccountManager'
-               #service_name = object_path.replace('/', '.')[1:]
-
-               object = bus.get_object(service_name, object_path)
-               telepathy.client.interfacefactory.InterfaceFactory.__init__(self, object, telepathy.interfaces.ACCOUNT)
-
-               self[DBUS_PROPERTIES].Get(
-                       telepathy.interfaces.ACCOUNT,
-                       'Interfaces',
-                       reply_handler=self._on_get,
-                       error_handler=self._on_error,
-               )
-
-       def _on_get(self, stuff):
-               self.get_valid_interfaces().update(stuff)
-
-       def _on_error(self, *args):
-               _moduleLogger.error(args)
-
-
-def _process_acct_path(acct_path):
-       print "Account:", acct_path
-       acct = Account(acct_path)
-       conn = acct[DBUS_PROPERTIES].Get(telepathy.interfaces.ACCOUNT, 'Connection')
-       print "Connection:", conn
-       if conn == "/":
-               return
-       conn = telepathy.client.Connection(conn.replace('/', '.')[1:], conn)
-       conn.call_when_ready(lambda con: _show_conn(acct, acct_path, con))
-
-
-def _show_conn(acct, path, conn):
-       print path
-       print "\t", repr(acct)
-       print "\t", repr(conn)
-       acct["com.nokia.Account.Interface.ChannelRequests"].EnsureChannel(
-               {
-                       telepathy.interfaces.CHANNEL+".ChannelType": telepathy.interfaces.CHANNEL_TYPE_STREAMED_MEDIA,
-                       telepathy.interfaces.CHANNEL+".TargetHandleType": telepathy.constants.HANDLE_TYPE_CONTACT,
-                       telepathy.interfaces.CHANNEL+".TargetID": "512-961-6001",
-               },
-               0,
-               "",
-               reply_handler=lambda *args: _on_ensure("good", path, *args),
-               error_handler=lambda *args: _on_ensure("bad", path, *args),
-       )
-
-
-def _on_ensure(state, acct_path, *args):
-       print state
-       print "\t", acct_path
-       print "\tEnsure:", args
-
-
-if __name__ == '__main__':
-       import gobject
-       from dbus.mainloop.glib import DBusGMainLoop
-       import accountmgr
-
-       DBusGMainLoop(set_as_default=True)
-
-       am = accountmgr.AccountManager()
-       for acct_path in am[DBUS_PROPERTIES].Get(telepathy.interfaces.ACCOUNT_MANAGER, 'ValidAccounts'):
-               _process_acct_path(acct_path)
-
-       gobject.MainLoop().run()
diff --git a/hand_tests/accountmgr.py b/hand_tests/accountmgr.py
deleted file mode 100755 (executable)
index 32a6e96..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-#!/usr/bin/env python
-
-import logging
-
-import dbus
-import telepathy
-
-
-_moduleLogger = logging.getLogger(__name__)
-
-
-DBUS_PROPERTIES = 'org.freedesktop.DBus.Properties'
-
-
-class AccountManager(telepathy.client.interfacefactory.InterfaceFactory):
-
-       service_name = 'org.freedesktop.Telepathy.AccountManager'
-       object_path = '/org/freedesktop/Telepathy/AccountManager'
-
-       # Some versions of Mission Control are only activatable under this
-       # name, not under the generic AccountManager name
-       MC5_name = 'org.freedesktop.Telepathy.MissionControl5'
-       MC5_path = '/org/freedesktop/Telepathy/MissionControl5'
-
-       def __init__(self, bus=None):
-               if not bus:
-                       bus = dbus.Bus()
-
-               try:
-                       object = bus.get_object(self.service_name, self.object_path)
-               except:
-                       raise
-                       # try activating MissionControl5 (ugly work-around)
-                       mc5 = bus.get_object(self.MC5_name, self.MC5_path)
-                       import time
-                       time.sleep(1)
-                       object = bus.get_object(self.service_name, self.object_path)
-               telepathy.client.interfacefactory.InterfaceFactory.__init__(self, object, telepathy.interfaces.ACCOUNT_MANAGER)
-
-               self[DBUS_PROPERTIES].Get(
-                       telepathy.interfaces.ACCOUNT_MANAGER,
-                       'Interfaces',
-                       reply_handler=self._on_get,
-                       error_handler=self._on_error,
-               )
-
-       def _on_get(self, stuff):
-               self.get_valid_interfaces().update(stuff)
-
-       def _on_error(self, *args):
-               _moduleLogger.error(args)
-
-
-if __name__ == '__main__':
-       import gobject
-       from dbus.mainloop.glib import DBusGMainLoop
-       DBusGMainLoop(set_as_default=True)
-
-       am = AccountManager()
-       print am[DBUS_PROPERTIES].Get(telepathy.interfaces.ACCOUNT_MANAGER, 'ValidAccounts')
-
-       gobject.MainLoop().run()
diff --git a/hand_tests/call.py b/hand_tests/call.py
deleted file mode 100755 (executable)
index 9213ffc..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-#!/usr/bin/python
-
-import sys
-sys.path.insert(0,"../src")
-import logging
-
-import gvoice.backend as backend
-
-
-def main():
-       logging.basicConfig(level=logging.DEBUG)
-
-       args = sys.argv
-       username = args[1]
-       password = args[2]
-
-       PHONE_TYPE_HOME = 1
-       PHONE_TYPE_MOBILE = 2
-       PHONE_TYPE_WORK = 3
-       PHONE_TYPE_GIZMO = 7
-
-       outgoingNumber = args[3]
-       forward = args[4]
-       subscriber = args[5] # Number or "undefined"
-       phoneType = args[6] # See PHONE_TYPE_*
-       remember = args[7] # "1" or "0"
-       if len(args) == 9:
-               cookiePath = args[8]
-       else:
-               cookiePath = None
-
-       b = backend.GVoiceBackend(cookiePath)
-       b.login(username, password)
-       assert b.is_authed()
-
-       callData = {
-                       'outgoingNumber': outgoingNumber,
-                       'forwardingNumber': forward,
-                       'subscriberNumber': subscriber,
-                       'phoneType': phoneType,
-                       'remember': remember,
-       }
-       logging.info("%r" % callData)
-
-       page = b._get_page_with_token(
-               b._callUrl,
-               callData,
-       )
-       print page
-
-
-if __name__ == "__main__":
-       main()
diff --git a/hand_tests/conv.py b/hand_tests/conv.py
deleted file mode 100755 (executable)
index bb534c2..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-#!/usr/bin/python
-
-import sys
-sys.path.insert(0,"../src")
-import pprint
-import logging
-
-import util.coroutines as coroutines
-import gvoice.backend as backend
-import gvoice.conversations as conversations
-
-
-@coroutines.func_sink
-@coroutines.expand_positional
-def updates(conv, ids):
-       print ids
-
-
-def main():
-       logging.basicConfig(level=logging.DEBUG)
-
-       args = sys.argv
-       username = args[1]
-       password = args[2]
-
-       b = backend.GVoiceBackend()
-       b.login(username, password)
-
-       c = conversations.Conversations(b.get_texts)
-       c.updateSignalHandler.register_sink(updates)
-
-       c.load("/home/epage/.telepathy-theonering/cache/eopage/texts.cache")
-       if True:
-               c.update(force=True)
-       else:
-               c.update(force=False)
-       if False:
-               for key in c.get_conversations():
-                       print "="*50
-                       print key
-                       for conv in c.get_conversation(key).conversations:
-                               pprint.pprint(conv.to_dict())
-
-
-if __name__ == "__main__":
-       main()
diff --git a/hand_tests/generic.py b/hand_tests/generic.py
deleted file mode 100755 (executable)
index a25f77b..0000000
+++ /dev/null
@@ -1,700 +0,0 @@
-#!/usr/bin/env python
-
-import sys
-
-import gobject
-import dbus.mainloop.glib
-dbus.mainloop.glib.DBusGMainLoop(set_as_default = True)
-
-import telepathy
-
-
-DBUS_PROPERTIES = 'org.freedesktop.DBus.Properties'
-
-
-def get_registry():
-       reg = telepathy.client.ManagerRegistry()
-       reg.LoadManagers()
-       return reg
-
-
-def get_connection_manager(reg):
-       cm = reg.GetManager('theonering')
-       return cm
-
-
-class Action(object):
-
-       def __init__(self):
-               self._action = None
-
-       def queue_action(self):
-               pass
-
-       def append_action(self, action):
-               assert self._action is None
-               self._action = action
-
-       def get_next_action(self):
-               assert self._action is not None
-               return self._action
-
-       def _on_done(self):
-               if self._action is None:
-                       return
-               self._action.queue_action()
-
-       def _on_error(self, error):
-               print error
-
-       def _on_generic_message(self, *args):
-               pass
-
-
-class DummyAction(Action):
-
-       def queue_action(self):
-               gobject.idle_add(self._on_done)
-
-
-class QuitLoop(Action):
-
-       def __init__(self, loop):
-               super(QuitLoop, self).__init__()
-               self._loop = loop
-
-       def queue_action(self):
-               self._loop.quit()
-
-
-class DisplayParams(Action):
-
-       def __init__(self, cm):
-               super(DisplayParams, self).__init__()
-               self._cm = cm
-
-       def queue_action(self):
-               self._cm[telepathy.interfaces.CONN_MGR_INTERFACE].GetParameters(
-                       'gv',
-                       reply_handler = self._on_done,
-                       error_handler = self._on_error,
-               )
-
-       def _on_done(self, params):
-               print "Connection Parameters:"
-               for name, flags, signature, default in params:
-                       print "\t%s (%s)" % (name, signature),
-
-                       if flags & telepathy.constants.CONN_MGR_PARAM_FLAG_REQUIRED:
-                               print "required",
-                       if flags & telepathy.constants.CONN_MGR_PARAM_FLAG_REGISTER:
-                               print "register",
-                       if flags & telepathy.constants.CONN_MGR_PARAM_FLAG_SECRET:
-                               print "secret",
-                       if flags & telepathy.constants.CONN_MGR_PARAM_FLAG_DBUS_PROPERTY:
-                               print "dbus-property",
-                       if flags & telepathy.constants.CONN_MGR_PARAM_FLAG_HAS_DEFAULT:
-                               print "has-default(%s)" % default,
-
-                       print ""
-               super(DisplayParams, self)._on_done()
-
-
-class RequestConnection(Action):
-
-       def __init__(self, cm, username, password, forward):
-               super(RequestConnection, self).__init__()
-               self._cm = cm
-
-               self._conn = None
-               self._serviceName = None
-
-               self._username = username
-               self._password = password
-               self._forward = forward
-
-       @property
-       def conn(self):
-               return self._conn
-
-       @property
-       def serviceName(self):
-               return self._serviceName
-
-       def queue_action(self):
-               self._cm[telepathy.server.CONNECTION_MANAGER].RequestConnection(
-                       'gv',
-                       {
-                               'account':  self._username,
-                               'password': self._password,
-                               'forward':  self._forward,
-                       },
-                       reply_handler = self._on_done,
-                       error_handler = self._on_error,
-               )
-
-       def _on_done(self, busName, objectPath):
-               self._serviceName = busName
-               self._conn = telepathy.client.Connection(busName, objectPath)
-               super(RequestConnection, self)._on_done()
-
-
-class Connect(Action):
-
-       def __init__(self, connAction):
-               super(Connect, self).__init__()
-               self._connAction = connAction
-
-       def queue_action(self):
-               self._connAction.conn[telepathy.server.CONNECTION].connect_to_signal(
-                       'StatusChanged',
-                       self._on_change,
-               )
-               self._connAction.conn[telepathy.server.CONNECTION].Connect(
-                       reply_handler = self._on_generic_message,
-                       error_handler = self._on_error,
-               )
-
-       def _on_done(self):
-               super(Connect, self)._on_done()
-
-       def _on_change(self, status, reason):
-               if status == telepathy.constants.CONNECTION_STATUS_DISCONNECTED:
-                       print "Disconnected!"
-                       self._conn = None
-               elif status == telepathy.constants.CONNECTION_STATUS_CONNECTED:
-                       print "Connected"
-                       self._on_done()
-               elif status == telepathy.constants.CONNECTION_STATUS_CONNECTING:
-                       print "Connecting"
-               else:
-                       print "Status: %r" % status
-
-
-class SimplePresenceOptions(Action):
-
-       def __init__(self, connAction):
-               super(SimplePresenceOptions, self).__init__()
-               self._connAction = connAction
-
-       def queue_action(self):
-               self._connAction.conn[DBUS_PROPERTIES].Get(
-                       telepathy.server.CONNECTION_INTERFACE_SIMPLE_PRESENCE,
-                       'Statuses',
-                       reply_handler = self._on_done,
-                       error_handler = self._on_error,
-               )
-
-       def _on_done(self, statuses):
-               print "\tAvailable Statuses"
-               for (key, value) in statuses.iteritems():
-                       print "\t\t - %s" % key
-               super(SimplePresenceOptions, self)._on_done()
-
-
-class NullHandle(object):
-
-       @property
-       def handle(self):
-               return 0
-
-       @property
-       def handles(self):
-               return []
-
-
-class UserHandle(Action):
-
-       def __init__(self, connAction):
-               super(UserHandle, self).__init__()
-               self._connAction = connAction
-               self._handle = None
-
-       @property
-       def handle(self):
-               return self._handle
-
-       @property
-       def handles(self):
-               return [self._handle]
-
-       def queue_action(self):
-               self._connAction.conn[telepathy.server.CONNECTION].GetSelfHandle(
-                       reply_handler = self._on_done,
-                       error_handler = self._on_error,
-               )
-
-       def _on_done(self, handle):
-               self._handle = handle
-               super(UserHandle, self)._on_done()
-
-
-class RequestHandle(Action):
-
-       def __init__(self, connAction, handleType, handleNames):
-               super(RequestHandle, self).__init__()
-               self._connAction = connAction
-               self._handle = None
-               self._handleType = handleType
-               self._handleNames = handleNames
-
-       @property
-       def handle(self):
-               return self._handle
-
-       @property
-       def handles(self):
-               return [self._handle]
-
-       def queue_action(self):
-               self._connAction.conn[telepathy.server.CONNECTION].RequestHandles(
-                       self._handleType,
-                       self._handleNames,
-                       reply_handler = self._on_done,
-                       error_handler = self._on_error,
-               )
-
-       def _on_done(self, handles):
-               self._handle = handles[0]
-               super(RequestHandle, self)._on_done()
-
-
-class RequestChannel(Action):
-
-       def __init__(self, connAction, handleAction, channelType, handleType):
-               super(RequestChannel, self).__init__()
-               self._connAction = connAction
-               self._handleAction = handleAction
-               self._channel = None
-               self._channelType = channelType
-               self._handleType = handleType
-
-       @property
-       def channel(self):
-               return self._channel
-
-       def queue_action(self):
-               self._connAction.conn[telepathy.server.CONNECTION].RequestChannel(
-                       self._channelType,
-                       self._handleType,
-                       self._handleAction.handle,
-                       True,
-                       reply_handler = self._on_done,
-                       error_handler = self._on_error,
-               )
-
-       def _on_done(self, channelObjectPath):
-               self._channel = telepathy.client.Channel(self._connAction.serviceName, channelObjectPath)
-               super(RequestChannel, self)._on_done()
-
-
-class EnsureChannel(Action):
-
-       def __init__(self, connAction, channelType, handleType, handleId):
-               super(EnsureChannel, self).__init__()
-               self._connAction = connAction
-               self._channel = None
-               self._channelType = channelType
-               self._handleType = handleType
-               self._handleId = handleId
-               self._handle = None
-
-       @property
-       def channel(self):
-               return self._channel
-
-       @property
-       def handle(self):
-               return self._handle
-
-       @property
-       def handles(self):
-               return [self._handle]
-
-       def queue_action(self):
-               properties = {
-                       telepathy.server.CHANNEL_INTERFACE+".ChannelType": self._channelType,
-                       telepathy.server.CHANNEL_INTERFACE+".TargetHandleType": self._handleType,
-                       telepathy.server.CHANNEL_INTERFACE+".TargetID": self._handleId,
-               }
-               self._connAction.conn[telepathy.server.CONNECTION_INTERFACE_REQUESTS].EnsureChannel(
-                       properties,
-                       reply_handler = self._on_done,
-                       error_handler = self._on_error,
-               )
-
-       def _on_done(self, yours, channelObjectPath, properties):
-               print "Create?", not not yours
-               print "Path:", channelObjectPath
-               print "Properties:", properties
-               self._channel = telepathy.client.Channel(self._connAction.serviceName, channelObjectPath)
-               self._handle = properties[telepathy.server.CHANNEL_INTERFACE+".TargetHandle"]
-               super(EnsureChannel, self)._on_done()
-
-
-class CloseChannel(Action):
-
-       def __init__(self, connAction, chanAction):
-               super(CloseChannel, self).__init__()
-               self._connAction = connAction
-               self._chanAction = chanAction
-               self._handles = []
-
-       def queue_action(self):
-               self._chanAction.channel[telepathy.server.CHANNEL].Close(
-                       reply_handler = self._on_done,
-                       error_handler = self._on_error,
-               )
-
-       def _on_done(self):
-               super(CloseChannel, self)._on_done()
-
-
-class ContactHandles(Action):
-
-       def __init__(self, connAction, chanAction):
-               super(ContactHandles, self).__init__()
-               self._connAction = connAction
-               self._chanAction = chanAction
-               self._handles = []
-
-       @property
-       def handles(self):
-               return self._handles
-
-       def queue_action(self):
-               self._chanAction.channel[DBUS_PROPERTIES].Get(
-                       telepathy.server.CHANNEL_INTERFACE_GROUP,
-                       'Members',
-                       reply_handler = self._on_done,
-                       error_handler = self._on_error,
-               )
-
-       def _on_done(self, handles):
-               self._handles = list(handles)
-               super(ContactHandles, self)._on_done()
-
-
-class SimplePresenceStatus(Action):
-
-       def __init__(self, connAction, handleAction):
-               super(SimplePresenceStatus, self).__init__()
-               self._connAction = connAction
-               self._handleAction = handleAction
-
-       def queue_action(self):
-               self._connAction.conn[telepathy.server.CONNECTION_INTERFACE_SIMPLE_PRESENCE].GetPresences(
-                       self._handleAction.handles,
-                       reply_handler = self._on_done,
-                       error_handler = self._on_error,
-               )
-
-       def _on_done(self, aliases):
-               print "\tPresences:"
-               for hid, (presenceType, presence, presenceMessage) in aliases.iteritems():
-                       print "\t\t%s:" % hid, presenceType, presence, presenceMessage
-               super(SimplePresenceStatus, self)._on_done()
-
-
-class SetSimplePresence(Action):
-
-       def __init__(self, connAction, status, message):
-               super(SetSimplePresence, self).__init__()
-               self._connAction = connAction
-               self._status = status
-               self._message = message
-
-       def queue_action(self):
-               self._connAction.conn[telepathy.server.CONNECTION_INTERFACE_SIMPLE_PRESENCE].SetPresence(
-                       self._status,
-                       self._message,
-                       reply_handler = self._on_done,
-                       error_handler = self._on_error,
-               )
-
-       def _on_done(self):
-               super(SetSimplePresence, self)._on_done()
-
-
-class Aliases(Action):
-
-       def __init__(self, connAction, handleAction):
-               super(Aliases, self).__init__()
-               self._connAction = connAction
-               self._handleAction = handleAction
-
-       def queue_action(self):
-               self._connAction.conn[telepathy.server.CONNECTION_INTERFACE_ALIASING].RequestAliases(
-                       self._handleAction.handles,
-                       reply_handler = self._on_done,
-                       error_handler = self._on_error,
-               )
-
-       def _on_done(self, aliases):
-               print "\tAliases:"
-               for h, alias in zip(self._handleAction.handles, aliases):
-                       print "\t\t", h, alias
-               super(Aliases, self)._on_done()
-
-
-class Call(Action):
-
-       def __init__(self, connAction, chanAction, handleAction):
-               super(Call, self).__init__()
-               self._connAction = connAction
-               self._chanAction = chanAction
-               self._handleAction = handleAction
-
-       def queue_action(self):
-               self._chanAction.channel[telepathy.server.CHANNEL_TYPE_STREAMED_MEDIA].RequestStreams(
-                       self._handleAction.handle,
-                       [telepathy.constants.MEDIA_STREAM_TYPE_AUDIO],
-                       reply_handler = self._on_done,
-                       error_handler = self._on_error,
-               )
-
-       def _on_done(self, handle):
-               print "Call started"
-               super(Call, self)._on_done()
-
-
-class SendText(Action):
-
-       def __init__(self, connAction, chanAction, handleAction, messageType, message):
-               super(SendText, self).__init__()
-               self._connAction = connAction
-               self._chanAction = chanAction
-               self._handleAction = handleAction
-               self._messageType = messageType
-               self._message = message
-
-       def queue_action(self):
-               self._chanAction.channel[telepathy.server.CHANNEL_TYPE_TEXT].Send(
-                       self._messageType,
-                       self._message,
-                       reply_handler = self._on_done,
-                       error_handler = self._on_error,
-               )
-
-       def _on_done(self,):
-               print "Message sent"
-               super(SendText, self)._on_done()
-
-
-class Sleep(Action):
-
-       def __init__(self, length):
-               super(Sleep, self).__init__()
-               self._length = length
-
-       def queue_action(self):
-               gobject.timeout_add(self._length, self._on_done)
-
-
-class Block(Action):
-
-       def __init__(self):
-               super(Block, self).__init__()
-
-       def queue_action(self):
-               print "Blocking"
-
-       def _on_done(self):
-               #super(SendText, self)._on_done()
-               pass
-
-
-class Disconnect(Action):
-
-       def __init__(self, connAction):
-               super(Disconnect, self).__init__()
-               self._connAction = connAction
-
-       def queue_action(self):
-               self._connAction.conn[telepathy.server.CONNECTION].Disconnect(
-                       reply_handler = self._on_done,
-                       error_handler = self._on_error,
-               )
-
-
-if __name__ == '__main__':
-       loop = gobject.MainLoop()
-
-       reg = get_registry()
-       cm = get_connection_manager(reg)
-
-       nullHandle = NullHandle()
-
-       dummy = DummyAction()
-       firstAction = dummy
-       lastAction = dummy
-
-       if True:
-               dp = DisplayParams(cm)
-               lastAction.append_action(dp)
-               lastAction = lastAction.get_next_action()
-
-       if True:
-               username = sys.argv[1]
-               password = sys.argv[2]
-               forward = sys.argv[3]
-               reqcon = RequestConnection(cm, username, password, forward)
-               lastAction.append_action(reqcon)
-               lastAction = lastAction.get_next_action()
-
-               if False:
-                       reqcon = RequestConnection(cm, username, password, forward)
-                       lastAction.append_action(reqcon)
-                       lastAction = lastAction.get_next_action()
-
-               con = Connect(reqcon)
-               lastAction.append_action(con)
-               lastAction = lastAction.get_next_action()
-
-               if True:
-                       spo = SimplePresenceOptions(reqcon)
-                       lastAction.append_action(spo)
-                       lastAction = lastAction.get_next_action()
-
-               if True:
-                       uh = UserHandle(reqcon)
-                       lastAction.append_action(uh)
-                       lastAction = lastAction.get_next_action()
-
-                       ua = Aliases(reqcon, uh)
-                       lastAction.append_action(ua)
-                       lastAction = lastAction.get_next_action()
-
-                       sps = SimplePresenceStatus(reqcon, uh)
-                       lastAction.append_action(sps)
-                       lastAction = lastAction.get_next_action()
-
-                       if False:
-                               setdnd = SetSimplePresence(reqcon, "dnd", "")
-                               lastAction.append_action(setdnd)
-                               lastAction = lastAction.get_next_action()
-
-                               sps = SimplePresenceStatus(reqcon, uh)
-                               lastAction.append_action(sps)
-                               lastAction = lastAction.get_next_action()
-
-                               setdnd = SetSimplePresence(reqcon, "available", "")
-                               lastAction.append_action(setdnd)
-                               lastAction = lastAction.get_next_action()
-
-                               sps = SimplePresenceStatus(reqcon, uh)
-                               lastAction.append_action(sps)
-                               lastAction = lastAction.get_next_action()
-
-               if False:
-                       sl = Sleep(10 * 1000)
-                       lastAction.append_action(sl)
-                       lastAction = lastAction.get_next_action()
-
-               if False:
-                       rclh = RequestHandle(reqcon, telepathy.HANDLE_TYPE_LIST, ["subscribe"])
-                       lastAction.append_action(rclh)
-                       lastAction = lastAction.get_next_action()
-
-                       rclc = RequestChannel(
-                               reqcon,
-                               rclh,
-                               telepathy.CHANNEL_TYPE_CONTACT_LIST,
-                               telepathy.HANDLE_TYPE_LIST,
-                       )
-                       lastAction.append_action(rclc)
-                       lastAction = lastAction.get_next_action()
-
-                       ch = ContactHandles(reqcon, rclc)
-                       lastAction.append_action(ch)
-                       lastAction = lastAction.get_next_action()
-
-                       ca = Aliases(reqcon, ch)
-                       lastAction.append_action(ca)
-                       lastAction = lastAction.get_next_action()
-
-               if True:
-                       accountNumber = sys.argv[4]
-                       enChan = EnsureChannel(reqcon, telepathy.CHANNEL_TYPE_TEXT, telepathy.HANDLE_TYPE_CONTACT, accountNumber)
-                       lastAction.append_action(enChan)
-                       lastAction = lastAction.get_next_action()
-
-                       sendDebugtext = SendText(reqcon, enChan, enChan, telepathy.CHANNEL_TEXT_MESSAGE_TYPE_NORMAL, "Boo!")
-                       lastAction.append_action(sendDebugtext)
-                       lastAction = lastAction.get_next_action()
-
-               if False:
-                       rch = RequestHandle(reqcon, telepathy.HANDLE_TYPE_CONTACT, ["18005558355"]) #(1-800-555-TELL)
-                       lastAction.append_action(rch)
-                       lastAction = lastAction.get_next_action()
-
-                       # making a phone call
-                       if True:
-                               smHandle = rch
-                               smHandleType = telepathy.HANDLE_TYPE_CONTACT
-                       else:
-                               smHandle = nullHandle
-                               smHandleType = telepathy.HANDLE_TYPE_NONE
-                       rsmc = RequestChannel(
-                               reqcon,
-                               smHandle,
-                               telepathy.CHANNEL_TYPE_STREAMED_MEDIA,
-                               smHandleType,
-                       )
-                       lastAction.append_action(rsmc)
-                       lastAction = lastAction.get_next_action()
-
-                       if False:
-                               call = Call(reqcon, rsmc, rch)
-                               lastAction.append_action(call)
-                               lastAction = lastAction.get_next_action()
-
-                       # sending a text
-                       rtc = RequestChannel(
-                               reqcon,
-                               rch,
-                               telepathy.CHANNEL_TYPE_TEXT,
-                               smHandleType,
-                       )
-                       lastAction.append_action(rtc)
-                       lastAction = lastAction.get_next_action()
-
-                       if True:
-                               closechan = CloseChannel(reqcon, rtc)
-                               lastAction.append_action(closechan)
-                               lastAction = lastAction.get_next_action()
-
-                               rtc = RequestChannel(
-                                       reqcon,
-                                       rch,
-                                       telepathy.CHANNEL_TYPE_TEXT,
-                                       smHandleType,
-                               )
-                               lastAction.append_action(rtc)
-                               lastAction = lastAction.get_next_action()
-
-                       if False:
-                               sendtext = SendText(reqcon, rtc, rch, telepathy.CHANNEL_TEXT_MESSAGE_TYPE_NORMAL, "Boo!")
-                               lastAction.append_action(sendtext)
-                               lastAction = lastAction.get_next_action()
-
-               if False:
-                       bl = Block()
-                       lastAction.append_action(bl)
-                       lastAction = lastAction.get_next_action()
-
-               if False:
-                       sl = Sleep(30 * 1000)
-                       lastAction.append_action(sl)
-                       lastAction = lastAction.get_next_action()
-
-               dis = Disconnect(reqcon)
-               lastAction.append_action(dis)
-               lastAction = lastAction.get_next_action()
-
-       quitter = QuitLoop(loop)
-       lastAction.append_action(quitter)
-       lastAction = lastAction.get_next_action()
-
-       firstAction.queue_action()
-       loop.run()
diff --git a/hand_tests/gv_call.py b/hand_tests/gv_call.py
new file mode 100755 (executable)
index 0000000..9213ffc
--- /dev/null
@@ -0,0 +1,53 @@
+#!/usr/bin/python
+
+import sys
+sys.path.insert(0,"../src")
+import logging
+
+import gvoice.backend as backend
+
+
+def main():
+       logging.basicConfig(level=logging.DEBUG)
+
+       args = sys.argv
+       username = args[1]
+       password = args[2]
+
+       PHONE_TYPE_HOME = 1
+       PHONE_TYPE_MOBILE = 2
+       PHONE_TYPE_WORK = 3
+       PHONE_TYPE_GIZMO = 7
+
+       outgoingNumber = args[3]
+       forward = args[4]
+       subscriber = args[5] # Number or "undefined"
+       phoneType = args[6] # See PHONE_TYPE_*
+       remember = args[7] # "1" or "0"
+       if len(args) == 9:
+               cookiePath = args[8]
+       else:
+               cookiePath = None
+
+       b = backend.GVoiceBackend(cookiePath)
+       b.login(username, password)
+       assert b.is_authed()
+
+       callData = {
+                       'outgoingNumber': outgoingNumber,
+                       'forwardingNumber': forward,
+                       'subscriberNumber': subscriber,
+                       'phoneType': phoneType,
+                       'remember': remember,
+       }
+       logging.info("%r" % callData)
+
+       page = b._get_page_with_token(
+               b._callUrl,
+               callData,
+       )
+       print page
+
+
+if __name__ == "__main__":
+       main()
diff --git a/hand_tests/gv_conv.py b/hand_tests/gv_conv.py
new file mode 100755 (executable)
index 0000000..bb534c2
--- /dev/null
@@ -0,0 +1,46 @@
+#!/usr/bin/python
+
+import sys
+sys.path.insert(0,"../src")
+import pprint
+import logging
+
+import util.coroutines as coroutines
+import gvoice.backend as backend
+import gvoice.conversations as conversations
+
+
+@coroutines.func_sink
+@coroutines.expand_positional
+def updates(conv, ids):
+       print ids
+
+
+def main():
+       logging.basicConfig(level=logging.DEBUG)
+
+       args = sys.argv
+       username = args[1]
+       password = args[2]
+
+       b = backend.GVoiceBackend()
+       b.login(username, password)
+
+       c = conversations.Conversations(b.get_texts)
+       c.updateSignalHandler.register_sink(updates)
+
+       c.load("/home/epage/.telepathy-theonering/cache/eopage/texts.cache")
+       if True:
+               c.update(force=True)
+       else:
+               c.update(force=False)
+       if False:
+               for key in c.get_conversations():
+                       print "="*50
+                       print key
+                       for conv in c.get_conversation(key).conversations:
+                               pprint.pprint(conv.to_dict())
+
+
+if __name__ == "__main__":
+       main()
diff --git a/hand_tests/gv_multisms.py b/hand_tests/gv_multisms.py
new file mode 100755 (executable)
index 0000000..f1a01e5
--- /dev/null
@@ -0,0 +1,41 @@
+#!/usr/bin/python
+
+import sys
+sys.path.insert(0,"../src")
+import logging
+
+import gvoice.backend as backend
+
+
+def main():
+       logging.basicConfig(level=logging.DEBUG)
+
+       args = sys.argv
+       username = args[1]
+       password = args[2]
+
+       PHONE_TYPE_HOME = 1
+       PHONE_TYPE_MOBILE = 2
+       PHONE_TYPE_WORK = 3
+       PHONE_TYPE_GIZMO = 7
+
+       outgoingNumber1 = args[3]
+       outgoingNumber2 = args[4]
+
+       b = backend.GVoiceBackend(None)
+       b.login(username, password)
+       assert b.is_authed()
+
+       phoneNumbers = ",".join([outgoingNumber1, outgoingNumber2])
+       page = b._get_page_with_token(
+               b._sendSmsURL,
+               {
+                       'phoneNumber': phoneNumbers,
+                       'text': "Broadcast SMS experiment, did it work?",
+               },
+       )
+       print page
+
+
+if __name__ == "__main__":
+       main()
diff --git a/hand_tests/multi_sms.py b/hand_tests/multi_sms.py
deleted file mode 100755 (executable)
index f1a01e5..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-#!/usr/bin/python
-
-import sys
-sys.path.insert(0,"../src")
-import logging
-
-import gvoice.backend as backend
-
-
-def main():
-       logging.basicConfig(level=logging.DEBUG)
-
-       args = sys.argv
-       username = args[1]
-       password = args[2]
-
-       PHONE_TYPE_HOME = 1
-       PHONE_TYPE_MOBILE = 2
-       PHONE_TYPE_WORK = 3
-       PHONE_TYPE_GIZMO = 7
-
-       outgoingNumber1 = args[3]
-       outgoingNumber2 = args[4]
-
-       b = backend.GVoiceBackend(None)
-       b.login(username, password)
-       assert b.is_authed()
-
-       phoneNumbers = ",".join([outgoingNumber1, outgoingNumber2])
-       page = b._get_page_with_token(
-               b._sendSmsURL,
-               {
-                       'phoneNumber': phoneNumbers,
-                       'text': "Broadcast SMS experiment, did it work?",
-               },
-       )
-       print page
-
-
-if __name__ == "__main__":
-       main()
diff --git a/hand_tests/params.py b/hand_tests/params.py
deleted file mode 100755 (executable)
index c3906ea..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-#!/usr/bin/env python
-
-import gobject
-import dbus.mainloop.glib
-dbus.mainloop.glib.DBusGMainLoop(set_as_default = True)
-
-import telepathy
-from telepathy.interfaces import CONN_MGR_INTERFACE
-from telepathy.constants import CONN_MGR_PARAM_FLAG_DBUS_PROPERTY, \
-                                                               CONN_MGR_PARAM_FLAG_HAS_DEFAULT, \
-                                                               CONN_MGR_PARAM_FLAG_REGISTER, \
-                                                               CONN_MGR_PARAM_FLAG_REQUIRED, \
-                                                               CONN_MGR_PARAM_FLAG_SECRET
-
-def print_params (params):
-       for name, flags, signature, default in params:
-               print "%s (%s)" % (name, signature),
-
-               if flags & CONN_MGR_PARAM_FLAG_REQUIRED: print "required",
-               if flags & CONN_MGR_PARAM_FLAG_REGISTER: print "register",
-               if flags & CONN_MGR_PARAM_FLAG_SECRET: print "secret",
-               if flags & CONN_MGR_PARAM_FLAG_DBUS_PROPERTY: print "dbus-property",
-               if flags & CONN_MGR_PARAM_FLAG_HAS_DEFAULT: print "has-default(%s)" % default,
-
-               print ""
-
-       loop.quit ()
-
-def error_cb (*args):
-       print "Error:", args
-       loop.quit ()
-
-
-if __name__ == "__main__":
-       reg = telepathy.client.ManagerRegistry()
-       reg.LoadManagers()
-
-       # get the gabble Connection Manager
-       cm = reg.GetManager('theonering')
-
-       # get the parameters required to make a Jabber connection
-       cm[CONN_MGR_INTERFACE].GetParameters('gv',
-               reply_handler = print_params, error_handler = error_cb)
-
-       loop = gobject.MainLoop()
-       loop.run()
diff --git a/hand_tests/presence.py b/hand_tests/presence.py
deleted file mode 100755 (executable)
index 52b6c9f..0000000
+++ /dev/null
@@ -1,250 +0,0 @@
-#!/usr/bin/env python
-
-import sys
-
-import gobject
-# Begin Example 2-1
-import dbus.mainloop.glib
-dbus.mainloop.glib.DBusGMainLoop(set_as_default = True)
-# End Example 2-1
-
-import telepathy
-import telepathy.client
-from telepathy.interfaces import CONNECTION_MANAGER, \
-                                                                CONNECTION, \
-                                                                CONNECTION_INTERFACE_REQUESTS, \
-                                                                CONNECTION_INTERFACE_ALIASING, \
-                                                                CONNECTION_INTERFACE_SIMPLE_PRESENCE, \
-                                                                CONNECTION_INTERFACE_CONTACTS, \
-                                                                CHANNEL, \
-                                                                CHANNEL_TYPE_CONTACT_LIST, \
-                                                                CHANNEL_INTERFACE_GROUP
-from telepathy.constants import CONNECTION_STATUS_CONNECTED, \
-                                                               CONNECTION_STATUS_DISCONNECTED, \
-                                                               HANDLE_TYPE_LIST, \
-                                                               HANDLE_TYPE_GROUP
-
-DBUS_PROPERTIES = 'org.freedesktop.DBus.Properties'
-
-
-class Example(object):
-
-       def __init__ (self, account, password, forward):
-               """e.g. account  = 'bob@example.com/test'
-                               password = 'bigbob'
-               """
-               self.conn = None
-
-               reg = telepathy.client.ManagerRegistry()
-               reg.LoadManagers()
-
-               # get the gabble Connection Manager
-               self.cm = cm = reg.GetManager('theonering')
-
-               # get the parameters required to make a Jabber connection
-               # Begin Example 2-3
-               cm[CONNECTION_MANAGER].RequestConnection('gv',
-                       {
-                               'account':  account,
-                               'forward':  forward,
-                               'password': password,
-                       },
-                       reply_handler = self.request_connection_cb,
-                       error_handler = self.error_cb)
-               # End Example 2-3
-
-       def run(self):
-               self.loop = gobject.MainLoop()
-               try:
-                       self.loop.run()
-               except KeyboardInterrupt:
-                       print "Terminating connection..."
-                       self.disconnect()
-                       # reengage the mainloop so that we can disconnect cleanly
-                       self.loop.run()
-
-       def generic_reply (self, *args): pass
-
-       def error_cb (self, error):
-               print "Error:", error
-               self.disconnect()
-
-       def disconnect (self):
-               if self.conn is None:
-                       return
-               self.conn[CONNECTION].Disconnect(reply_handler = self.generic_reply,
-                                                                                error_handler = self.error_cb)
-
-       # Begin Example 2-4
-       def request_connection_cb (self, bus_name, object_path):
-               print bus_name, object_path
-               # End Example 2-4
-               self.conn = conn = telepathy.client.Connection(bus_name, object_path)
-
-               conn[CONNECTION].connect_to_signal('StatusChanged',
-                       self.status_changed_cb)
-
-               print "Establishing connection..."
-               conn[CONNECTION].Connect(reply_handler = self.generic_reply,
-                                                                error_handler = self.error_cb)
-
-       def status_changed_cb (self, status, reason):
-               conn = self.conn
-
-               if status == CONNECTION_STATUS_DISCONNECTED:
-                       print "Disconnected!"
-                       self.loop.quit()
-
-               if status != CONNECTION_STATUS_CONNECTED: return
-
-               print 'Carrier Detected' # remember dialup modems?
-               print 'Ctrl-C to disconnect'
-
-               # get a list of interfaces on this connection
-               conn[CONNECTION].GetInterfaces(reply_handler = self.get_interfaces_cb,
-                                                                          error_handler = self.error_cb)
-
-       def request_contact_list (self, *groups):
-               conn = self.conn
-
-               class ensure_channel_cb (object):
-                       def __init__ (self, parent, group):
-                               self.parent = parent
-                               self.group = group
-
-                       def __call__ (self, yours, path, properties):
-                               print "got channel for %s -> %s, yours = %s" % (
-                                       self.group, path, yours)
-
-                               channel = telepathy.client.Channel(conn.service_name, path)
-                               self.channel = channel
-
-                               # Begin Example 6-8
-                               # request the list of members
-                               channel[DBUS_PROPERTIES].Get(CHANNEL_INTERFACE_GROUP,
-                                                                                'Members',
-                                                                                reply_handler = self.members_cb,
-                                                                                error_handler = self.parent.error_cb)
-
-                       def members_cb (self, handles):
-                               # request information for this list of handles using the
-                               # Contacts interface
-                               conn[CONNECTION_INTERFACE_CONTACTS].GetContactAttributes(
-                                       handles, [
-                                               CONNECTION,
-                                               CONNECTION_INTERFACE_ALIASING,
-                                               CONNECTION_INTERFACE_SIMPLE_PRESENCE,
-                                       ],
-                                       False,
-                                       reply_handler = self.get_contact_attributes_cb,
-                                       error_handler = self.parent.error_cb)
-                               # End Example 6-8
-
-                       def get_contact_attributes_cb (self, attributes):
-                               return # DEBUG
-
-                               print '-' * 78
-                               print self.group
-                               print '-' * 78
-                               for member in attributes.values():
-                                       for key, value in member.iteritems():
-                                               print '%s: %s' % (key, value)
-                                       print
-                               print '-' * 78
-
-               def no_channel_available (error):
-                       print error
-
-               # we can either use TargetID if we know a name, or TargetHandle
-               # if we already have a handle
-               for group in groups:
-                       # Begin Example 6-6
-                       print "Ensuring channel to %s..." % group
-                       conn[CONNECTION_INTERFACE_REQUESTS].EnsureChannel({
-                               CHANNEL + '.ChannelType'         : CHANNEL_TYPE_CONTACT_LIST,
-                               CHANNEL + '.TargetHandleType': HANDLE_TYPE_LIST,
-                               CHANNEL + '.TargetID'           : group,
-                               },
-                               reply_handler = ensure_channel_cb(self, group),
-                               error_handler = no_channel_available)
-                       # End Example 6-6
-
-       def get_interfaces_cb (self, interfaces):
-               conn = self.conn
-
-               print "Interfaces:"
-               for interface in interfaces:
-                       print " - %s" % interface
-
-               if CONNECTION_INTERFACE_REQUESTS in interfaces:
-                       self.request_contact_list('subscribe',
-                                                                         'publish',
-                                                                         'hide',
-                                                                         'allow',
-                                                                         'deny',
-                                                                         'known')
-
-                       # get the open channelsA
-                       # Begin Example 2-6
-                       conn[CONNECTION_INTERFACE_REQUESTS].connect_to_signal(
-                                                                       'NewChannels',
-                                                                       self.get_channels_cb)
-                       # End Example 2-6
-                       # Begin Example 2-5
-                       conn[DBUS_PROPERTIES].Get(CONNECTION_INTERFACE_REQUESTS,
-                                                                       'Channels',
-                                                                       reply_handler = self.get_channels_cb,
-                                                                       error_handler = self.error_cb)
-                       # End Example 2-5
-
-               if CONNECTION_INTERFACE_SIMPLE_PRESENCE in interfaces:
-                       # Begin Example 5-4
-                       # request the statuses
-                       print 'Requesting statuses...'
-                       conn[DBUS_PROPERTIES].Get(CONNECTION_INTERFACE_SIMPLE_PRESENCE,
-                                                                       'Statuses',
-                                                                       reply_handler = self.get_statuses_cb,
-                                                                       error_handler = self.error_cb)
-
-                       # set our presence
-                       #print 'Setting presence...'
-                       #conn[CONNECTION_INTERFACE_SIMPLE_PRESENCE].SetPresence(
-                       #                                               'away',
-                       #                                               'At the Movies',
-                       #                                               reply_handler = self.generic_reply,
-                       #                                               error_handler = self.error_cb)
-                       # End Example 5-4
-
-               if CONNECTION_INTERFACE_CONTACTS in interfaces:
-                       print 'Requesting contact attribute interfaces...'
-                       conn[DBUS_PROPERTIES].Get(CONNECTION_INTERFACE_CONTACTS,
-                                                                       'ContactAttributeInterfaces',
-                                                                       reply_handler = self.get_contact_ifaces_cb,
-                                                                       error_handler = self.error_cb)
-
-       def get_channels_cb (self, channels):
-               for channel, props in channels:
-                       # find the group channels
-                       if props[CHANNEL + '.ChannelType'] != CHANNEL_TYPE_CONTACT_LIST or \
-                          props[CHANNEL + '.TargetHandleType'] != HANDLE_TYPE_GROUP:
-                               continue
-
-                       print 'GROUP: Got channel %s: %s' % (channel, props[CHANNEL + '.TargetID'])
-
-       def get_statuses_cb (self, value):
-               print "Statuses:"
-
-               for (key, value) in value.iteritems():
-                       print " - %s" % key
-
-       def get_contact_ifaces_cb (self, interfaces):
-               print "Contact Attribute Interfaces:"
-               for interface in interfaces:
-                       print " - %s" % interface
-
-if __name__ == '__main__':
-       username = sys.argv[1]
-       password = sys.argv[2]
-       forward = sys.argv[3]
-       e = Example(username, password, forward)
-       e.run()
diff --git a/hand_tests/tp_account.py b/hand_tests/tp_account.py
new file mode 100755 (executable)
index 0000000..8b56500
--- /dev/null
@@ -0,0 +1,85 @@
+#!/usr/bin/env python
+
+import logging
+
+import dbus
+import telepathy
+
+
+_moduleLogger = logging.getLogger(__name__)
+
+
+DBUS_PROPERTIES = 'org.freedesktop.DBus.Properties'
+
+
+class Account(telepathy.client.interfacefactory.InterfaceFactory):
+
+       def __init__(self, object_path, bus=None):
+               if not bus:
+                       bus = dbus.Bus()
+               service_name = 'org.freedesktop.Telepathy.AccountManager'
+               #service_name = object_path.replace('/', '.')[1:]
+
+               object = bus.get_object(service_name, object_path)
+               telepathy.client.interfacefactory.InterfaceFactory.__init__(self, object, telepathy.interfaces.ACCOUNT)
+
+               self[DBUS_PROPERTIES].Get(
+                       telepathy.interfaces.ACCOUNT,
+                       'Interfaces',
+                       reply_handler=self._on_get,
+                       error_handler=self._on_error,
+               )
+
+       def _on_get(self, stuff):
+               self.get_valid_interfaces().update(stuff)
+
+       def _on_error(self, *args):
+               _moduleLogger.error(args)
+
+
+def _process_acct_path(acct_path):
+       print "Account:", acct_path
+       acct = Account(acct_path)
+       conn = acct[DBUS_PROPERTIES].Get(telepathy.interfaces.ACCOUNT, 'Connection')
+       print "Connection:", conn
+       if conn == "/":
+               return
+       conn = telepathy.client.Connection(conn.replace('/', '.')[1:], conn)
+       conn.call_when_ready(lambda con: _show_conn(acct, acct_path, con))
+
+
+def _show_conn(acct, path, conn):
+       print path
+       print "\t", repr(acct)
+       print "\t", repr(conn)
+       acct["com.nokia.Account.Interface.ChannelRequests"].EnsureChannel(
+               {
+                       telepathy.interfaces.CHANNEL+".ChannelType": telepathy.interfaces.CHANNEL_TYPE_STREAMED_MEDIA,
+                       telepathy.interfaces.CHANNEL+".TargetHandleType": telepathy.constants.HANDLE_TYPE_CONTACT,
+                       telepathy.interfaces.CHANNEL+".TargetID": "512-961-6001",
+               },
+               0,
+               "",
+               reply_handler=lambda *args: _on_ensure("good", path, *args),
+               error_handler=lambda *args: _on_ensure("bad", path, *args),
+       )
+
+
+def _on_ensure(state, acct_path, *args):
+       print state
+       print "\t", acct_path
+       print "\tEnsure:", args
+
+
+if __name__ == '__main__':
+       import gobject
+       from dbus.mainloop.glib import DBusGMainLoop
+       import accountmgr
+
+       DBusGMainLoop(set_as_default=True)
+
+       am = accountmgr.AccountManager()
+       for acct_path in am[DBUS_PROPERTIES].Get(telepathy.interfaces.ACCOUNT_MANAGER, 'ValidAccounts'):
+               _process_acct_path(acct_path)
+
+       gobject.MainLoop().run()
diff --git a/hand_tests/tp_accountmgr.py b/hand_tests/tp_accountmgr.py
new file mode 100755 (executable)
index 0000000..32a6e96
--- /dev/null
@@ -0,0 +1,62 @@
+#!/usr/bin/env python
+
+import logging
+
+import dbus
+import telepathy
+
+
+_moduleLogger = logging.getLogger(__name__)
+
+
+DBUS_PROPERTIES = 'org.freedesktop.DBus.Properties'
+
+
+class AccountManager(telepathy.client.interfacefactory.InterfaceFactory):
+
+       service_name = 'org.freedesktop.Telepathy.AccountManager'
+       object_path = '/org/freedesktop/Telepathy/AccountManager'
+
+       # Some versions of Mission Control are only activatable under this
+       # name, not under the generic AccountManager name
+       MC5_name = 'org.freedesktop.Telepathy.MissionControl5'
+       MC5_path = '/org/freedesktop/Telepathy/MissionControl5'
+
+       def __init__(self, bus=None):
+               if not bus:
+                       bus = dbus.Bus()
+
+               try:
+                       object = bus.get_object(self.service_name, self.object_path)
+               except:
+                       raise
+                       # try activating MissionControl5 (ugly work-around)
+                       mc5 = bus.get_object(self.MC5_name, self.MC5_path)
+                       import time
+                       time.sleep(1)
+                       object = bus.get_object(self.service_name, self.object_path)
+               telepathy.client.interfacefactory.InterfaceFactory.__init__(self, object, telepathy.interfaces.ACCOUNT_MANAGER)
+
+               self[DBUS_PROPERTIES].Get(
+                       telepathy.interfaces.ACCOUNT_MANAGER,
+                       'Interfaces',
+                       reply_handler=self._on_get,
+                       error_handler=self._on_error,
+               )
+
+       def _on_get(self, stuff):
+               self.get_valid_interfaces().update(stuff)
+
+       def _on_error(self, *args):
+               _moduleLogger.error(args)
+
+
+if __name__ == '__main__':
+       import gobject
+       from dbus.mainloop.glib import DBusGMainLoop
+       DBusGMainLoop(set_as_default=True)
+
+       am = AccountManager()
+       print am[DBUS_PROPERTIES].Get(telepathy.interfaces.ACCOUNT_MANAGER, 'ValidAccounts')
+
+       gobject.MainLoop().run()
diff --git a/hand_tests/tp_generic.py b/hand_tests/tp_generic.py
new file mode 100755 (executable)
index 0000000..a25f77b
--- /dev/null
@@ -0,0 +1,700 @@
+#!/usr/bin/env python
+
+import sys
+
+import gobject
+import dbus.mainloop.glib
+dbus.mainloop.glib.DBusGMainLoop(set_as_default = True)
+
+import telepathy
+
+
+DBUS_PROPERTIES = 'org.freedesktop.DBus.Properties'
+
+
+def get_registry():
+       reg = telepathy.client.ManagerRegistry()
+       reg.LoadManagers()
+       return reg
+
+
+def get_connection_manager(reg):
+       cm = reg.GetManager('theonering')
+       return cm
+
+
+class Action(object):
+
+       def __init__(self):
+               self._action = None
+
+       def queue_action(self):
+               pass
+
+       def append_action(self, action):
+               assert self._action is None
+               self._action = action
+
+       def get_next_action(self):
+               assert self._action is not None
+               return self._action
+
+       def _on_done(self):
+               if self._action is None:
+                       return
+               self._action.queue_action()
+
+       def _on_error(self, error):
+               print error
+
+       def _on_generic_message(self, *args):
+               pass
+
+
+class DummyAction(Action):
+
+       def queue_action(self):
+               gobject.idle_add(self._on_done)
+
+
+class QuitLoop(Action):
+
+       def __init__(self, loop):
+               super(QuitLoop, self).__init__()
+               self._loop = loop
+
+       def queue_action(self):
+               self._loop.quit()
+
+
+class DisplayParams(Action):
+
+       def __init__(self, cm):
+               super(DisplayParams, self).__init__()
+               self._cm = cm
+
+       def queue_action(self):
+               self._cm[telepathy.interfaces.CONN_MGR_INTERFACE].GetParameters(
+                       'gv',
+                       reply_handler = self._on_done,
+                       error_handler = self._on_error,
+               )
+
+       def _on_done(self, params):
+               print "Connection Parameters:"
+               for name, flags, signature, default in params:
+                       print "\t%s (%s)" % (name, signature),
+
+                       if flags & telepathy.constants.CONN_MGR_PARAM_FLAG_REQUIRED:
+                               print "required",
+                       if flags & telepathy.constants.CONN_MGR_PARAM_FLAG_REGISTER:
+                               print "register",
+                       if flags & telepathy.constants.CONN_MGR_PARAM_FLAG_SECRET:
+                               print "secret",
+                       if flags & telepathy.constants.CONN_MGR_PARAM_FLAG_DBUS_PROPERTY:
+                               print "dbus-property",
+                       if flags & telepathy.constants.CONN_MGR_PARAM_FLAG_HAS_DEFAULT:
+                               print "has-default(%s)" % default,
+
+                       print ""
+               super(DisplayParams, self)._on_done()
+
+
+class RequestConnection(Action):
+
+       def __init__(self, cm, username, password, forward):
+               super(RequestConnection, self).__init__()
+               self._cm = cm
+
+               self._conn = None
+               self._serviceName = None
+
+               self._username = username
+               self._password = password
+               self._forward = forward
+
+       @property
+       def conn(self):
+               return self._conn
+
+       @property
+       def serviceName(self):
+               return self._serviceName
+
+       def queue_action(self):
+               self._cm[telepathy.server.CONNECTION_MANAGER].RequestConnection(
+                       'gv',
+                       {
+                               'account':  self._username,
+                               'password': self._password,
+                               'forward':  self._forward,
+                       },
+                       reply_handler = self._on_done,
+                       error_handler = self._on_error,
+               )
+
+       def _on_done(self, busName, objectPath):
+               self._serviceName = busName
+               self._conn = telepathy.client.Connection(busName, objectPath)
+               super(RequestConnection, self)._on_done()
+
+
+class Connect(Action):
+
+       def __init__(self, connAction):
+               super(Connect, self).__init__()
+               self._connAction = connAction
+
+       def queue_action(self):
+               self._connAction.conn[telepathy.server.CONNECTION].connect_to_signal(
+                       'StatusChanged',
+                       self._on_change,
+               )
+               self._connAction.conn[telepathy.server.CONNECTION].Connect(
+                       reply_handler = self._on_generic_message,
+                       error_handler = self._on_error,
+               )
+
+       def _on_done(self):
+               super(Connect, self)._on_done()
+
+       def _on_change(self, status, reason):
+               if status == telepathy.constants.CONNECTION_STATUS_DISCONNECTED:
+                       print "Disconnected!"
+                       self._conn = None
+               elif status == telepathy.constants.CONNECTION_STATUS_CONNECTED:
+                       print "Connected"
+                       self._on_done()
+               elif status == telepathy.constants.CONNECTION_STATUS_CONNECTING:
+                       print "Connecting"
+               else:
+                       print "Status: %r" % status
+
+
+class SimplePresenceOptions(Action):
+
+       def __init__(self, connAction):
+               super(SimplePresenceOptions, self).__init__()
+               self._connAction = connAction
+
+       def queue_action(self):
+               self._connAction.conn[DBUS_PROPERTIES].Get(
+                       telepathy.server.CONNECTION_INTERFACE_SIMPLE_PRESENCE,
+                       'Statuses',
+                       reply_handler = self._on_done,
+                       error_handler = self._on_error,
+               )
+
+       def _on_done(self, statuses):
+               print "\tAvailable Statuses"
+               for (key, value) in statuses.iteritems():
+                       print "\t\t - %s" % key
+               super(SimplePresenceOptions, self)._on_done()
+
+
+class NullHandle(object):
+
+       @property
+       def handle(self):
+               return 0
+
+       @property
+       def handles(self):
+               return []
+
+
+class UserHandle(Action):
+
+       def __init__(self, connAction):
+               super(UserHandle, self).__init__()
+               self._connAction = connAction
+               self._handle = None
+
+       @property
+       def handle(self):
+               return self._handle
+
+       @property
+       def handles(self):
+               return [self._handle]
+
+       def queue_action(self):
+               self._connAction.conn[telepathy.server.CONNECTION].GetSelfHandle(
+                       reply_handler = self._on_done,
+                       error_handler = self._on_error,
+               )
+
+       def _on_done(self, handle):
+               self._handle = handle
+               super(UserHandle, self)._on_done()
+
+
+class RequestHandle(Action):
+
+       def __init__(self, connAction, handleType, handleNames):
+               super(RequestHandle, self).__init__()
+               self._connAction = connAction
+               self._handle = None
+               self._handleType = handleType
+               self._handleNames = handleNames
+
+       @property
+       def handle(self):
+               return self._handle
+
+       @property
+       def handles(self):
+               return [self._handle]
+
+       def queue_action(self):
+               self._connAction.conn[telepathy.server.CONNECTION].RequestHandles(
+                       self._handleType,
+                       self._handleNames,
+                       reply_handler = self._on_done,
+                       error_handler = self._on_error,
+               )
+
+       def _on_done(self, handles):
+               self._handle = handles[0]
+               super(RequestHandle, self)._on_done()
+
+
+class RequestChannel(Action):
+
+       def __init__(self, connAction, handleAction, channelType, handleType):
+               super(RequestChannel, self).__init__()
+               self._connAction = connAction
+               self._handleAction = handleAction
+               self._channel = None
+               self._channelType = channelType
+               self._handleType = handleType
+
+       @property
+       def channel(self):
+               return self._channel
+
+       def queue_action(self):
+               self._connAction.conn[telepathy.server.CONNECTION].RequestChannel(
+                       self._channelType,
+                       self._handleType,
+                       self._handleAction.handle,
+                       True,
+                       reply_handler = self._on_done,
+                       error_handler = self._on_error,
+               )
+
+       def _on_done(self, channelObjectPath):
+               self._channel = telepathy.client.Channel(self._connAction.serviceName, channelObjectPath)
+               super(RequestChannel, self)._on_done()
+
+
+class EnsureChannel(Action):
+
+       def __init__(self, connAction, channelType, handleType, handleId):
+               super(EnsureChannel, self).__init__()
+               self._connAction = connAction
+               self._channel = None
+               self._channelType = channelType
+               self._handleType = handleType
+               self._handleId = handleId
+               self._handle = None
+
+       @property
+       def channel(self):
+               return self._channel
+
+       @property
+       def handle(self):
+               return self._handle
+
+       @property
+       def handles(self):
+               return [self._handle]
+
+       def queue_action(self):
+               properties = {
+                       telepathy.server.CHANNEL_INTERFACE+".ChannelType": self._channelType,
+                       telepathy.server.CHANNEL_INTERFACE+".TargetHandleType": self._handleType,
+                       telepathy.server.CHANNEL_INTERFACE+".TargetID": self._handleId,
+               }
+               self._connAction.conn[telepathy.server.CONNECTION_INTERFACE_REQUESTS].EnsureChannel(
+                       properties,
+                       reply_handler = self._on_done,
+                       error_handler = self._on_error,
+               )
+
+       def _on_done(self, yours, channelObjectPath, properties):
+               print "Create?", not not yours
+               print "Path:", channelObjectPath
+               print "Properties:", properties
+               self._channel = telepathy.client.Channel(self._connAction.serviceName, channelObjectPath)
+               self._handle = properties[telepathy.server.CHANNEL_INTERFACE+".TargetHandle"]
+               super(EnsureChannel, self)._on_done()
+
+
+class CloseChannel(Action):
+
+       def __init__(self, connAction, chanAction):
+               super(CloseChannel, self).__init__()
+               self._connAction = connAction
+               self._chanAction = chanAction
+               self._handles = []
+
+       def queue_action(self):
+               self._chanAction.channel[telepathy.server.CHANNEL].Close(
+                       reply_handler = self._on_done,
+                       error_handler = self._on_error,
+               )
+
+       def _on_done(self):
+               super(CloseChannel, self)._on_done()
+
+
+class ContactHandles(Action):
+
+       def __init__(self, connAction, chanAction):
+               super(ContactHandles, self).__init__()
+               self._connAction = connAction
+               self._chanAction = chanAction
+               self._handles = []
+
+       @property
+       def handles(self):
+               return self._handles
+
+       def queue_action(self):
+               self._chanAction.channel[DBUS_PROPERTIES].Get(
+                       telepathy.server.CHANNEL_INTERFACE_GROUP,
+                       'Members',
+                       reply_handler = self._on_done,
+                       error_handler = self._on_error,
+               )
+
+       def _on_done(self, handles):
+               self._handles = list(handles)
+               super(ContactHandles, self)._on_done()
+
+
+class SimplePresenceStatus(Action):
+
+       def __init__(self, connAction, handleAction):
+               super(SimplePresenceStatus, self).__init__()
+               self._connAction = connAction
+               self._handleAction = handleAction
+
+       def queue_action(self):
+               self._connAction.conn[telepathy.server.CONNECTION_INTERFACE_SIMPLE_PRESENCE].GetPresences(
+                       self._handleAction.handles,
+                       reply_handler = self._on_done,
+                       error_handler = self._on_error,
+               )
+
+       def _on_done(self, aliases):
+               print "\tPresences:"
+               for hid, (presenceType, presence, presenceMessage) in aliases.iteritems():
+                       print "\t\t%s:" % hid, presenceType, presence, presenceMessage
+               super(SimplePresenceStatus, self)._on_done()
+
+
+class SetSimplePresence(Action):
+
+       def __init__(self, connAction, status, message):
+               super(SetSimplePresence, self).__init__()
+               self._connAction = connAction
+               self._status = status
+               self._message = message
+
+       def queue_action(self):
+               self._connAction.conn[telepathy.server.CONNECTION_INTERFACE_SIMPLE_PRESENCE].SetPresence(
+                       self._status,
+                       self._message,
+                       reply_handler = self._on_done,
+                       error_handler = self._on_error,
+               )
+
+       def _on_done(self):
+               super(SetSimplePresence, self)._on_done()
+
+
+class Aliases(Action):
+
+       def __init__(self, connAction, handleAction):
+               super(Aliases, self).__init__()
+               self._connAction = connAction
+               self._handleAction = handleAction
+
+       def queue_action(self):
+               self._connAction.conn[telepathy.server.CONNECTION_INTERFACE_ALIASING].RequestAliases(
+                       self._handleAction.handles,
+                       reply_handler = self._on_done,
+                       error_handler = self._on_error,
+               )
+
+       def _on_done(self, aliases):
+               print "\tAliases:"
+               for h, alias in zip(self._handleAction.handles, aliases):
+                       print "\t\t", h, alias
+               super(Aliases, self)._on_done()
+
+
+class Call(Action):
+
+       def __init__(self, connAction, chanAction, handleAction):
+               super(Call, self).__init__()
+               self._connAction = connAction
+               self._chanAction = chanAction
+               self._handleAction = handleAction
+
+       def queue_action(self):
+               self._chanAction.channel[telepathy.server.CHANNEL_TYPE_STREAMED_MEDIA].RequestStreams(
+                       self._handleAction.handle,
+                       [telepathy.constants.MEDIA_STREAM_TYPE_AUDIO],
+                       reply_handler = self._on_done,
+                       error_handler = self._on_error,
+               )
+
+       def _on_done(self, handle):
+               print "Call started"
+               super(Call, self)._on_done()
+
+
+class SendText(Action):
+
+       def __init__(self, connAction, chanAction, handleAction, messageType, message):
+               super(SendText, self).__init__()
+               self._connAction = connAction
+               self._chanAction = chanAction
+               self._handleAction = handleAction
+               self._messageType = messageType
+               self._message = message
+
+       def queue_action(self):
+               self._chanAction.channel[telepathy.server.CHANNEL_TYPE_TEXT].Send(
+                       self._messageType,
+                       self._message,
+                       reply_handler = self._on_done,
+                       error_handler = self._on_error,
+               )
+
+       def _on_done(self,):
+               print "Message sent"
+               super(SendText, self)._on_done()
+
+
+class Sleep(Action):
+
+       def __init__(self, length):
+               super(Sleep, self).__init__()
+               self._length = length
+
+       def queue_action(self):
+               gobject.timeout_add(self._length, self._on_done)
+
+
+class Block(Action):
+
+       def __init__(self):
+               super(Block, self).__init__()
+
+       def queue_action(self):
+               print "Blocking"
+
+       def _on_done(self):
+               #super(SendText, self)._on_done()
+               pass
+
+
+class Disconnect(Action):
+
+       def __init__(self, connAction):
+               super(Disconnect, self).__init__()
+               self._connAction = connAction
+
+       def queue_action(self):
+               self._connAction.conn[telepathy.server.CONNECTION].Disconnect(
+                       reply_handler = self._on_done,
+                       error_handler = self._on_error,
+               )
+
+
+if __name__ == '__main__':
+       loop = gobject.MainLoop()
+
+       reg = get_registry()
+       cm = get_connection_manager(reg)
+
+       nullHandle = NullHandle()
+
+       dummy = DummyAction()
+       firstAction = dummy
+       lastAction = dummy
+
+       if True:
+               dp = DisplayParams(cm)
+               lastAction.append_action(dp)
+               lastAction = lastAction.get_next_action()
+
+       if True:
+               username = sys.argv[1]
+               password = sys.argv[2]
+               forward = sys.argv[3]
+               reqcon = RequestConnection(cm, username, password, forward)
+               lastAction.append_action(reqcon)
+               lastAction = lastAction.get_next_action()
+
+               if False:
+                       reqcon = RequestConnection(cm, username, password, forward)
+                       lastAction.append_action(reqcon)
+                       lastAction = lastAction.get_next_action()
+
+               con = Connect(reqcon)
+               lastAction.append_action(con)
+               lastAction = lastAction.get_next_action()
+
+               if True:
+                       spo = SimplePresenceOptions(reqcon)
+                       lastAction.append_action(spo)
+                       lastAction = lastAction.get_next_action()
+
+               if True:
+                       uh = UserHandle(reqcon)
+                       lastAction.append_action(uh)
+                       lastAction = lastAction.get_next_action()
+
+                       ua = Aliases(reqcon, uh)
+                       lastAction.append_action(ua)
+                       lastAction = lastAction.get_next_action()
+
+                       sps = SimplePresenceStatus(reqcon, uh)
+                       lastAction.append_action(sps)
+                       lastAction = lastAction.get_next_action()
+
+                       if False:
+                               setdnd = SetSimplePresence(reqcon, "dnd", "")
+                               lastAction.append_action(setdnd)
+                               lastAction = lastAction.get_next_action()
+
+                               sps = SimplePresenceStatus(reqcon, uh)
+                               lastAction.append_action(sps)
+                               lastAction = lastAction.get_next_action()
+
+                               setdnd = SetSimplePresence(reqcon, "available", "")
+                               lastAction.append_action(setdnd)
+                               lastAction = lastAction.get_next_action()
+
+                               sps = SimplePresenceStatus(reqcon, uh)
+                               lastAction.append_action(sps)
+                               lastAction = lastAction.get_next_action()
+
+               if False:
+                       sl = Sleep(10 * 1000)
+                       lastAction.append_action(sl)
+                       lastAction = lastAction.get_next_action()
+
+               if False:
+                       rclh = RequestHandle(reqcon, telepathy.HANDLE_TYPE_LIST, ["subscribe"])
+                       lastAction.append_action(rclh)
+                       lastAction = lastAction.get_next_action()
+
+                       rclc = RequestChannel(
+                               reqcon,
+                               rclh,
+                               telepathy.CHANNEL_TYPE_CONTACT_LIST,
+                               telepathy.HANDLE_TYPE_LIST,
+                       )
+                       lastAction.append_action(rclc)
+                       lastAction = lastAction.get_next_action()
+
+                       ch = ContactHandles(reqcon, rclc)
+                       lastAction.append_action(ch)
+                       lastAction = lastAction.get_next_action()
+
+                       ca = Aliases(reqcon, ch)
+                       lastAction.append_action(ca)
+                       lastAction = lastAction.get_next_action()
+
+               if True:
+                       accountNumber = sys.argv[4]
+                       enChan = EnsureChannel(reqcon, telepathy.CHANNEL_TYPE_TEXT, telepathy.HANDLE_TYPE_CONTACT, accountNumber)
+                       lastAction.append_action(enChan)
+                       lastAction = lastAction.get_next_action()
+
+                       sendDebugtext = SendText(reqcon, enChan, enChan, telepathy.CHANNEL_TEXT_MESSAGE_TYPE_NORMAL, "Boo!")
+                       lastAction.append_action(sendDebugtext)
+                       lastAction = lastAction.get_next_action()
+
+               if False:
+                       rch = RequestHandle(reqcon, telepathy.HANDLE_TYPE_CONTACT, ["18005558355"]) #(1-800-555-TELL)
+                       lastAction.append_action(rch)
+                       lastAction = lastAction.get_next_action()
+
+                       # making a phone call
+                       if True:
+                               smHandle = rch
+                               smHandleType = telepathy.HANDLE_TYPE_CONTACT
+                       else:
+                               smHandle = nullHandle
+                               smHandleType = telepathy.HANDLE_TYPE_NONE
+                       rsmc = RequestChannel(
+                               reqcon,
+                               smHandle,
+                               telepathy.CHANNEL_TYPE_STREAMED_MEDIA,
+                               smHandleType,
+                       )
+                       lastAction.append_action(rsmc)
+                       lastAction = lastAction.get_next_action()
+
+                       if False:
+                               call = Call(reqcon, rsmc, rch)
+                               lastAction.append_action(call)
+                               lastAction = lastAction.get_next_action()
+
+                       # sending a text
+                       rtc = RequestChannel(
+                               reqcon,
+                               rch,
+                               telepathy.CHANNEL_TYPE_TEXT,
+                               smHandleType,
+                       )
+                       lastAction.append_action(rtc)
+                       lastAction = lastAction.get_next_action()
+
+                       if True:
+                               closechan = CloseChannel(reqcon, rtc)
+                               lastAction.append_action(closechan)
+                               lastAction = lastAction.get_next_action()
+
+                               rtc = RequestChannel(
+                                       reqcon,
+                                       rch,
+                                       telepathy.CHANNEL_TYPE_TEXT,
+                                       smHandleType,
+                               )
+                               lastAction.append_action(rtc)
+                               lastAction = lastAction.get_next_action()
+
+                       if False:
+                               sendtext = SendText(reqcon, rtc, rch, telepathy.CHANNEL_TEXT_MESSAGE_TYPE_NORMAL, "Boo!")
+                               lastAction.append_action(sendtext)
+                               lastAction = lastAction.get_next_action()
+
+               if False:
+                       bl = Block()
+                       lastAction.append_action(bl)
+                       lastAction = lastAction.get_next_action()
+
+               if False:
+                       sl = Sleep(30 * 1000)
+                       lastAction.append_action(sl)
+                       lastAction = lastAction.get_next_action()
+
+               dis = Disconnect(reqcon)
+               lastAction.append_action(dis)
+               lastAction = lastAction.get_next_action()
+
+       quitter = QuitLoop(loop)
+       lastAction.append_action(quitter)
+       lastAction = lastAction.get_next_action()
+
+       firstAction.queue_action()
+       loop.run()
diff --git a/hand_tests/tp_params.py b/hand_tests/tp_params.py
new file mode 100755 (executable)
index 0000000..c3906ea
--- /dev/null
@@ -0,0 +1,46 @@
+#!/usr/bin/env python
+
+import gobject
+import dbus.mainloop.glib
+dbus.mainloop.glib.DBusGMainLoop(set_as_default = True)
+
+import telepathy
+from telepathy.interfaces import CONN_MGR_INTERFACE
+from telepathy.constants import CONN_MGR_PARAM_FLAG_DBUS_PROPERTY, \
+                                                               CONN_MGR_PARAM_FLAG_HAS_DEFAULT, \
+                                                               CONN_MGR_PARAM_FLAG_REGISTER, \
+                                                               CONN_MGR_PARAM_FLAG_REQUIRED, \
+                                                               CONN_MGR_PARAM_FLAG_SECRET
+
+def print_params (params):
+       for name, flags, signature, default in params:
+               print "%s (%s)" % (name, signature),
+
+               if flags & CONN_MGR_PARAM_FLAG_REQUIRED: print "required",
+               if flags & CONN_MGR_PARAM_FLAG_REGISTER: print "register",
+               if flags & CONN_MGR_PARAM_FLAG_SECRET: print "secret",
+               if flags & CONN_MGR_PARAM_FLAG_DBUS_PROPERTY: print "dbus-property",
+               if flags & CONN_MGR_PARAM_FLAG_HAS_DEFAULT: print "has-default(%s)" % default,
+
+               print ""
+
+       loop.quit ()
+
+def error_cb (*args):
+       print "Error:", args
+       loop.quit ()
+
+
+if __name__ == "__main__":
+       reg = telepathy.client.ManagerRegistry()
+       reg.LoadManagers()
+
+       # get the gabble Connection Manager
+       cm = reg.GetManager('theonering')
+
+       # get the parameters required to make a Jabber connection
+       cm[CONN_MGR_INTERFACE].GetParameters('gv',
+               reply_handler = print_params, error_handler = error_cb)
+
+       loop = gobject.MainLoop()
+       loop.run()
diff --git a/hand_tests/tp_presence.py b/hand_tests/tp_presence.py
new file mode 100755 (executable)
index 0000000..52b6c9f
--- /dev/null
@@ -0,0 +1,250 @@
+#!/usr/bin/env python
+
+import sys
+
+import gobject
+# Begin Example 2-1
+import dbus.mainloop.glib
+dbus.mainloop.glib.DBusGMainLoop(set_as_default = True)
+# End Example 2-1
+
+import telepathy
+import telepathy.client
+from telepathy.interfaces import CONNECTION_MANAGER, \
+                                                                CONNECTION, \
+                                                                CONNECTION_INTERFACE_REQUESTS, \
+                                                                CONNECTION_INTERFACE_ALIASING, \
+                                                                CONNECTION_INTERFACE_SIMPLE_PRESENCE, \
+                                                                CONNECTION_INTERFACE_CONTACTS, \
+                                                                CHANNEL, \
+                                                                CHANNEL_TYPE_CONTACT_LIST, \
+                                                                CHANNEL_INTERFACE_GROUP
+from telepathy.constants import CONNECTION_STATUS_CONNECTED, \
+                                                               CONNECTION_STATUS_DISCONNECTED, \
+                                                               HANDLE_TYPE_LIST, \
+                                                               HANDLE_TYPE_GROUP
+
+DBUS_PROPERTIES = 'org.freedesktop.DBus.Properties'
+
+
+class Example(object):
+
+       def __init__ (self, account, password, forward):
+               """e.g. account  = 'bob@example.com/test'
+                               password = 'bigbob'
+               """
+               self.conn = None
+
+               reg = telepathy.client.ManagerRegistry()
+               reg.LoadManagers()
+
+               # get the gabble Connection Manager
+               self.cm = cm = reg.GetManager('theonering')
+
+               # get the parameters required to make a Jabber connection
+               # Begin Example 2-3
+               cm[CONNECTION_MANAGER].RequestConnection('gv',
+                       {
+                               'account':  account,
+                               'forward':  forward,
+                               'password': password,
+                       },
+                       reply_handler = self.request_connection_cb,
+                       error_handler = self.error_cb)
+               # End Example 2-3
+
+       def run(self):
+               self.loop = gobject.MainLoop()
+               try:
+                       self.loop.run()
+               except KeyboardInterrupt:
+                       print "Terminating connection..."
+                       self.disconnect()
+                       # reengage the mainloop so that we can disconnect cleanly
+                       self.loop.run()
+
+       def generic_reply (self, *args): pass
+
+       def error_cb (self, error):
+               print "Error:", error
+               self.disconnect()
+
+       def disconnect (self):
+               if self.conn is None:
+                       return
+               self.conn[CONNECTION].Disconnect(reply_handler = self.generic_reply,
+                                                                                error_handler = self.error_cb)
+
+       # Begin Example 2-4
+       def request_connection_cb (self, bus_name, object_path):
+               print bus_name, object_path
+               # End Example 2-4
+               self.conn = conn = telepathy.client.Connection(bus_name, object_path)
+
+               conn[CONNECTION].connect_to_signal('StatusChanged',
+                       self.status_changed_cb)
+
+               print "Establishing connection..."
+               conn[CONNECTION].Connect(reply_handler = self.generic_reply,
+                                                                error_handler = self.error_cb)
+
+       def status_changed_cb (self, status, reason):
+               conn = self.conn
+
+               if status == CONNECTION_STATUS_DISCONNECTED:
+                       print "Disconnected!"
+                       self.loop.quit()
+
+               if status != CONNECTION_STATUS_CONNECTED: return
+
+               print 'Carrier Detected' # remember dialup modems?
+               print 'Ctrl-C to disconnect'
+
+               # get a list of interfaces on this connection
+               conn[CONNECTION].GetInterfaces(reply_handler = self.get_interfaces_cb,
+                                                                          error_handler = self.error_cb)
+
+       def request_contact_list (self, *groups):
+               conn = self.conn
+
+               class ensure_channel_cb (object):
+                       def __init__ (self, parent, group):
+                               self.parent = parent
+                               self.group = group
+
+                       def __call__ (self, yours, path, properties):
+                               print "got channel for %s -> %s, yours = %s" % (
+                                       self.group, path, yours)
+
+                               channel = telepathy.client.Channel(conn.service_name, path)
+                               self.channel = channel
+
+                               # Begin Example 6-8
+                               # request the list of members
+                               channel[DBUS_PROPERTIES].Get(CHANNEL_INTERFACE_GROUP,
+                                                                                'Members',
+                                                                                reply_handler = self.members_cb,
+                                                                                error_handler = self.parent.error_cb)
+
+                       def members_cb (self, handles):
+                               # request information for this list of handles using the
+                               # Contacts interface
+                               conn[CONNECTION_INTERFACE_CONTACTS].GetContactAttributes(
+                                       handles, [
+                                               CONNECTION,
+                                               CONNECTION_INTERFACE_ALIASING,
+                                               CONNECTION_INTERFACE_SIMPLE_PRESENCE,
+                                       ],
+                                       False,
+                                       reply_handler = self.get_contact_attributes_cb,
+                                       error_handler = self.parent.error_cb)
+                               # End Example 6-8
+
+                       def get_contact_attributes_cb (self, attributes):
+                               return # DEBUG
+
+                               print '-' * 78
+                               print self.group
+                               print '-' * 78
+                               for member in attributes.values():
+                                       for key, value in member.iteritems():
+                                               print '%s: %s' % (key, value)
+                                       print
+                               print '-' * 78
+
+               def no_channel_available (error):
+                       print error
+
+               # we can either use TargetID if we know a name, or TargetHandle
+               # if we already have a handle
+               for group in groups:
+                       # Begin Example 6-6
+                       print "Ensuring channel to %s..." % group
+                       conn[CONNECTION_INTERFACE_REQUESTS].EnsureChannel({
+                               CHANNEL + '.ChannelType'         : CHANNEL_TYPE_CONTACT_LIST,
+                               CHANNEL + '.TargetHandleType': HANDLE_TYPE_LIST,
+                               CHANNEL + '.TargetID'           : group,
+                               },
+                               reply_handler = ensure_channel_cb(self, group),
+                               error_handler = no_channel_available)
+                       # End Example 6-6
+
+       def get_interfaces_cb (self, interfaces):
+               conn = self.conn
+
+               print "Interfaces:"
+               for interface in interfaces:
+                       print " - %s" % interface
+
+               if CONNECTION_INTERFACE_REQUESTS in interfaces:
+                       self.request_contact_list('subscribe',
+                                                                         'publish',
+                                                                         'hide',
+                                                                         'allow',
+                                                                         'deny',
+                                                                         'known')
+
+                       # get the open channelsA
+                       # Begin Example 2-6
+                       conn[CONNECTION_INTERFACE_REQUESTS].connect_to_signal(
+                                                                       'NewChannels',
+                                                                       self.get_channels_cb)
+                       # End Example 2-6
+                       # Begin Example 2-5
+                       conn[DBUS_PROPERTIES].Get(CONNECTION_INTERFACE_REQUESTS,
+                                                                       'Channels',
+                                                                       reply_handler = self.get_channels_cb,
+                                                                       error_handler = self.error_cb)
+                       # End Example 2-5
+
+               if CONNECTION_INTERFACE_SIMPLE_PRESENCE in interfaces:
+                       # Begin Example 5-4
+                       # request the statuses
+                       print 'Requesting statuses...'
+                       conn[DBUS_PROPERTIES].Get(CONNECTION_INTERFACE_SIMPLE_PRESENCE,
+                                                                       'Statuses',
+                                                                       reply_handler = self.get_statuses_cb,
+                                                                       error_handler = self.error_cb)
+
+                       # set our presence
+                       #print 'Setting presence...'
+                       #conn[CONNECTION_INTERFACE_SIMPLE_PRESENCE].SetPresence(
+                       #                                               'away',
+                       #                                               'At the Movies',
+                       #                                               reply_handler = self.generic_reply,
+                       #                                               error_handler = self.error_cb)
+                       # End Example 5-4
+
+               if CONNECTION_INTERFACE_CONTACTS in interfaces:
+                       print 'Requesting contact attribute interfaces...'
+                       conn[DBUS_PROPERTIES].Get(CONNECTION_INTERFACE_CONTACTS,
+                                                                       'ContactAttributeInterfaces',
+                                                                       reply_handler = self.get_contact_ifaces_cb,
+                                                                       error_handler = self.error_cb)
+
+       def get_channels_cb (self, channels):
+               for channel, props in channels:
+                       # find the group channels
+                       if props[CHANNEL + '.ChannelType'] != CHANNEL_TYPE_CONTACT_LIST or \
+                          props[CHANNEL + '.TargetHandleType'] != HANDLE_TYPE_GROUP:
+                               continue
+
+                       print 'GROUP: Got channel %s: %s' % (channel, props[CHANNEL + '.TargetID'])
+
+       def get_statuses_cb (self, value):
+               print "Statuses:"
+
+               for (key, value) in value.iteritems():
+                       print " - %s" % key
+
+       def get_contact_ifaces_cb (self, interfaces):
+               print "Contact Attribute Interfaces:"
+               for interface in interfaces:
+                       print " - %s" % interface
+
+if __name__ == '__main__':
+       username = sys.argv[1]
+       password = sys.argv[2]
+       forward = sys.argv[3]
+       e = Example(username, password, forward)
+       e.run()