<commit_before>"""
sentry.middleware.sudo
~~~~~~~~~~~~~~~~~~~~~~

:copyright: (c) 2010-2014 by the Sentry Team, see AUTHORS for more details.
:license: BSD, see LICENSE for more details.
"""
from sentry.utils.sudo import has_sudo_privileges, SUDO_COOKIE_NAME


class SudoMiddleware(object):
    def process_request(self, request):
        request._sentry_sudo = None
        request.is_sudo = lambda: has_sudo_privileges(request)

    def process_response(self, request, response):
        is_sudo = request._sentry_sudo

        if is_sudo is None:
            return response

        # We have explicitly had sudo revoked, so clean up cookie
        if is_sudo is False and SUDO_COOKIE_NAME in request.COOKIES:<commit_msg>Don't assume _sentry_sudo exists<commit_after>"""
sentry.middleware.sudo
~~~~~~~~~~~~~~~~~~~~~~

:copyright: (c) 2010-2014 by the Sentry Team, see AUTHORS for more details.
:license: BSD, see LICENSE for more details.
"""
from sentry.utils.sudo import has_sudo_privileges, SUDO_COOKIE_NAME


class SudoMiddleware(object):
    def process_request(self, request):
        request._sentry_sudo = None
        request.is_sudo = lambda: has_sudo_privileges(request)

    def process_response(self, request, response):
        is_sudo = getattr(request, '_sentry_sudo', None)

        if is_sudo is None:
            return response

        # We have explicitly had sudo revoked, so clean up cookie
        if is_sudo is False and SUDO_COOKIE_NAME in request.COOKIES:
{'fraction_non_alphanumeric': 0.10221923335574983, 'fraction_numerical': 0.010759919300605245, 'mean_word_length': 3.694006309148265, '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': '3925594', 'n_tokens_mistral': 486, 'n_tokens_neox': 441, 'n_words': 136}