<commit_before>import dbus.glib
import gobject
import logging
import sys

from time import sleep

from account import connection_from_file

from telepathy.client.channel import Channel
from telepathy.constants import (
    CONNECTION_HANDLE_TYPE_NONE as HANDLE_TYPE_NONE,
    CONNECTION_HANDLE_TYPE_ROOM as HANDLE_TYPE_ROOM,
    CONNECTION_STATUS_CONNECTED,
    CHANNEL_TEXT_MESSAGE_TYPE_NORMAL)
from telepathy.interfaces import CHANNEL_TYPE_ROOM_LIST, CONN_INTERFACE

logging.basicConfig()

class RoomListChannel(Channel):
    def __init__(self, *stuff):
        Channel.__init__(self, *stuff)
        self.get_valid_interfaces().add(CHANNEL_TYPE_ROOM_LIST)

class RoomListExample:
    def __init__(self, conn):
        self.conn = conn

        conn[CONN_INTERFACE].connect_to_signal('StatusChanged',
            self.status_changed_cb)
        conn[CONN_INTERFACE].connect_to_signal('NewChannel',
            self.new_channel_cb)

    def run(self):
        print "main loop running"
        self.loop = gobject.MainLoop()
        self.loop.run()

    def quit(self):
        if self.loop:
            self.loop.quit()
            self.loop = None

    def status_changed_cb(self, state, reason):
        if state != CONNECTION_STATUS_CONNECTED:
            return
        print "connection became ready, requesting channel"

        try:
            conn[CONN_INTERFACE].RequestChannel(
                CHANNEL_TYPE_ROOM_LIST, HANDLE_TYPE_NONE, 0, True,
                reply_handler=self.request_channel_cb,
                error_handler=self.request_channel_error_cb)
        except Exception, e:
            print e
            self.quit()

    def request_channel_error_cb(self, exception):
        print 'error returned by RequestChannel:', exception
        self.quit()

    def new_channel_cb(self, object_path, channel_type, handle_type, handle,
            suppress_handler):
        if channel_type != CHANNEL_TYPE_ROOM_LIST:
            return

        print 'New room-list channel created'

    def request_channel_cb(self, object_path):
        print "Got requested channel:", object_path

        channel = RoomListChannel(self.conn.service_name, object_path)

        print "Connecting to ListingRooms"
        channel[CHANNEL_TYPE_ROOM_LIST].connect_to_signal('ListingRooms',
                                                         self.listing_cb)
        print "Connecting to GotRooms"
        channel[CHANNEL_TYPE_ROOM_LIST].connect_to_signal('GotRooms',
                                                         self.rooms_cb)
        print "Calling ListRooms"
        channel[CHANNEL_TYPE_ROOM_LIST].ListRooms()

    def listing_cb(self, listing):<commit_msg>examples/roomlist.py: use request_channel<commit_after>import dbus.glib
import gobject
import logging
import sys

from time import sleep

from account import connection_from_file

from telepathy.client.channel import Channel
from telepathy.constants import (
    CONNECTION_HANDLE_TYPE_NONE as HANDLE_TYPE_NONE,
    CONNECTION_HANDLE_TYPE_ROOM as HANDLE_TYPE_ROOM,
    CONNECTION_STATUS_CONNECTED,
    CHANNEL_TEXT_MESSAGE_TYPE_NORMAL)
from telepathy.interfaces import CHANNEL_TYPE_ROOM_LIST, CONN_INTERFACE

logging.basicConfig()

class RoomListExample:
    def __init__(self, conn):
        self.conn = conn

        conn[CONN_INTERFACE].connect_to_signal('StatusChanged',
            self.status_changed_cb)

    def run(self):
        print "main loop running"
        self.loop = gobject.MainLoop()
        self.loop.run()

    def quit(self):
        if self.loop:
            self.loop.quit()
            self.loop = None

    def status_changed_cb(self, state, reason):
        if state != CONNECTION_STATUS_CONNECTED:
            return
        print "connection became ready, requesting channel"

        try:
            channel = conn.request_channel(
                CHANNEL_TYPE_ROOM_LIST, HANDLE_TYPE_NONE, 0, True)
        except Exception, e:
            print e
            self.quit()
            return

        print "Connecting to ListingRooms"
        channel[CHANNEL_TYPE_ROOM_LIST].connect_to_signal('ListingRooms',
                                                         self.listing_cb)
        print "Connecting to GotRooms"
        channel[CHANNEL_TYPE_ROOM_LIST].connect_to_signal('GotRooms',
                                                         self.rooms_cb)
        print "Calling ListRooms"
        channel[CHANNEL_TYPE_ROOM_LIST].ListRooms()

    def listing_cb(self, listing):
{'fraction_non_alphanumeric': 0.06820706509664519, 'fraction_numerical': 0.00044434570095534326, 'mean_word_length': 2.479134466769706, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '877836', 'n_tokens_mistral': 1301, 'n_tokens_neox': 1244, 'n_words': 266}