<commit_before>import json
import threading
import socket
import ssl
import datetime

from ..exceptions import SocketError
from ..compat import is_py3


class BetfairStream(object):
    """Socket holder, connects to betfair and
    pushes any received data to listener
    """

    __host = 'stream-api.betfair.com'
    __port = 443
    __CRLF = '\r\n'
    __encoding = 'utf-8'

    def __init__(self, unique_id, listener, app_key, session_token, timeout, buffer_size, description):
        self.unique_id = unique_id
        self.listener = listener
        self.app_key = app_key
        self.session_token = session_token
        self.timeout = timeout
        self.buffer_size = buffer_size
        self.description = description
        self.receive_count = 0
        self.datetime_last_received = None

        self._socket = None
        self._running = False

    def start(self, async=False):
        """Starts read loop, new thread if async and
        connects/authenticates if not already running.

        :param async: If True new thread is started
        """
        if not self._running:
            self._connect()
            self.authenticate()
        if async:
            threading.Thread(name=self.description, target=self._read_loop, daemon=False).start()
        else:
            self._read_loop()

    def stop(self):
        """Stops read loop which closes socket
        """
        self._running = False

    def authenticate(self, unique_id=None):
        """Authentication request.

        :param unique_id: self.unique_id used if not supplied.
        """
        message = {
            'op': 'authentication',
            'id': unique_id or self.unique_id,
            'appKey': self.app_key,
            'session': self.session_token
        }
        self.listener.register_stream(unique_id or self.unique_id, 'authentication')
        self._send(message)

    def heartbeat(self, unique_id=None):<commit_msg>python 2.7 threading.Thread has no daemon kwarg<commit_after>import json
import threading
import socket
import ssl
import datetime

from ..exceptions import SocketError
from ..compat import is_py3


class BetfairStream(object):
    """Socket holder, connects to betfair and
    pushes any received data to listener
    """

    __host = 'stream-api.betfair.com'
    __port = 443
    __CRLF = '\r\n'
    __encoding = 'utf-8'

    def __init__(self, unique_id, listener, app_key, session_token, timeout, buffer_size, description):
        self.unique_id = unique_id
        self.listener = listener
        self.app_key = app_key
        self.session_token = session_token
        self.timeout = timeout
        self.buffer_size = buffer_size
        self.description = description
        self.receive_count = 0
        self.datetime_last_received = None

        self._socket = None
        self._running = False

    def start(self, async=False):
        """Starts read loop, new thread if async and
        connects/authenticates if not already running.

        :param async: If True new thread is started
        """
        if not self._running:
            self._connect()
            self.authenticate()
        if async:
            t = threading.Thread(name=self.description, target=self._read_loop)
            t.daemon = False
            t.start()
        else:
            self._read_loop()

    def stop(self):
        """Stops read loop which closes socket
        """
        self._running = False

    def authenticate(self, unique_id=None):
        """Authentication request.

        :param unique_id: self.unique_id used if not supplied.
        """
        message = {
            'op': 'authentication',
            'id': unique_id or self.unique_id,
            'appKey': self.app_key,
            'session': self.session_token
        }
        self.listener.register_stream(unique_id or self.unique_id, 'authentication')
        self._send(message)

    def heartbeat(self, unique_id=None):
{'fraction_non_alphanumeric': 0.08806459752712592, 'fraction_numerical': 0.0035326772646984608, 'mean_word_length': 2.241210139002453, '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': '1681535', 'n_tokens_mistral': 1136, 'n_tokens_neox': 1082, 'n_words': 304}