<commit_before>"""
    serializers.jsonapi
    ~~~~~~~~~~~~~~~~~~~

    Serializer that is compliant with the JSON API specification
    as documented here:

        http://jsonapi.org/
"""

import goldman
import json

from goldman.utils.url_helpers import rid_url
from ..serializers.base import Serializer as BaseSerializer


class Serializer(BaseSerializer):
    """ JSON API compliant serializer """

    MIMETYPE = goldman.JSONAPI_MIMETYPE

    def serialize(self, data):
        """ Determine & invoke the proper serializer method

        If data is a list then the serialize_datas method will
        be run otherwise serialize_data.
        """

        super(Serializer, self).serialize(data)

        body = {
            'jsonapi': {
                'version': goldman.config.JSONAPI_VERSION,
            },
            'links': {
                'self': self.req.path,
            },
            'meta': {
                'included-count': 0,
                'primary-count': 0,
                'total-primary': self.req.pages.total,
            },
        }

        included = data['included']
        if included:
            body['included'] = self._serialize_datas(included)
            body['meta']['included-count'] = len(included)

        _data = data['data']
        if isinstance(_data, list):
            body.update({'data': self._serialize_datas(_data)})
            body.update({'links': self._serialize_pages()})
            body['meta']['primary-count'] = len(_data)
        elif _data:
            body.update({'data': self._serialize_data(_data)})
            body['meta']['primary-count'] = 1
        else:
            body.update({'data': None})

        self.resp.body = json.dumps(body)

    def _serialize_datas(self, datas):
        """ Turn the list into JSON API compliant resource objects

        :spec:
            jsonapi.org/format/#document-top-level
        :param datas:
            list of dicts
        :return:
            list resources in JSON API format
        """

        return [self._serialize_data(data) for data in datas]

    def _serialize_data(self, data):
        """ Turn the data into a JSON API compliant resource object

        WARN: This function has both side effects & a return.
              It's complete shit because it mutates data &<commit_msg>renamed jsonapi serializer pagination keys<commit_after>"""
    serializers.jsonapi
    ~~~~~~~~~~~~~~~~~~~

    Serializer that is compliant with the JSON API specification
    as documented here:

        http://jsonapi.org/
"""

import goldman
import json

from goldman.utils.url_helpers import rid_url
from ..serializers.base import Serializer as BaseSerializer


class Serializer(BaseSerializer):
    """ JSON API compliant serializer """

    MIMETYPE = goldman.JSONAPI_MIMETYPE

    def serialize(self, data):
        """ Determine & invoke the proper serializer method

        If data is a list then the serialize_datas method will
        be run otherwise serialize_data.
        """

        super(Serializer, self).serialize(data)

        body = {
            'jsonapi': {
                'version': goldman.config.JSONAPI_VERSION,
            },
            'links': {
                'self': self.req.path,
            },
            'meta': {
                'included_count': 0,
                'primary_count': 0,
                'total_primary': self.req.pages.total,
            },
        }

        included = data['included']
        if included:
            body['included'] = self._serialize_datas(included)
            body['meta']['included_count'] = len(included)

        _data = data['data']
        if isinstance(_data, list):
            body.update({'data': self._serialize_datas(_data)})
            body.update({'links': self._serialize_pages()})
            body['meta']['primary_count'] = len(_data)
        elif _data:
            body.update({'data': self._serialize_data(_data)})
            body['meta']['primary_count'] = 1
        else:
            body.update({'data': None})

        self.resp.body = json.dumps(body)

    def _serialize_datas(self, datas):
        """ Turn the list into JSON API compliant resource objects

        :spec:
            jsonapi.org/format/#document-top-level
        :param datas:
            list of dicts
        :return:
            list resources in JSON API format
        """

        return [self._serialize_data(data) for data in datas]

    def _serialize_data(self, data):
        """ Turn the data into a JSON API compliant resource object

        WARN: This function has both side effects & a return.
              It's complete shit because it mutates data &
{'fraction_non_alphanumeric': 0.11218154570755727, 'fraction_numerical': 0.0012845215157353885, 'mean_word_length': 2.0122501611863313, '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': 2, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3720327', 'n_tokens_mistral': 1281, 'n_tokens_neox': 1188, 'n_words': 338}