<commit_before>#!/usr/bin/env python
"""
Sample sever, just echos input plus seq number
"""

import pollengine

# ---

class EchoDriver:
    """Driver to echo back client data"""

    def __init__( self ):
        self.seq = 0
        return

    def process_request( self, conn ):
        """Handle requests received from the client"""

        __continue = True
        __inp = conn.inp_queue
        if __inp[-1:] == '\n':
            __inp = __inp[:-1]

        conn.inp_queue = ''

        if __inp == 'QUIT':
            PE.displaymsg( 'Stopping server.' )
            __continue = False

        elif __inp == 'DROP':
            PE.displaymsg( 'Dropped client.' )
            conn.close()

        else:
            self.seq += 1
            conn.queue_response( 'Msg#{seq} len={ilen} {inp}'.format(
                    seq=self.seq, ilen=len(__inp), inp=__inp) )

        return __continue

    def get_name( self ):
        """Return a description of the class"""

        return 'Echo-Driver'

# ---

ECHO_PORT = 8888
SERVER_PORTS = set()
SERVER_PORTS.add( ECHO_PORT )

# ---

PE = pollengine

ECHO_SHELL = EchoDriver()

ENGINE = PE.Engine( port_list = SERVER_PORTS )
ENGINE.config_server( ECHO_PORT, shell = ECHO_SHELL )
ENGINE.run()
<commit_msg>Simplify the "echo-sequence" sample server<commit_after>#!/usr/bin/env python
"""
Sample sever, just echos input plus seq number
"""

import pollengine
PE = pollengine

# ---

class EchoDriver:
    """Driver to echo back client data"""

    def __init__( self ):
        self.seq = 0
        return

    def process_request( self, conn ):
        """Handle requests received from the client"""

        __continue = True
        __inp = conn.inp_queue
        if __inp[-1:] == '\n':
            __inp = __inp[:-1]

        conn.inp_queue = ''

        if __inp == 'QUIT':
            PE.displaymsg( 'Stopping server.' )
            __continue = False

        elif __inp == 'DROP':
            PE.displaymsg( 'Dropped client.' )
            conn.close()

        else:
            self.seq += 1
            conn.queue_response( 'Msg#{seq} len={ilen} {inp}'.format(
                    seq=self.seq, ilen=len(__inp), inp=__inp) )

        return __continue

    def get_name( self ):
        """Return a description of the class"""

        return 'Echo-Driver'

# ---

ECHO_PORT = 8888

ENGINE = PE.Engine( port_list = [ ECHO_PORT ] )
ENGINE.config_server( ECHO_PORT, shell = EchoDriver() )
ENGINE.run()

{'fraction_non_alphanumeric': 0.12835093419983754, 'fraction_numerical': 0.006498781478472786, 'mean_word_length': 2.0183823529411766, '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': '4354222', 'n_tokens_mistral': 837, 'n_tokens_neox': 782, 'n_words': 204}