<commit_before>import gobject
import xmlrpclib
from discovery import ServiceBrowser
from util import getWizUrl
from xmlrpcdeferred import GXMLRPCTransport
from server import find_running_server_by_name

class SharesDatabase(gobject.GObject):
    def __init__(self):
        self.sb = ServiceBrowser("_wizbit._tcp")
        self.sb.connect ( "service-found", self._service_found)
        self.sb.connect ( "service-removed", self._service_removed)

        self.shares = {}
        self.names = {}

    def _update_shares (self, shares, name, interface, address, port, dir):
        for dirId, shareId, dir in shares:
            if shareId not in self.shares:
                self.shares[shareId] = {}
            self.shares[shareId][dirId] = (interface, address, port, dir)
            if name not in self.names:
                self.names[name] = []
            self.names[name].append((shareId,dirId))


    def _get_shares_done(self, deferred, name, interface, address, port, dir):
        self._update_shares(deferred.value, name, interface, address, port, dir)

    def _service_found(self, object, name, type, interface, host, address, port):
        print "service found",name, type, interface, host, address, port;
        #see if this service is local to our process, if so dont xmlrpc!
        server = find_running_server_by_name (name)
        if server:
            shares = server.instance.getShares()
            self._update_shares(shares, name, interface, address,port,dir)
        else:
            t = GXMLRPCTransport()
            srcUrl = getWizUrl(address, port)
            server = xmlrpclib.ServerProxy(srcUrl, t)
            shares = server.getShares()
            shares.connect('ready', self._get_shares_done, name, interface, address, port, dir);

    def _service_removed(self, widget, name):
        for shrId, dirId in self.names[name]:
            del self.shares[shrId][dirId]
            if self.shares[shrId] == {}:
                    del self.shares[shrId]
<commit_msg>deferred.value is a tuple of return values, so extract the first one<commit_after>import gobject
import xmlrpclib
from discovery import ServiceBrowser
from util import getWizUrl
from xmlrpcdeferred import GXMLRPCTransport
from server import find_running_server_by_name

class SharesDatabase(gobject.GObject):
    def __init__(self):
        self.sb = ServiceBrowser("_wizbit._tcp")
        self.sb.connect ( "service-found", self._service_found)
        self.sb.connect ( "service-removed", self._service_removed)

        self.shares = {}
        self.names = {}

    def _update_shares (self, shares, name, interface, address, port, dir):
        for dirId, shareId, dir in shares:
            if shareId not in self.shares:
                self.shares[shareId] = {}
            self.shares[shareId][dirId] = (interface, address, port, dir)
            if name not in self.names:
                self.names[name] = []
            self.names[name].append((shareId,dirId))


    def _get_shares_done(self, deferred, name, interface, address, port, dir):
        self._update_shares(deferred.value[0], name, interface, address, port, dir)

    def _service_found(self, object, name, type, interface, host, address, port):
        print "service found",name, type, interface, host, address, port;
        #see if this service is local to our process, if so dont xmlrpc!
        server = find_running_server_by_name (name)
        if server:
            shares = server.instance.getShares()
            self._update_shares(shares, name, interface, address,port,dir)
        else:
            t = GXMLRPCTransport()
            srcUrl = getWizUrl(address, port)
            server = xmlrpclib.ServerProxy(srcUrl, t)
            shares = server.getShares()
            shares.connect('ready', self._get_shares_done, name, interface, address, port, dir);

    def _service_removed(self, widget, name):
        for shrId, dirId in self.names[name]:
            del self.shares[shrId][dirId]
            if self.shares[shrId] == {}:
                    del self.shares[shrId]

{'fraction_non_alphanumeric': 0.10102991662579695, 'fraction_numerical': 0.0002452182442373713, 'mean_word_length': 2.6847335140018065, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 8}, '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': '3580515', 'n_tokens_mistral': 1216, 'n_tokens_neox': 1197, 'n_words': 321}