<commit_before>from rest_framework.pagination import PageNumberPagination, _positive_int
from rest_framework.response import Response
from rest_framework.settings import api_settings


class GeoReportV2Pagination(PageNumberPagination):
    max_page_size = getattr(api_settings, 'MAX_PAGE_SIZE', 500)
    page_size_query_params = ('per_page', 'page_size')

    def get_paginated_response(self, data):
        return Response(
            data,
            headers={
                'X-Next-Page-URL': self.get_next_link(),
                'X-Page-Count': self.page.paginator.num_pages,
                'X-Page-Size': self.page.paginator.per_page,
                'X-Previous-Page-URL': self.get_previous_link(),
                'X-Result-Count': self.page.paginator.count,
            }
        )

    def get_page_size(self, request):
        for param in self.page_size_query_params:
            try:
                return _positive_int(
                    request.query_params[param],
                    strict=True,
                    cutoff=self.max_page_size
                )
            except (KeyError, ValueError):
                pass

        return self.page_size<commit_msg>Pagination: Don't show headers that have falsy values<commit_after>from rest_framework.pagination import PageNumberPagination, _positive_int
from rest_framework.response import Response
from rest_framework.settings import api_settings


class GeoReportV2Pagination(PageNumberPagination):
    max_page_size = getattr(api_settings, 'MAX_PAGE_SIZE', 500)
    page_size_query_params = ('per_page', 'page_size')

    def get_paginated_response(self, data):
        return Response(
            data,
            headers=dict(
                (key, value)
                for (key, value) in {
                    'X-Next-Page-URL': self.get_next_link(),
                    'X-Page-Count': self.page.paginator.num_pages,
                    'X-Page-Size': self.page.paginator.per_page,
                    'X-Previous-Page-URL': self.get_previous_link(),
                    'X-Result-Count': self.page.paginator.count,
                }.items()
                if (key and value)
            ))

    def get_page_size(self, request):
        for param in self.page_size_query_params:
            try:
                return _positive_int(
                    request.query_params[param],
                    strict=True,
                    cutoff=self.max_page_size
                )
            except (KeyError, ValueError):
                pass

        return self.page_size
{'fraction_non_alphanumeric': 0.08687183482664589, 'fraction_numerical': 0.0031164783794312427, 'mean_word_length': 1.91156462585034, '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': '2609545', 'n_tokens_mistral': 737, 'n_tokens_neox': 697, 'n_words': 133}