<commit_before># Python rough implementation of a C# TCP client
import errno
import socket
from datetime import timedelta
from io import BytesIO, BufferedWriter
from threading import Lock


class TcpClient:
    def __init__(self, proxy=None, timeout=timedelta(seconds=5)):
        self._proxy = proxy
        self._socket = None
        self._closing_lock = Lock()

        if isinstance(timeout, timedelta):
            self.timeout = timeout.seconds
        elif isinstance(timeout, int) or isinstance(timeout, float):
            self.timeout = float(timeout)
        else:
            raise ValueError('Invalid timeout type', type(timeout))

    def _recreate_socket(self, mode):
        if self._proxy is None:
            self._socket = socket.socket(mode, socket.SOCK_STREAM)
        else:
            import socks
            self._socket = socks.socksocket(mode, socket.SOCK_STREAM)
            if type(self._proxy) is dict:
                self._socket.set_proxy(**self._proxy)
            else:  # tuple, list, etc.
                self._socket.set_proxy(*self._proxy)

        self._socket.settimeout(self.timeout)

    def connect(self, ip, port):
        """Connects to the specified IP and port number.
           'timeout' must be given in seconds
        """
        if ':' in ip:  # IPv6
            mode, address = socket.AF_INET6, (ip, port, 0, 0)
        else:
            mode, address = socket.AF_INET, (ip, port)

        while True:
            try:
                if not self._socket:
                    self._recreate_socket(mode)
<commit_msg>Attempt at fixing socket is None on .connect()<commit_after># Python rough implementation of a C# TCP client
import errno
import socket
from datetime import timedelta
from io import BytesIO, BufferedWriter
from threading import Lock


class TcpClient:
    def __init__(self, proxy=None, timeout=timedelta(seconds=5)):
        self._proxy = proxy
        self._socket = None
        self._closing_lock = Lock()

        if isinstance(timeout, timedelta):
            self.timeout = timeout.seconds
        elif isinstance(timeout, int) or isinstance(timeout, float):
            self.timeout = float(timeout)
        else:
            raise ValueError('Invalid timeout type', type(timeout))

    def _recreate_socket(self, mode):
        if self._proxy is None:
            self._socket = socket.socket(mode, socket.SOCK_STREAM)
        else:
            import socks
            self._socket = socks.socksocket(mode, socket.SOCK_STREAM)
            if type(self._proxy) is dict:
                self._socket.set_proxy(**self._proxy)
            else:  # tuple, list, etc.
                self._socket.set_proxy(*self._proxy)

        self._socket.settimeout(self.timeout)

    def connect(self, ip, port):
        """Connects to the specified IP and port number.
           'timeout' must be given in seconds
        """
        if ':' in ip:  # IPv6
            mode, address = socket.AF_INET6, (ip, port, 0, 0)
        else:
            mode, address = socket.AF_INET, (ip, port)

        while True:
            try:
                while not self._socket:
                    self._recreate_socket(mode)

{'fraction_non_alphanumeric': 0.09025157232704402, 'fraction_numerical': 0.0031446540880503146, 'mean_word_length': 2.079380445304937, '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': '908719', 'n_tokens_mistral': 887, 'n_tokens_neox': 849, 'n_words': 259}