<commit_before>##
## Will hopefully be refactored soon
##

import sys
import dbus.glib
import logging
import telepathy

import IMDemo
import ContactList
import IMSession
import Settings
import AccountRegister

import time
from telepathy.client.channel import Channel
from telepathy.interfaces import CONN_MGR_INTERFACE, CONN_INTERFACE_PRESENCE, CONNECTION_INTERFACE_SIMPLE_PRESENCE, CHANNEL
from telepathy.interfaces import CHANNEL_TYPE_TEXT, CONN_INTERFACE, CHANNEL_INTERFACE_GROUP, CHANNEL_TYPE_CONTACT_LIST
from telepathy.constants import (
    CONNECTION_HANDLE_TYPE_CONTACT, CONNECTION_STATUS_CONNECTED,
    CHANNEL_TEXT_MESSAGE_TYPE_NORMAL, CONNECTION_STATUS_DISCONNECTED, CONNECTION_HANDLE_TYPE_LIST)

from threading import Thread
from Queue import Queue
import traceback


class Connection():
    
    def __init__(self, app):
        self.manager_file = "gabble.manager"
        self.manager = "gabble"
        self.protocol = "jabber"
        self.conn = None
        self.cb_app = app
        self.contactlist = ContactList.ContactList(None, app)
        self.chat_address = None
        self.textchannel = None
        self.contactlistInit = False
        self.current_precenses = None        
        self.precenseCallBackSet = False

        #contact list subscribed status map
        self.presence = {}
        self.requested_contacts = {}
        self.requested_contacts_phase_map = {} # need to be aware of number of added messages
        self.sessions = {} # map of IM sessions (address & IMSession class)
        self.settings = Settings.Settings()
        self.register = AccountRegister.AccountRegister(app)

        
    def _getRequestedContact(self, h):
        if (self.requested_contacts.__contains__(h)==True):
            return self.requested_contacts[h]
        else:
            return "None contact"

        
##====================================================
##    CONNECTING
##====================================================
    def ConnectAccount(self, d):
        self.account = d["account"]
        self.password = d["password"]
        self.server = d["server"]
        self.port = d["port"]
        self.old_ssl = d["old-ssl"]
        self.ignore_ssl_errors = d["ignore-ssl-errors"]
        self.manager = d["manager"]
        self.protocol = d["protocol"]
        del d["manager"]
        del d["protocol"]
        
        reg = telepathy.client.ManagerRegistry()
        reg.LoadManager(self.manager_file)
        mgr = reg.GetManager(self.manager)
        
        p = d["port"]
        p0 = dbus.UInt32(int(p))
        d["port"] = p0

        conn_bus_name, conn_object_path = mgr[CONN_MGR_INTERFACE].RequestConnection(self.protocol, d)
        
        self.conn = telepathy.client.Connection(conn_bus_name, conn_object_path, ready_handler=None)<commit_msg>fix comm crash when doesn't find dbus daemon <commit_after>##
## Will hopefully be refactored soon
##

import sys
import dbus.glib
import logging
import telepathy

import IMDemo
import ContactList
import IMSession
import Settings
import AccountRegister

import time
from telepathy.client.channel import Channel
from telepathy.interfaces import CONN_MGR_INTERFACE, CONN_INTERFACE_PRESENCE, CONNECTION_INTERFACE_SIMPLE_PRESENCE, CHANNEL
from telepathy.interfaces import CHANNEL_TYPE_TEXT, CONN_INTERFACE, CHANNEL_INTERFACE_GROUP, CHANNEL_TYPE_CONTACT_LIST
from telepathy.constants import (
    CONNECTION_HANDLE_TYPE_CONTACT, CONNECTION_STATUS_CONNECTED,
    CHANNEL_TEXT_MESSAGE_TYPE_NORMAL, CONNECTION_STATUS_DISCONNECTED, CONNECTION_HANDLE_TYPE_LIST)

from threading import Thread
from Queue import Queue
import traceback


class Connection():
    
    def __init__(self, app):
        self.manager_file = "gabble.manager"
        self.manager = "gabble"
        self.protocol = "jabber"
        self.conn = None
        self.cb_app = app
        self.contactlist = ContactList.ContactList(None, app)
        self.chat_address = None
        self.textchannel = None
        self.contactlistInit = False
        self.current_precenses = None        
        self.precenseCallBackSet = False

        #contact list subscribed status map
        self.presence = {}
        self.requested_contacts = {}
        self.requested_contacts_phase_map = {} # need to be aware of number of added messages
        self.sessions = {} # map of IM sessions (address & IMSession class)
        self.settings = Settings.Settings()
        self.register = AccountRegister.AccountRegister(app)

        
    def _getRequestedContact(self, h):
        if (self.requested_contacts.__contains__(h)==True):
            return self.requested_contacts[h]
        else:
            return "None contact"

        
##====================================================
##    CONNECTING
##====================================================
    def ConnectAccount(self, d):
        self.account = d["account"]
        self.password = d["password"]
        self.server = d["server"]
        self.port = d["port"]
        self.old_ssl = d["old-ssl"]
        self.ignore_ssl_errors = d["ignore-ssl-errors"]
        self.manager = d["manager"]
        self.protocol = d["protocol"]
        del d["manager"]
        del d["protocol"]
        
        reg = telepathy.client.ManagerRegistry()
        reg.LoadManager(self.manager_file)
        try:
            mgr = reg.GetManager(self.manager)
        except dbus.exceptions.DBusException, e:
            print("ERROR: Cannot find dbus daemon!")
            print(e)
            return
        
        p = d["port"]
        p0 = dbus.UInt32(int(p))
        d["port"] = p0

        conn_bus_name, conn_object_path = mgr[CONN_MGR_INTERFACE].RequestConnection(self.protocol, d)
        
        self.conn = telepathy.client.Connection(conn_bus_name, conn_object_path, ready_handler=None)
{'fraction_non_alphanumeric': 0.11892077676576732, 'fraction_numerical': 0.001374806667812339, 'mean_word_length': 2.9972527472527473, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6426727', 'n_tokens_mistral': 1699, 'n_tokens_neox': 1649, 'n_words': 365}