<commit_before>from pydht import DHT
import sys
import os
import time
import cPickle as pickle

class ChordNode():
    """docstring for ChordNode"""
    def __init__(self, address, port, hostip):
        self.address = address
        self.port = port
        self.hostip = hostip

    def join(self):
        if self.address == self.hostip:
            print "Only node in group"
            try:
                print "Starting server"
                dht = DHT(self.hostip, self.port)
                dht['hi'] = ['hi2']
                print dht
                return dht
            except Exception, e:
                raise e

        else:
            print "Joining DHT group"
            try:
                print "Starting server"
                dht = DHT(self.hostip, self.port, boot_host=self.address, boot_port=self.port)
                return dht
            except Exception, e:
                print e

class ChordSetter():

    @staticmethod
    def getval(dht, key):
        print "Getting the host with key: " + key
        try:
            print dht
            k = pickle.dumps(key)

            value = dht[k][0]
            time.sleep(1)
            return pickle.loads(value)
        except Exception, e:
            print e

    @staticmethod
    def setval(dht, key, value):
        print "Setting the host with key: " + key + " and value: " + value
        try:
            print key
            print value
            print "Setting......"
            k = pickle.dumps(key)
            v - pickle.dumps(value)
            print k
            print v
            dht[k] = [v]
            print "If it was succesfull print this"
            time.sleep(2)
            print "Slept"
        except Exception, e:
            print e<commit_msg>jelte<commit_after>from pydht import DHT
import sys
import os
import time
import cPickle as pickle

class ChordNode():
    """docstring for ChordNode"""
    def __init__(self, address, port, hostip):
        self.address = address
        self.port = port
        self.hostip = hostip

    def join(self):
        if self.address == self.hostip:
            print "Only node in group"
            try:
                print "Starting server"
                dht = DHT(self.hostip, self.port)
                dht[u'hi'] = ['hi2']
                print dht
                return dht
            except Exception, e:
                raise e

        else:
            print "Joining DHT group"
            try:
                print "Starting server"
                dht = DHT(self.hostip, self.port, boot_host=self.address, boot_port=self.port)
                return dht
            except Exception, e:
                print e

class ChordSetter():

    @staticmethod
    def getval(dht, key):
        print "Getting the host with key: " + key
        try:
            print dht
            k = pickle.dumps(key)

            value = dht[k][0]
            time.sleep(1)
            return pickle.loads(value)
        except Exception, e:
            print e

    @staticmethod
    def setval(dht, key, value):
        print "Setting the host with key: " + key + " and value: " + value
        try:
            print key
            print value
            print "Setting......"
            dht[key] = [value]
            print "If it was succesfull print this"
            time.sleep(2)
            print dht[key]
            print "Slept"
        except Exception, e:
            print e
{'fraction_non_alphanumeric': 0.08492201039861352, 'fraction_numerical': 0.002310803004043905, 'mean_word_length': 1.3241610738255034, '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': '2413549', 'n_tokens_mistral': 998, 'n_tokens_neox': 957, 'n_words': 301}