<commit_before>import base64
import json
import logging
import socket
import time

from . import exceptions

class RemoteWebsocket():
    """Object for remote control connection."""

    def __init__(self, config):
        import websocket

        if not config["port"]:
            config["port"] = 8001

        URL_FORMAT = "ws://{}:{}/api/v2/channels/samsung.remote.control?name={}"

        """Make a new connection."""
        self.connection = websocket.WebSocket()
        self.connection.connect(URL_FORMAT.format(config["host"], config["port"],
                                                  self._serialize_string(config["name"])))

        self._read_response()

    def __enter__(self):
        return self

    def __exit__(self, type, value, traceback):
        self.close()

    def close(self):
        """Close the connection."""
        if self.connection:
            self.connection.close()
            self.connection = None<commit_msg>Add timeout support for websocket connections<commit_after>import base64
import json
import logging
import socket
import time

from . import exceptions

class RemoteWebsocket():
    """Object for remote control connection."""

    def __init__(self, config):
        import websocket

        if not config["port"]:
            config["port"] = 8001

        URL_FORMAT = "ws://{}:{}/api/v2/channels/samsung.remote.control?name={}"

        """Make a new connection."""
        self.connection = websocket.create_connection(URL_FORMAT.format(config["host"], config["port"],
                                                  self._serialize_string(config["name"])), config["timeout"])

        self._read_response()

    def __enter__(self):
        return self

    def __exit__(self, type, value, traceback):
        self.close()

    def close(self):
        """Close the connection."""
        if self.connection:
            self.connection.close()
            self.connection = None
{'fraction_non_alphanumeric': 0.1216008209338122, 'fraction_numerical': 0.007183170856849667, 'mean_word_length': 2.339041095890411, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5261956', 'n_tokens_mistral': 506, 'n_tokens_neox': 483, 'n_words': 128}