<commit_before>from __future__ import absolute_import,unicode_literals

import os
import select
import socket
import logging
import msgpack
import collections

logger = logging.getLogger(__name__)

import synapse.glob as s_glob
import synapse.common as s_common
import synapse.lib.threads as s_threads

from synapse.eventbus import EventBus

from synapse.common import *

class SockXform:
    '''
    Base class for a socket bytes transform class.

    Notes:

        * for obj tx/rx, these are called once per.
    '''
    def init(self, sock):
        pass

    def txform(self, byts):
        return byts

    def rxform(self, byts):
        return byts

class Socket(EventBus):

    def __init__(self, sock, **info):
        EventBus.__init__(self)

        self.sock = sock
        self.plex = None
        self.unpk = msgpack.Unpacker(use_list=0,encoding='utf8')
        self.iden = s_common.guid()
        self.xforms = []        # list of SockXform instances
        self.info = info

        # used by Plex() tx
        self.txbuf = None
        self.txque = collections.deque()

        self.onfini(self._finiSocket)

    def addSockXform(self, xform):
        '''
        Add a data transformation filter to the socket.

        Example:

            sock.addSockXform(xform)

        '''
        xform.init(self)
        self.xforms.append(xform)

    def get(self, prop):
        '''
        Retrieve a property from the socket's info dict.

        Example:

            if sock.get('listen'):
                dostuff()<commit_msg>make socket idens be hex guids not binary<commit_after>from __future__ import absolute_import,unicode_literals

import os
import select
import socket
import logging
import msgpack
import collections

logger = logging.getLogger(__name__)

import synapse.glob as s_glob
import synapse.common as s_common
import synapse.lib.threads as s_threads

from synapse.eventbus import EventBus

from synapse.common import *

class SockXform:
    '''
    Base class for a socket bytes transform class.

    Notes:

        * for obj tx/rx, these are called once per.
    '''
    def init(self, sock):
        pass

    def txform(self, byts):
        return byts

    def rxform(self, byts):
        return byts

class Socket(EventBus):

    def __init__(self, sock, **info):
        EventBus.__init__(self)

        self.sock = sock
        self.plex = None
        self.unpk = msgpack.Unpacker(use_list=0,encoding='utf8')
        self.iden = s_common.guidstr()
        self.xforms = []        # list of SockXform instances
        self.info = info

        # used by Plex() tx
        self.txbuf = None
        self.txque = collections.deque()

        self.onfini(self._finiSocket)

    def addSockXform(self, xform):
        '''
        Add a data transformation filter to the socket.

        Example:

            sock.addSockXform(xform)

        '''
        xform.init(self)
        self.xforms.append(xform)

    def get(self, prop):
        '''
        Retrieve a property from the socket's info dict.

        Example:

            if sock.get('listen'):
                dostuff()
{'fraction_non_alphanumeric': 0.08517451168747998, 'fraction_numerical': 0.001280819724623759, 'mean_word_length': 2.220618556701031, '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': '5410283', 'n_tokens_mistral': 957, 'n_tokens_neox': 916, 'n_words': 268}