<commit_before>"Smarkets TCP-based session management"
import logging
import Queue
import socket

from google.protobuf import text_format

import eto.piqi_pb2 as eto
import seto.piqi_pb2 as seto

from smk.exceptions import ConnectionError, SocketDisconnected


class Session(object):
    "Manages TCP communication via Smarkets streaming API"
    logger = logging.getLogger('smk.session')

    def __init__(self, username, password, host='localhost', port=3701,
                 session=None, inseq=1, outseq=1, socket_timeout=None):
        self.username = username
        self.password = password
        self.socket = SessionSocket(host, port, socket_timeout)
        self.session = session
        self.inseq = inseq
        # Outgoing socket sequence number
        self.outseq = outseq
        # Outgoing buffer sequence number
        self.buf_outseq = outseq
        self.in_payload = seto.Payload()
        self.out_payload = seto.Payload()
        self.send_buffer = Queue.Queue()

    @property
    def connected(self):
        "Returns True if the socket is currently connected"
        return self.socket.connected

    def connect(self):
        "Connects to the API and logs in if not already connected"
        if self.socket.connect():
            # Clear the outgoing send buffer
            self.send_buffer = Queue.Queue()
            # Reset separate outgoing buffer sequence number
            self.buf_outseq = self.outseq
            login = self.out_payload
            login.Clear()<commit_msg>Add default session timeout of 30 seconds<commit_after>"Smarkets TCP-based session management"
import logging
import Queue
import socket

from google.protobuf import text_format

import eto.piqi_pb2 as eto
import seto.piqi_pb2 as seto

from smk.exceptions import ConnectionError, SocketDisconnected


class Session(object):
    "Manages TCP communication via Smarkets streaming API"
    logger = logging.getLogger('smk.session')

    def __init__(self, username, password, host='localhost', port=3701,
                 session=None, inseq=1, outseq=1, socket_timeout=30):
        self.username = username
        self.password = password
        self.socket = SessionSocket(host, port, socket_timeout)
        self.session = session
        self.inseq = inseq
        # Outgoing socket sequence number
        self.outseq = outseq
        # Outgoing buffer sequence number
        self.buf_outseq = outseq
        self.in_payload = seto.Payload()
        self.out_payload = seto.Payload()
        self.send_buffer = Queue.Queue()

    @property
    def connected(self):
        "Returns True if the socket is currently connected"
        return self.socket.connected

    def connect(self):
        "Connects to the API and logs in if not already connected"
        if self.socket.connect():
            # Clear the outgoing send buffer
            self.send_buffer = Queue.Queue()
            # Reset separate outgoing buffer sequence number
            self.buf_outseq = self.outseq
            login = self.out_payload
            login.Clear()
{'fraction_non_alphanumeric': 0.07170795306388526, 'fraction_numerical': 0.00651890482398957, 'mean_word_length': 2.6233766233766236, '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': '2920212', 'n_tokens_mistral': 832, 'n_tokens_neox': 806, 'n_words': 253}