<commit_before>"""IP Physical Layer
"""
from __future__ import absolute_import
import socket
from .protocol import PhysicalLayer


class Ip(PhysicalLayer):
    """IP Physical Layer"""

    def __init__(self, addr):
        """Create an IP Physical Layer.
        :addr tuple: Address tuple (host, port)
        """
        self.addr = addr
        self.connection = None

    def connect(self):
        """Connect to `self.addr`
        """
        self.connection = socket.create_connection(self.addr)
    
    def disconnect(self):
        """Disconnects
        """
        if self.connection:
            self.connection.close()
    
    def send_byte(self, byte):
        """Send a byte"""
        assert isinstance(self.connection, socket.socket)
        self.connection.send(byte)
    
    def get_byte(self, timeout):
        """Read a byte"""
        assert isinstance(self.connection, socket.socket)
        self.connection.recv(1)<commit_msg>Implement reading socket with threading<commit_after>"""IP Physical Layer
"""
from __future__ import absolute_import
import socket
import queue
import threading
from .protocol import PhysicalLayer


class Ip(PhysicalLayer):
    """IP Physical Layer"""

    def __init__(self, addr):
        """Create an IP Physical Layer.
        :addr tuple: Address tuple (host, port)
        """
        self.addr = addr
        self.connection = None
        self.connected = False
        self.queue = queue.Queue()
        self.thread = threading.Thread(target=self.read_port)

    def connect(self):
        """Connect to `self.addr`
        """
        self.connection = socket.create_connection(self.addr)
        self.connected = True
        self.thread.start()

    def disconnect(self):
        """Disconnects
        """
        if self.connection:
            self.connection.close()
        self.connected = False

    def read_port(self):
        """Read bytes from socket
        """
        while self.connected:
            response = self.connection.recv(16)
            if not response:
                continue
            for byte_resp in response:
                self.queue.put(byte_resp)

    def send_byte(self, byte):
        """Send a byte"""
        assert isinstance(self.connection, socket.socket)
        self.connection.send(byte)

    def get_byte(self, timeout=60):
        """Read a byte"""
        return self.queue.get(True, timeout=timeout)
{'fraction_non_alphanumeric': 0.10835401157981803, 'fraction_numerical': 0.0020678246484698098, 'mean_word_length': 2.2124833997343956, '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': '2594317', 'n_tokens_mistral': 657, 'n_tokens_neox': 632, 'n_words': 174}