<commit_before>import time

import requests
from requests.compat import urljoin


class API:

    send_task_endpoint = 'user/submit_task'
    get_answer_endpoint = 'user/request_answer'
    estimate_time_left_endpoint = 'user/estimate_time_left'

    @staticmethod
    def make_task(function_description, argskwargs):
        task = function_description.copy()
        task['args'] = argskwargs.get('args', [])
        task['kwargs'] = argskwargs.get('kwargs', {})
        return task

    def __init__(self, server_addr):
        self.server_addr = server_addr

    def send_task(self, task):
        response = requests.post(urljoin(self.server_addr, self.send_task_endpoint), json=task).json()

        if response['sucsess']:
            return response['id']
        else:
            raise RuntimeError('Server returned sucsess != True')

    def get_answer(self, id_):
        params = {'id': id_}
        response = requests.get(urljoin(self.server_addr, self.get_answer_endpoint), params=params).json()
        return response['sucsess'], response.get('answer', None)

    def estimate_time_left(self):
        response = requests.get(urljoin(self.server_addr, self.estimate_time_left_endpoint))
        response = response.json()
        return response['time']

    def map_unordered(self, function_description, argskwargslist, check_interval=1):
        ids = set()
        for task in (self.make_task(function_description, argskwargs) for argskwargs in argskwargslist):
            ids.add(self.send_task(task))

        while ids:
            for id_ in ids.copy():
                sucsess, answer = self.get_answer(id_)
                if sucsess:
                    ids.remove(id_)
                    yield answer
                else:
                    time.sleep(check_interval)

    def map(self, function_description, argskwargslist, check_interval=1):
        ids = set()
        for task in (self.make_task(function_description, argskwargs) for argskwargs in argskwargslist):
            ids.add(self.send_task(task))

        for id_ in ids:
            while True:
                sucsess, answer = self.get_answer(id_)
                if sucsess:
                    yield answer
                    break
                else:
                    time.sleep(check_interval)<commit_msg>map and map_unordered now accept items, apply added #13<commit_after>import time

import requests
from requests.compat import urljoin


class API:

    send_task_endpoint = 'user/submit_task'
    get_answer_endpoint = 'user/request_answer'
    estimate_time_left_endpoint = 'user/estimate_time_left'

    @staticmethod
    def make_task(function_description, args=[], kwargs={}):
        task = function_description.copy()
        task['args'] = args
        task['kwargs'] = kwargs
        return task

    def __init__(self, server_addr, check_interval=1):
        self.check_interval = check_interval
        self.server_addr = server_addr

    def send_task(self, task):
        response = requests.post(urljoin(self.server_addr, self.send_task_endpoint), json=task).json()

        if response['sucsess']:
            return response['id']
        else:
            raise RuntimeError('Server returned sucsess != True')

    def get_answer(self, id_):
        params = {'id': id_}
        response = requests.get(urljoin(self.server_addr, self.get_answer_endpoint), params=params).json()
        return response['sucsess'], response.get('answer', None)

    def estimate_time_left(self):
        response = requests.get(urljoin(self.server_addr, self.estimate_time_left_endpoint))
        response = response.json()
        return response['time']

    def map_unordered(self, function_description, items):
        ids = set()
        for task in (self.make_task(function_description, args=[item]) for item in items):
            ids.add(self.send_task(task))

        while ids:
            for id_ in ids.copy():
                sucsess, answer = self.get_answer(id_)
                if sucsess:
                    ids.remove(id_)
                    yield answer
                else:
                    time.sleep(self.check_interval)

    def map(self, function_description, items):
        ids = []
        for task in (self.make_task(function_description, args=[item]) for item in items):
            ids.append(self.send_task(task))

        for id_ in ids:
            while True:
                sucsess, answer = self.get_answer(id_)
                if sucsess:
                    yield answer
                    break
                else:
                    time.sleep(self.check_interval)

    def apply(self, function_description, args=[], kwargs={}):
        task = self.make_task(function_description, args=args, kwargs=kwargs)
        id_ = self.send_task(task)

        while True:
            sucsess, answer = self.get_answer(id_)
            if sucsess:
                return answer
            else:
                time.sleep(self.check_interval)
{'fraction_non_alphanumeric': 0.0966773418734988, 'fraction_numerical': 0.0010008006405124099, 'mean_word_length': 2.246913580246914, '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': '1250383', 'n_tokens_mistral': 1433, 'n_tokens_neox': 1385, 'n_words': 308}