<commit_before>""" Copyright 2012, 2013 UW Information Technology, University of Washington

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

    Changes
    =================================================================

    <EMAIL>: add JSONResponse subclass of HttpResponse;
        add some exceptions for subclass views to raise; simplify
        choosing a method to call; catch exceptions and return them
        to the client (always with an error field); move etag
        validation to here.
"""

from django.core.exceptions import ObjectDoesNotExist, ValidationError
from django.conf import settings
from django.http import HttpResponse
import simplejson as json
import traceback


class JSONResponse(HttpResponse):
    """
    A standard HttpResponse that will serialize the body to JSON
    and set the content-type to 'application/json'
    """

    def __init__(self, content='', *args, **kwargs):
        if content != '':
            if getattr(settings, 'DEBUG', False):
                content = json.dumps(content, sort_keys=True, indent=4 * ' ')
            else:
                content = json.dumps(content)

        if not kwargs.get('content_type', None):
            kwargs['content_type'] = 'application/json'

        super(JSONResponse, self).__init__(content, *args, **kwargs)


class RESTException(Exception):
    """
    Can be thrown inside RESTful methods. Accepts a specific
    status code to use, or 500 by default.
    """
    def __init__(self, message, status_code):<commit_msg>adds a pretty print boolean to settings.py to toggle json being pretty printed while developing<commit_after>""" Copyright 2012, 2013 UW Information Technology, University of Washington

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

    Changes
    =================================================================

    <EMAIL>: add JSONResponse subclass of HttpResponse;
        add some exceptions for subclass views to raise; simplify
        choosing a method to call; catch exceptions and return them
        to the client (always with an error field); move etag
        validation to here.
"""

from django.core.exceptions import ObjectDoesNotExist, ValidationError
from django.conf import settings
from django.http import HttpResponse
import simplejson as json
import traceback


class JSONResponse(HttpResponse):
    """
    A standard HttpResponse that will serialize the body to JSON
    and set the content-type to 'application/json'
    """

    def __init__(self, content='', *args, **kwargs):
        if content != '':
            if settings.DEBUG and settings.JSON_PRETTY_PRINT:
                content = json.dumps(content, sort_keys=True, indent=4 * ' ')
            else:
                content = json.dumps(content)

        if not kwargs.get('content_type', None):
            kwargs['content_type'] = 'application/json'

        super(JSONResponse, self).__init__(content, *args, **kwargs)


class RESTException(Exception):
    """
    Can be thrown inside RESTful methods. Accepts a specific
    status code to use, or 500 by default.
    """
    def __init__(self, message, status_code):
{'fraction_non_alphanumeric': 0.10091522157996147, 'fraction_numerical': 0.007707129094412331, 'mean_word_length': 3.255122950819672, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '201065', 'n_tokens_mistral': 1042, 'n_tokens_neox': 985, 'n_words': 443}