<commit_before># Sfevy - Sockets for everyone
# by Vox

# Copyright (c) 2017 VOX
#      MIT LICENSE

import socket
import threading

class Protocol():
    TCP = 1
    UDP = 2

class sockets:
    def __init__(self, host, port, ip=socket.gethostname()):
        self.listening = False
        self.IP = ip
        self.HOST = host
        self.PORT = port
    def setHost(host, port):
        self.HOST = host
        self.PORT = port
    def setAddress(self, ip, port):
        self.IP = ip
        self.PORT = port
    def sendData(self, data, pcol, raw=False):
        if pcol == Protocol.TCP:
            threading.Thread(target=_sendTCPThread, args=(data, raw)).start()
        elif pcol == Protocol.UDP:
            threading.Thread(target=_sendUDPThread, args=(data, raw)).start()
        else:
            print("error: Not avaliable protocol.")
    def _sendUDPThread(self, data, raw):
        if raw == False:
            sData = bytes(data, "utf-8")
        else:
            sData = data
        sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # UDP
        sock.sendto((self.HOST, self.PORT))
        sock.close()
    def _sendTCPThread(self, data, raw):
        if raw == False:
            sData = bytes(data, "utf-8")
        else:
            sData = data
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # TCP
        sock.connect((self.HOST, self.PORT))
        sock.sendall(sData)
        sock.close()
    def startListening(self, dataHandler, pcol, buffer=1024, raw=False):<commit_msg>added optional encoding on sendData()<commit_after># Sfevy - Sockets for everyone
# by Vox

# Copyright (c) 2017 VOX
#      MIT LICENSE

import socket
import threading

class Protocol():
    TCP = 1
    UDP = 2

class sockets:
    def __init__(self, host, port, ip=socket.gethostname()):
        self.listening = False
        self.IP = ip
        self.HOST = host
        self.PORT = port
    def setHost(host, port):
        self.HOST = host
        self.PORT = port
    def setAddress(self, ip, port):
        self.IP = ip
        self.PORT = port
    def sendData(self, data, pcol, raw=False):
        if not raw:
            raw = bytes(data, "utf-8")
        if pcol == Protocol.TCP:
            threading.Thread(target=_sendTCPThread, args=(data, raw)).start()
        elif pcol == Protocol.UDP:
            threading.Thread(target=_sendUDPThread, args=(data, raw)).start()
        else:
            print("error: Not avaliable protocol.")
    def _sendUDPThread(self, data, raw):
        if raw == False:
            sData = bytes(data, "utf-8")
        else:
            sData = data
        sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # UDP
        sock.sendto((self.HOST, self.PORT))
        sock.close()
    def _sendTCPThread(self, data, raw):
        if raw == False:
            sData = bytes(data, "utf-8")
        else:
            sData = data
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # TCP
        sock.connect((self.HOST, self.PORT))
        sock.sendall(sData)
        sock.close()
    def startListening(self, dataHandler, pcol, buffer=1024, raw=False):
{'fraction_non_alphanumeric': 0.11850907932462568, 'fraction_numerical': 0.00796431984708506, 'mean_word_length': 2.1243781094527363, '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': '543184', 'n_tokens_mistral': 1006, 'n_tokens_neox': 979, 'n_words': 253}