<commit_before>import zlib

from colander import Invalid
from ichnaea.exceptions import BaseJSONError
from pyramid.httpexceptions import HTTPError
from pyramid.response import Response

from ichnaea.customjson import (
    dumps,
    loads,
)

MSG_EMPTY = 'No JSON body was provided.'
MSG_GZIP = 'Error decompressing gzip data stream.'
MSG_ONE_OF = 'You need to provide a mapping with least one cell or wifi entry.'
MSG_BAD_RADIO = 'Radio fields were not consistent in the cellTower data.'


class JSONError(HTTPError, BaseJSONError):
    def __init__(self, errors, status=400):
        body = {'errors': errors}
        Response.__init__(self, dumps(body))
        self.status = status
        self.content_type = 'application/json'

PARSE_ERROR = {"error": {"errors": [{
    "domain": "global",
    "reason":
    "parseError",
    "message":
    "Parse Error",
    }],
    "code": 400,
    "message": "Parse Error"
    }
    }

PARSE_ERROR = dumps(PARSE_ERROR)


class JSONParseError(HTTPError, BaseJSONError):
    def __init__(self, errors, status=400):
        Response.__init__(self, PARSE_ERROR)
        self.status = status
        self.content_type = 'application/json'


def preprocess_request(request, schema, extra_checks=(), response=JSONError,
                       accept_empty=False):
    body = {}
    errors = []
    validated = {}

    body = request.body
    if body:
        if request.headers.get('Content-Encoding') == 'gzip':
            # handle gzip request bodies
            try:<commit_msg>whitespace<commit_after>import zlib

from colander import Invalid
from ichnaea.exceptions import BaseJSONError
from pyramid.httpexceptions import HTTPError
from pyramid.response import Response

from ichnaea.customjson import (
    dumps,
    loads,
)

MSG_EMPTY = 'No JSON body was provided.'
MSG_GZIP = 'Error decompressing gzip data stream.'
MSG_ONE_OF = 'You need to provide a mapping with least one cell or wifi entry.'
MSG_BAD_RADIO = 'Radio fields were not consistent in the cellTower data.'


class JSONError(HTTPError, BaseJSONError):
    def __init__(self, errors, status=400):
        body = {'errors': errors}
        Response.__init__(self, dumps(body))
        self.status = status
        self.content_type = 'application/json'

PARSE_ERROR = {"error": {
    "errors": [{
        "domain": "global",
        "reason":
        "parseError",
        "message":
        "Parse Error",
    }],
    "code": 400,
    "message": "Parse Error"
}}

PARSE_ERROR = dumps(PARSE_ERROR)


class JSONParseError(HTTPError, BaseJSONError):
    def __init__(self, errors, status=400):
        Response.__init__(self, PARSE_ERROR)
        self.status = status
        self.content_type = 'application/json'


def preprocess_request(request, schema, extra_checks=(), response=JSONError,
                       accept_empty=False):
    body = {}
    errors = []
    validated = {}

    body = request.body
    if body:
        if request.headers.get('Content-Encoding') == 'gzip':
            # handle gzip request bodies
            try:
{'fraction_non_alphanumeric': 0.10553916748607015, 'fraction_numerical': 0.0058997050147492625, 'mean_word_length': 3.0317040951122856, 'pattern_counts': {'":': 14, '<': 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': '204958', 'n_tokens_mistral': 932, 'n_tokens_neox': 905, 'n_words': 251}