<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-


import logging
from jsonrpc.server import ServerEvents
import traceback


# logging
logger = logging.getLogger('root')
logger.setLevel(logging.DEBUG)
# console handler
console = logging.StreamHandler()
console.setLevel(logging.DEBUG)
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s \
[ %(filename)s : %(lineno)s ] - %(message)s")
console.setFormatter(formatter)
logger.addHandler(console)

class Chat(ServerEvents):

    def log(self, responses, txrequest, error):

        if isinstance(responses, list):
            for response in responses:
                msg = self._get_msg(response)
                logger.debug("%d %s > %s" % (txrequest.code, txrequest, msg))
        else:
            msg = self._get_msg(responses)
            logger.debug("CODE: %d %s" % (txrequest.code, txrequest))
            logger.debug("TXT: " + msg)

    def findmethod(self, method, args=None, kwargs=None):
        logger.debug('Got method: ' + repr(method))

        if method in self.methods:
            return getattr(self, method)
        else:
            return None

    # helper
    methods = set(['echo'])

    def _get_msg(self, resp):
        logger.debug("%s -> %s" % (resp, dir(resp)))
        return ' '.join(str(x) for x in [resp.id, resp.result or resp.error])

    def echo(self):
        return "Hi, what's your name?"
<commit_msg>Added methods: hello, server_methods, want_pizza<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-


import logging
from jsonrpc.server import ServerEvents
import traceback


# logging
logger = logging.getLogger('root')
logger.setLevel(logging.DEBUG)
# console handler
console = logging.StreamHandler()
console.setLevel(logging.DEBUG)
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s \
[ %(filename)s : %(lineno)s ] - %(message)s")
console.setFormatter(formatter)
logger.addHandler(console)

class Chat(ServerEvents):

    def log(self, responses, txrequest, error):

        if isinstance(responses, list):
            for response in responses:
                msg = self._get_msg(response)
                logger.debug("%d %s > %s" % (txrequest.code, txrequest, msg))
        else:
            msg = self._get_msg(responses)
            logger.debug("CODE: %d %s" % (txrequest.code, txrequest))
            logger.debug("TXT: " + msg)

    def findmethod(self, method, args=None, kwargs=None):
        logger.debug('Got method: ' + repr(method))

        if method in self.methods:
            return getattr(self, method)
        else:
            return None

    # helper
    methods = set(['hello', 'echo', 'want_pizza', 'server_methods'])

    def _get_msg(self, resp):
        logger.debug("%s -> %s" % (resp, dir(resp)))
        return ' '.join(str(x) for x in [resp.id, resp.result or resp.error])

    def hello(self):
        return "Hi, I am Pizza-Bot. Can I help you?"

    def echo(self, args):
        if isinstance(args, list):
            return ">> %s" % (' '.join(args))
        else:
            return ">> {0}".format(args)

    def want_pizza(self, kwargs):
        args = []
        for k,v in kwargs.items():
            args.append((k, v))
        return args


    def server_methods(self):
        return { 'methods': self.methods }
{'fraction_non_alphanumeric': 0.14453832226916113, 'fraction_numerical': 0.0009052504526252263, 'mean_word_length': 2.6549062844542446, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '1405208', 'n_tokens_mistral': 1046, 'n_tokens_neox': 1009, 'n_words': 252}