<commit_before>from __future__ import absolute_import

__all__ = ('ApiClient',)

from rest_framework.test import (
    APIClient as DefaultRequestClient, ForceAuthClientHandler
)

from sentry.utils import json


class ApiError(Exception):
    def __init__(self, status_code, body):
        self.status_code = status_code
        self.body = body

    def __unicode__(self):
        return u'status=%s body=%s' % (self.status_code, self.body)

    @property
    def status(self):
        return self.status_code


class ApiClientHandler(ForceAuthClientHandler):
    def __init__(self, is_sudo=False, *args, **kwargs):
        self.is_sudo = is_sudo
        super(ApiClientHandler, self).__init__(*args, **kwargs)

    def get_response(self, request):
        # This is the simplest place we can hook into to patch the
        # request object.
        request._sudo = self.is_sudo<commit_msg>Handle encoding correctly on ApiError<commit_after>from __future__ import absolute_import

__all__ = ('ApiClient',)

from rest_framework.test import (
    APIClient as DefaultRequestClient, ForceAuthClientHandler
)

from sentry.utils import json


class ApiError(Exception):
    def __init__(self, status_code, body):
        self.status_code = status_code
        self.body = body

    def __unicode__(self):
        return u'status=%s body=%s' % (self.status_code, self.body)

    def __str__(self):
        return unicode(self).encode('utf-8')

    @property
    def status(self):
        return self.status_code


class ApiClientHandler(ForceAuthClientHandler):
    def __init__(self, is_sudo=False, *args, **kwargs):
        self.is_sudo = is_sudo
        super(ApiClientHandler, self).__init__(*args, **kwargs)

    def get_response(self, request):
        # This is the simplest place we can hook into to patch the
        # request object.
        request._sudo = self.is_sudo
{'fraction_non_alphanumeric': 0.09226666666666666, 'fraction_numerical': 0.0005333333333333334, 'mean_word_length': 3.403755868544601, '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': '5867358', 'n_tokens_mistral': 567, 'n_tokens_neox': 551, 'n_words': 147}