/usr/share/doc/python-telepathy/examples/chatroom.py is in python-telepathy 0.15.19-2.1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | """
Example Telepathy chatroom client.
"""
import sys
import dbus.glib
import gobject
import telepathy
from account import connection_from_file
class ChatroomClient:
def __init__(self, conn, chatroom):
self.conn = conn
self.chatroom = chatroom
conn[telepathy.CONN_INTERFACE].connect_to_signal('StatusChanged',
self.status_changed_cb)
def status_changed_cb(self, status, reason):
if status == telepathy.CONNECTION_STATUS_CONNECTED:
room_handle = self.conn[telepathy.CONN_INTERFACE].RequestHandles(
telepathy.HANDLE_TYPE_ROOM, [self.chatroom])[0]
channel = self.conn.request_channel(telepathy.CHANNEL_TYPE_TEXT,
telepathy.HANDLE_TYPE_ROOM, room_handle, True)
channel[telepathy.CHANNEL_TYPE_TEXT].connect_to_signal(
'Received', self.received_cb)
gobject.io_add_watch(sys.stdin, gobject.IO_IN, self.stdin_cb)
self.channel = channel
def received_cb(self, id, timestamp, sender, type, flags, text):
self.channel[telepathy.CHANNEL_TYPE_TEXT].AcknowledgePendingMessages(
[id])
contact = self.conn[telepathy.CONN_INTERFACE].InspectHandles(
telepathy.HANDLE_TYPE_CONTACT, [sender])[0]
print '<%s> %s' % (contact, text)
def stdin_cb(self, fd, condition):
text = fd.readline()[:-1]
self.channel[telepathy.CHANNEL_TYPE_TEXT].Send(
telepathy.CHANNEL_TEXT_MESSAGE_TYPE_NORMAL, text)
return True
if __name__ == '__main__':
account_file, chatroom = sys.argv[1], sys.argv[2]
conn = connection_from_file(account_file)
client = ChatroomClient(conn, chatroom)
conn[telepathy.CONN_INTERFACE].Connect()
loop = gobject.MainLoop()
try:
loop.run()
except KeyboardInterrupt:
print 'interrupted'
print 'disconnecting'
try:
conn[telepathy.CONN_INTERFACE].Disconnect()
except dbus.DBusException:
pass
|