<commit_before>import jwt
from django.utils.encoding import smart_text
from rest_framework import exceptions
from rest_framework.authentication import BaseAuthentication, get_authorization_header
from rest_framework_jwt.settings import api_settings
from rest_framework_jwt.utils import jwt_decode_handler


class User(object):
    '''
    A class that emulates Django's auth User, for use with microservices where
    the actual User is unavailable. Surfaces via `request.user`.
    '''

    def __init__(self, **kwargs):
        for kwarg in kwargs:
            setattr(self, kwarg, kwargs[kwarg])

    def is_authenticated(self):
        return True

    def get_roles(self):
        '''
            Note: For testing purposes only
                  https://github.com/ZeroCater/mp-users/blob/master/users/models.py
        '''
        return self.roles


class JWTAuthentication(BaseAuthentication):
    """
        Clients should authenticate by passing the token key in the "Authorization"
        HTTP header, prepended with the string specified in the setting
        `JWT_AUTH_HEADER_PREFIX`. For example:

            Authorization: JWT <KEY>
    """
    www_authenticate_realm = 'api'

    def get_jwt_value(self, request):
        auth = get_authorization_header(request).split()
        auth_header_prefix = api_settings.JWT_AUTH_HEADER_PREFIX.lower()

        if not auth or smart_text(auth[0].lower()) != auth_header_prefix:
            return None

        if len(auth) == 1:  # pragma: no cover
            msg = 'Invalid Authorization header. No credentials provided.'
            raise exceptions.AuthenticationFailed(msg)<commit_msg>Extend get_roles note<commit_after>import jwt
from django.utils.encoding import smart_text
from rest_framework import exceptions
from rest_framework.authentication import BaseAuthentication, get_authorization_header
from rest_framework_jwt.settings import api_settings
from rest_framework_jwt.utils import jwt_decode_handler


class User(object):
    '''
    A class that emulates Django's auth User, for use with microservices where
    the actual User is unavailable. Surfaces via `request.user`.
    '''

    def __init__(self, **kwargs):
        for kwarg in kwargs:
            setattr(self, kwarg, kwargs[kwarg])

    def is_authenticated(self):
        return True

    def get_roles(self):
        '''
            Note: For testing purposes only. Emulates `get_roles` in
                  https://github.com/ZeroCater/mp-users/blob/master/users/models.py
        '''
        return self.roles


class JWTAuthentication(BaseAuthentication):
    """
        Clients should authenticate by passing the token key in the "Authorization"
        HTTP header, prepended with the string specified in the setting
        `JWT_AUTH_HEADER_PREFIX`. For example:

            Authorization: JWT eyJhbGciOiAiSFMyNTYiLCAidHlwIj
    """
    www_authenticate_realm = 'api'

    def get_jwt_value(self, request):
        auth = get_authorization_header(request).split()
        auth_header_prefix = api_settings.JWT_AUTH_HEADER_PREFIX.lower()

        if not auth or smart_text(auth[0].lower()) != auth_header_prefix:
            return None

        if len(auth) == 1:  # pragma: no cover
            msg = 'Invalid Authorization header. No credentials provided.'
            raise exceptions.AuthenticationFailed(msg)
{'fraction_non_alphanumeric': 0.0752528256989887, 'fraction_numerical': 0.001189767995240928, 'mean_word_length': 3.046931407942238, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 2, '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': '113008', 'n_tokens_mistral': 941, 'n_tokens_neox': 908, 'n_words': 264}