<commit_before>import socket
import threading

class MalformedResponseError(Exception):
    pass

class StreamClient:
    def __init__(self, host, port, timeout=0.1, debug=False):
        self.timeout = timeout
        self.sock = socket.socket(type=socket.SOCK_DGRAM)
        self.sock.settimeout(self.timeout)
        self.hostaddr = (socket.gethostbyname(host), port)
        self.streaming = False
        self.callbackMap = {}
        self.tseq = 1
        
        self.sent = 0
        self.send_failed = 0
        self.received = 0
        self.delivered = 0
        self.missing = 0
        self.ooo = 0

        if debug:
            self.st = threading.Timer(1,self.stats)
            self.st.start()
        else:
            self.st = None

    def stats(self):
        print("sent: %i send-failed: %i received: %i delivered: %i missing: %i out-of-order: %i" % (self.sent, self.send_failed, self.received, self.delivered, self.missing, self.ooo))
        self.sent = 0
        self.send_failed = 0
        self.received = 0
        self.delivered = 0
        self.missing = 0
        self.ooo = 0
        self.st = threading.Timer(1,self.stats)
        self.st.start()

    def stop(self):
        if self.st:
            self.st.cancel()

    def get(self, key, blocking=False):
        reqdata = 'GET ' + key + '\r\n'
        self.transmit(reqdata)
        
        if blocking:
            self.sock.settimeout(None)

        data,addr = self.sock.recvfrom(65536)

        if blocking:
            self.sock.settimeout(self.timeout)

        return data.split('\r\n', 1)[1][:-2]

    def set(self, key, value):
        data = 'SET ' + key + ' ' + str(self.tseq) + ' ' + str(len(value)) + '\r\n' + str(value) + '\r\n'
        self.tseq += 1
        self.transmit(data)
<commit_msg>have to use byte strings when operating on bytes<commit_after>import socket
import threading

class MalformedResponseError(Exception):
    pass

class StreamClient:
    def __init__(self, host, port, timeout=0.1, debug=False):
        self.timeout = timeout
        self.sock = socket.socket(type=socket.SOCK_DGRAM)
        self.sock.settimeout(self.timeout)
        self.hostaddr = (socket.gethostbyname(host), port)
        self.streaming = False
        self.callbackMap = {}
        self.tseq = 1
        
        self.sent = 0
        self.send_failed = 0
        self.received = 0
        self.delivered = 0
        self.missing = 0
        self.ooo = 0

        if debug:
            self.st = threading.Timer(1,self.stats)
            self.st.start()
        else:
            self.st = None

    def stats(self):
        print("sent: %i send-failed: %i received: %i delivered: %i missing: %i out-of-order: %i" % (self.sent, self.send_failed, self.received, self.delivered, self.missing, self.ooo))
        self.sent = 0
        self.send_failed = 0
        self.received = 0
        self.delivered = 0
        self.missing = 0
        self.ooo = 0
        self.st = threading.Timer(1,self.stats)
        self.st.start()

    def stop(self):
        if self.st:
            self.st.cancel()

    def get(self, key, blocking=False):
        reqdata = 'GET ' + key + '\r\n'
        self.transmit(reqdata)
        
        if blocking:
            self.sock.settimeout(None)

        data,addr = self.sock.recvfrom(65536)

        if blocking:
            self.sock.settimeout(self.timeout)

        return data.split(b'\r\n', 1)[1][:-2]

    def set(self, key, value):
        data = 'SET ' + key + ' ' + str(self.tseq) + ' ' + str(len(value)) + '\r\n' + str(value) + '\r\n'
        self.tseq += 1
        self.transmit(data)

{'fraction_non_alphanumeric': 0.12899669239250275, 'fraction_numerical': 0.014332965821389196, 'mean_word_length': 1.8552321007081038, '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': '5601492', 'n_tokens_mistral': 1231, 'n_tokens_neox': 1161, 'n_words': 254}