<commit_before>try:
    import hashlib
    md5hash = hashlib.md5
except ImportError:
    import md5
    md5hash = md5.new
import time
from urllib import urlencode
from urllib2 import urlopen


class GobbleException(Exception):

    pass


class GobbleServer(object):

    def __init__(self, server_name, username, password):
        if server_name[:7] != "http://":
            server_name = "http://%s" % (server_name,)
        self.name = server_name
        self.password = password
        self.post_data = []
        self.session_id = None
        self.submit_url = None
        self.username = username
        self._handshake()


    def _handshake(self):
        timestamp = int(time.time())
        token = (md5hash(md5hash(self.password).hexdigest()
                    + str(timestamp)).hexdigest())
        auth_url = "%s/?hs=true&p=1.2&u=%s&t=%d&a=%s&c=imp" % (self.name,
                                                               self.username,
                                                               timestamp, token)
        response = urlopen(auth_url).read()
        lines = response.split("\n")
        if lines[0] != "OK":
            raise GobbleException("Server returned: %s" % (response,))
        self.session_id = lines[1]
        self.submit_url = lines[3]

    def submit(self):
        if len(self.post_data) == 0:
            return
        i = 0
        data = []
        for track in self.post_data:
            data += track.get_tuples(i)
            i += 1
        data += [('s', self.session_id)]
        response = urlopen(self.submit_url, urlencode(data)).read()
        if response != "OK\n":
            raise GobbleException("Server returned: %s" % (response,))
        self.post_data = []
        time.sleep(1)

    def add_track(self, gobble_track):
        i = len(self.post_data)<commit_msg>Client code can be customised.<commit_after>try:
    import hashlib
    md5hash = hashlib.md5
except ImportError:
    import md5
    md5hash = md5.new
import time
from urllib import urlencode
from urllib2 import urlopen


class GobbleException(Exception):

    pass


class GobbleServer(object):

    def __init__(self, server_name, username, password, client_code='imp'):
        if server_name[:7] != "http://":
            server_name = "http://%s" % (server_name,)
        self.client_code = client_code
        self.name = server_name
        self.password = password
        self.post_data = []
        self.session_id = None
        self.submit_url = None
        self.username = username
        self._handshake()


    def _handshake(self):
        timestamp = int(time.time())
        token = (md5hash(md5hash(self.password).hexdigest()
                    + str(timestamp)).hexdigest())
        auth_url = "%s/?hs=true&p=1.2&u=%s&t=%d&a=%s&c=%s" % (self.name,
                                                              self.username,
                                                              timestamp,
                                                              token,
                                                              self.client_code)
        response = urlopen(auth_url).read()
        lines = response.split("\n")
        if lines[0] != "OK":
            raise GobbleException("Server returned: %s" % (response,))
        self.session_id = lines[1]
        self.submit_url = lines[3]

    def submit(self):
        if len(self.post_data) == 0:
            return
        i = 0
        data = []
        for track in self.post_data:
            data += track.get_tuples(i)
            i += 1
        data += [('s', self.session_id)]
        response = urlopen(self.submit_url, urlencode(data)).read()
        if response != "OK\n":
            raise GobbleException("Server returned: %s" % (response,))
        self.post_data = []
        time.sleep(1)

    def add_track(self, gobble_track):
        i = len(self.post_data)
{'fraction_non_alphanumeric': 0.11827956989247312, 'fraction_numerical': 0.009216589861751152, 'mean_word_length': 1.67419575633128, 'pattern_counts': {'":': 6, '<': 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': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '462488', 'n_tokens_mistral': 1143, 'n_tokens_neox': 1101, 'n_words': 239}