<commit_before>from settings import *
from stream import Stream
import socket
from util import *
from binascii import unhexlify
from pyHPACK.HPACK import encode, decode
from pyHPACK.tables import Table

class Connection(object):
    def __init__(self, sock, addr):
        self.sock = sock
        self.addr = addr
        self.table = Table()
        self.streams = {}
        self.addStream(0)
        self.enablePush = SET.INIT_VALUE[2]
        self.maxConcurrentStreams = SET.INIT_VALUE[3]
        self.maxFrameSize = SET.INIT_VALUE[5]
        self.maxHeaderListSize = SET.INIT_VALUE[6]
        self.readyToPayload = False
        self.goAwayId = 0
        # temporaly using
        self.wireLenLimit = 24

    def send(self, frameType, flag = FLAG.NO, streamId = 0, **kwargs):
        frame = self.streams[streamId].makeFrame(frameType, flag, **kwargs)
        self.sock.send(frame)
        # here?
        while len(self.streams[streamId].wire):
            if len(self.streams[streamId].wire) > self.wireLenLimit:
                frame = self.streams[streamId].makeFrame(TYPE.CONTINUATION, FLAG.NO)
            else:
                frame = self.streams[streamId].makeFrame(TYPE.CONTINUATION, FLAG.END_HEADERS)
            self.sock.send(frame)

    def parseData(self, data):
        Length, Type, Flag, sId = 0, '\x00', '\x00', 0 #here?

        def _parseFrameHeader(data):
            return upackHex(data[:3]), data[3:4], \
                data[4:5], upackHex(data[5:9])

        def _data(data):<commit_msg>added setSocket method to hide difference TLS is used or not<commit_after>from settings import *
from stream import Stream
import socket
from util import *
from binascii import unhexlify
from pyHPACK.HPACK import encode, decode
from pyHPACK.tables import Table

class Connection(object):
    def __init__(self, sock, addr, enable_tls):
        self.setSocket(sock, enable_tls)
        self.addr = addr
        self.table = Table()
        self.streams = {}
        self.addStream(0)
        self.enablePush = SET.INIT_VALUE[2]
        self.maxConcurrentStreams = SET.INIT_VALUE[3]
        self.maxFrameSize = SET.INIT_VALUE[5]
        self.maxHeaderListSize = SET.INIT_VALUE[6]
        self.readyToPayload = False
        self.goAwayId = 0
        # temporaly using
        self.wireLenLimit = 24

    def setSocket(self, sock, enable_tls):
        self.sock = sock
        if enable_tls:
            self._send = sock.write
            self._recv = sock.read
        else:
            self._send = sock.send
            self._recv = sock.recv

    def _send(self):
        pass

    def _recv(self):
        pass

    def send(self, frameType, flag = FLAG.NO, streamId = 0, **kwargs):
        frame = self.streams[streamId].makeFrame(frameType, flag, **kwargs)
        self._send(frame)
        # here?
        while len(self.streams[streamId].wire):
            if len(self.streams[streamId].wire) > self.wireLenLimit:
                frame = self.streams[streamId].makeFrame(TYPE.CONTINUATION, FLAG.NO)
            else:
                frame = self.streams[streamId].makeFrame(TYPE.CONTINUATION, FLAG.END_HEADERS)
            self._send(frame)

    def parseData(self, data):
        Length, Type, Flag, sId = 0, '\x00', '\x00', 0 #here?

        def _parseFrameHeader(data):
            return upackHex(data[:3]), data[3:4], \
                data[4:5], upackHex(data[5:9])

        def _data(data):
{'fraction_non_alphanumeric': 0.10922897196261683, 'fraction_numerical': 0.012850467289719626, 'mean_word_length': 2.3284742468415938, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '4173649', 'n_tokens_mistral': 1090, 'n_tokens_neox': 1047, 'n_words': 239}