<commit_before># -*- coding: utf-8 -*-

import json
import uuid

__all__ = ['ServerProxy', 'Call']


class Call:

    def __init__(self, method, version, caller=None):
        self.method = method
        self.version = version
        self.caller = caller

    def _generate_id(self):
        return str(uuid.uuid4())

    def set_caller(self, caller):
        self.caller = caller

    def dump(self, params):
        if self.version == '2.0':
            dct = dict(jsonrpc=self.version,
                       method=self.method,
                       id=self._generate_id())

            if params:
                dct.update(params=params)

            return dct

        raise NotImplementedError()

    def __getattr__(self, name):
        return Call(self.method + '.' + name, self.version, self.caller)

    def __call__(self, *args, **kwargs):
        if len(args) == len(kwargs) == 0:
            params = dict()
        elif len(args) == 0:
            params = kwargs
        elif len(kwargs) == 0:
            params = args
        else:
            raise ValueError('All parameters must be anonymouse or named')

        return self.caller(self.dump(params))


class ServerProxy:

    version = '2.0'

    def __init__(self, uri, transport):
        self.uri = uri
        self.transport = transport

    def send_request(self, call):
        encoded = json.dumps(call)
        resp = self.transport.send_request(encoded)

        respobj = json.loads(resp)
        if not isinstance(respobj, dict):
            raise ValueError()

        if respobj['id'] != call.get('id'):
            raise ValueError()

        return respobj

    def __getattr__(self, name):
        return Call(name, self.version, self.send_request)<commit_msg>return response as instance of client.Response<commit_after># -*- coding: utf-8 -*-

import json
import uuid

__all__ = ['ServerProxy', 'Call']


class Call:

    def __init__(self, method, version, caller=None):
        self.method = method
        self.version = version
        self.caller = caller

    def _generate_id(self):
        return str(uuid.uuid4())

    def set_caller(self, caller):
        self.caller = caller

    def dump(self, params):
        if self.version == '2.0':
            dct = dict(jsonrpc=self.version,
                       method=self.method,
                       id=self._generate_id())

            if params:
                dct.update(params=params)

            return dct

        raise NotImplementedError()

    def __getattr__(self, name):
        return Call(self.method + '.' + name, self.version, self.caller)

    def __call__(self, *args, **kwargs):
        if len(args) == len(kwargs) == 0:
            params = dict()
        elif len(args) == 0:
            params = kwargs
        elif len(kwargs) == 0:
            params = args
        else:
            raise ValueError('All parameters must be anonymouse or named')

        return self.caller(self.dump(params))


class Response:

    def __init__(self, call, response):
        self.call = call
        self.response = response

    def get_result(self):
        if self.has_error():
            return None
        return self.response.get('result')

    def get_error(self):
        return self.response.get('error')

    def has_error(self):
        return self.get_error() is not None


class ServerProxy:

    version = '2.0'
    response_cls = Response

    def __init__(self, uri, transport):
        self.uri = uri
        self.transport = transport

    def send_request(self, call):
        encoded = json.dumps(call)
        resp = self.transport.send_request(encoded)

        respobj = json.loads(resp)
        if not isinstance(respobj, dict):
            raise ValueError()

        return self.response_cls(call, respobj)

    def __getattr__(self, name):
        return Call(name, self.version, self.send_request)
{'fraction_non_alphanumeric': 0.10991268618387262, 'fraction_numerical': 0.004622496147919877, 'mean_word_length': 1.9984603541185528, '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': '2593874', 'n_tokens_mistral': 1143, 'n_tokens_neox': 1096, 'n_words': 289}