<commit_before>"""The core components

Todos
-----
* serializing query params
* pagination
"""
import typing as t
import types
import inspect
from functools import partial
from operator import methodcaller

from dataclasses import dataclass, field, astuple

from toolz import identity, compose

from . import http
from .utils import apply

_dictfield = partial(field, default_factory=dict)


@dataclass(frozen=True)
class Api:
    """an API endpoint"""
    prepare: t.Callable[[http.Request], http.Request] = identity
    parse:   t.Callable[[http.Response], t.Any] = identity


class BoundMeta(type):
    """used to bind classes to the parent class in which they are declared"""

    def __set_name__(self, kls, name):
        self.__name__ = f'{kls.__name__}.{self.__name__}'

    def __get__(self, instance, cls):
        """like a method, pass the current instance as first argument"""
        return self if instance is None else partial(self, instance)


class Query(metaclass=BoundMeta):
    """base for all queries. Can be used as a base class,
    or initialized directly"""
    def __init__(self, request, rtype):
        self.__req__, self.__rtype__ = request, rtype

    def __init_subclass__(cls, rtype, **kwargs):
        cls.__rtype__ = rtype

    __req__ = NotImplemented
    __rtype__ = NotImplemented<commit_msg>small rename<commit_after>"""high-level query interface

Todos
-----
* serializing query params
* pagination
"""
import typing as t
import types
import inspect
from functools import partial
from operator import methodcaller

from dataclasses import dataclass, field, astuple

from toolz import identity, compose

from . import http
from .utils import apply

_dictfield = partial(field, default_factory=dict)


@dataclass(frozen=True)
class Api:
    """an API endpoint"""
    prepare: t.Callable[[http.Request], http.Request] = identity
    parse:   t.Callable[[http.Response], t.Any] = identity


class _Bound(type):
    """used to bind classes to the parent class in which they are declared"""

    def __set_name__(self, kls, name):
        self.__name__ = f'{kls.__name__}.{self.__name__}'

    def __get__(self, instance, cls):
        """like a method, pass the current instance as first argument"""
        return self if instance is None else partial(self, instance)


class Query(metaclass=_Bound):
    """base for all queries. Can be used as a base class,
    or initialized directly"""
    def __init__(self, request, rtype):
        self.__req__, self.__rtype__ = request, rtype

    def __init_subclass__(cls, rtype, **kwargs):
        cls.__rtype__ = rtype

    __req__ = NotImplemented
    __rtype__ = NotImplemented
{'fraction_non_alphanumeric': 0.0981203007518797, 'fraction_numerical': 0.0, 'mean_word_length': 3.8119349005424956, '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': '6835073', 'n_tokens_mistral': 791, 'n_tokens_neox': 773, 'n_words': 274}