<commit_before>from http.client import HTTPConnection
import json
import re
import threading
from socket import socket


server_addr = '172.16.31.10:8080'
APP_PORT = 1652
BUFF = 4096


def post_nick(nick='ivan'):
    """
    nick: str
    post your nickname to remote server
    """
    con = HTTPConnection(server_addr)
    header = {'Content-type': 'text/plain'}
    con.request('POST', '', bytes(nick, 'utf-8'), header)
    con.close()


def get_peers():
    """
    use get_peers_
    retuns dict of peers from server
    keys : values
    IP : NICK
    NICK : IP
    """
    con = HTTPConnection(server_addr)
    con.request('GET', '')
    response = con.getresponse()
    d = json.loads(response.read().decode('utf-8'))
    return d


def get_peers_():
    """
    -> (nicks, ips)
    split mixed tuple into two separate ones
    """
    nicks = get_peers()
    ips = dict()
    ipv4 = re.compile(r'^(?:\d{1,3}\.){3}\d{1,3}$')  # this regex mathes ipv4
    for item in nicks:
        if ipv4.match(item):
            ips[item] = nicks.pop(item)
    return nicks, ips


class Conversation:
    """
    a chat object
    use:

    in_stream - generator -> incoming messages

    out_stream <- outgoing messages

    """
    def __init__(self, ip, nick='{username}'):
        """
        ip: str '000.000.000.000'

        makes incoming and outgoing connections in a non-blocking way
        """
        self.i_conn = None      # REMEMBER setting theese two takes some time
        self.o_conn = None
        self.quit_flag = 0
        self.nick = nick

        def out_connect(ip):
            """
            sets o_conn: connection for outgoing messages
            """
            client_sock = socket()
            while not self.quit_flag:
                try:
                    client_sock.connect((str(ip), APP_PORT), timeout=5)
                    self.o_conn = client_sock
                except socket.timeout:
                    continue<commit_msg>timeout fix<commit_after>from http.client import HTTPConnection
import json
import re
import threading
from socket import socket


server_addr = '172.16.31.10:8080'
APP_PORT = 1652
BUFF = 4096


def post_nick(nick='ivan'):
    """
    nick: str
    post your nickname to remote server
    """
    con = HTTPConnection(server_addr)
    header = {'Content-type': 'text/plain'}
    con.request('POST', '', bytes(nick, 'utf-8'), header)
    con.close()


def get_peers():
    """
    use get_peers_
    retuns dict of peers from server
    keys : values
    IP : NICK
    NICK : IP
    """
    con = HTTPConnection(server_addr)
    con.request('GET', '')
    response = con.getresponse()
    d = json.loads(response.read().decode('utf-8'))
    return d


def get_peers_():
    """
    -> (nicks, ips)
    split mixed tuple into two separate ones
    """
    nicks = get_peers()
    ips = dict()
    ipv4 = re.compile(r'^(?:\d{1,3}\.){3}\d{1,3}$')  # this regex mathes ipv4
    for item in nicks:
        if ipv4.match(item):
            ips[item] = nicks.pop(item)
    return nicks, ips


class Conversation:
    """
    a chat object
    use:

    in_stream - generator -> incoming messages

    out_stream <- outgoing messages

    """
    def __init__(self, ip, nick='{username}'):
        """
        ip: str '000.000.000.000'

        makes incoming and outgoing connections in a non-blocking way
        """
        self.i_conn = None      # REMEMBER setting theese two takes some time
        self.o_conn = None
        self.quit_flag = 0
        self.nick = nick

        def out_connect(ip):
            """
            sets o_conn: connection for outgoing messages
            """
            client_sock = socket()
            while not self.quit_flag:
                try:
                    client_sock.settimeout(5)
                    client_sock.connect((str(ip), APP_PORT))
                    self.o_conn = client_sock
                except socket.timeout:
                    continue
{'fraction_non_alphanumeric': 0.11615016376921139, 'fraction_numerical': 0.022675736961451247, 'mean_word_length': 2.000755857898715, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, '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': '291390', 'n_tokens_mistral': 1294, 'n_tokens_neox': 1196, 'n_words': 326}