<commit_before>import requests
from .validator import ValidationError

class Client:
    def __init__(self, server_url, auth_token=None):
        # strip trailing / to avoid double / chars in the URL
        self.server_url = server_url.rstrip("/")
        self.auth_token = auth_token

    def __getattr__(self, func_name):
        return RemoteFunction(self, func_name)

    def call_func(self, func_name, **kwargs):
        url = self.server_url+"/"+func_name
        headers = {}
        if self.auth_token:
            headers['Authorization'] = 'Token {}'.format(self.auth_token)
        try:
            data, files = self.decouple_files(kwargs)
            if files:
                response = requests.post(url, data=data, files=files, headers=headers)
            else:
                response = requests.post(url, json=data, headers=headers)
        except ConnectionError as err:
            raise FireflyError(str(err))
        return self.handle_response(response)

    def _get_metadata(self):
        url = self.server_url + "/"
        return requests.get(url).json()

    def get_doc(self, func_name):
        metadata = self._get_metadata().get("functions", {})
        return metadata.get(func_name, {}).get("doc") or ""

    def decouple_files(self, kwargs):
        data = {arg: value for arg, value in kwargs.items() if not self.is_file(value)}
        files = {arg: value for arg, value in kwargs.items() if self.is_file(value)}
        return data, files

    def is_file(self, value):
        return hasattr(value, 'read') or hasattr(value, 'readlines')

    def handle_response(self, response):
        if response.status_code == 200:
            return response.json()
        elif response.status_code == 403:
            raise FireflyError("Authorization token mismatch.")
        elif response.status_code == 404:
            raise FireflyError("Requested function not found")
        elif response.status_code == 422:
            raise ValidationError(response.json()["error"])
        elif response.status_code == 500:
            raise FireflyError("Internal Server Error")
        else:
            raise FireflyError("Oops! Something really bad happened")

def RemoteFunction(client, func_name):
    def wrapped(self, **kwargs):
        return client.call_func(func_name, **kwargs)
    wrapped.__name__ = func_name
    wrapped.__qualname__ = func_name
    wrapped.__doc__ = client.get_doc(func_name)
    return wrapped
<commit_msg>Fixed a typo in the client function arguments.<commit_after>import requests
from .validator import ValidationError

class Client:
    def __init__(self, server_url, auth_token=None):
        # strip trailing / to avoid double / chars in the URL
        self.server_url = server_url.rstrip("/")
        self.auth_token = auth_token

    def __getattr__(self, func_name):
        return RemoteFunction(self, func_name)

    def call_func(self, func_name, **kwargs):
        url = self.server_url+"/"+func_name
        headers = {}
        if self.auth_token:
            headers['Authorization'] = 'Token {}'.format(self.auth_token)
        try:
            data, files = self.decouple_files(kwargs)
            if files:
                response = requests.post(url, data=data, files=files, headers=headers)
            else:
                response = requests.post(url, json=data, headers=headers)
        except ConnectionError as err:
            raise FireflyError(str(err))
        return self.handle_response(response)

    def _get_metadata(self):
        url = self.server_url + "/"
        return requests.get(url).json()

    def get_doc(self, func_name):
        metadata = self._get_metadata().get("functions", {})
        return metadata.get(func_name, {}).get("doc") or ""

    def decouple_files(self, kwargs):
        data = {arg: value for arg, value in kwargs.items() if not self.is_file(value)}
        files = {arg: value for arg, value in kwargs.items() if self.is_file(value)}
        return data, files

    def is_file(self, value):
        return hasattr(value, 'read') or hasattr(value, 'readlines')

    def handle_response(self, response):
        if response.status_code == 200:
            return response.json()
        elif response.status_code == 403:
            raise FireflyError("Authorization token mismatch.")
        elif response.status_code == 404:
            raise FireflyError("Requested function not found")
        elif response.status_code == 422:
            raise ValidationError(response.json()["error"])
        elif response.status_code == 500:
            raise FireflyError("Internal Server Error")
        else:
            raise FireflyError("Oops! Something really bad happened")

def RemoteFunction(client, func_name):
    def wrapped(**kwargs):
        return client.call_func(func_name, **kwargs)
    wrapped.__name__ = func_name
    wrapped.__qualname__ = func_name
    wrapped.__doc__ = client.get_doc(func_name)
    return wrapped

{'fraction_non_alphanumeric': 0.10558130163207738, 'fraction_numerical': 0.006044731009470079, 'mean_word_length': 2.677037037037037, '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': '760215', 'n_tokens_mistral': 1411, 'n_tokens_neox': 1371, 'n_words': 360}