<commit_before># -*- coding: utf-8 -*-

from token import Token
from jose import jwt
from os import urandom

class JWT(Token):
    """JSON Web Token"""

    def __init__(self, *args, **kwargs):
        super(JWT, self).__init__(*args, **kwargs)

        self.algorithm = 'HS256'
        self.context['username'] = self.username

        if not 'salt' in self.context:
            self.context['salt'] = urandom(256).encode('base-64')

    def generate(self):
        return jwt.encode(self.context,
                          self.secret_key,
                          algorithm=self.algorithm)

    def validate(self, token, **validation_context):
        context = jwt.decode(token,
                             self.secret_key,
                             algorithms=[self.algorithm])

        if ('ip' in validation_context and
            not context['ip'] == validation_context['ip']):
            return False

        return True
        <commit_msg>fix JSON Web Token token/jwt.py<commit_after># -*- coding: utf-8 -*-

from token import Token
from jose import jwt
from os import urandom

class JWT(Token):
    """JSON Web Token"""

    def __init__(self, *args, **kwargs):
        super(JWT, self).__init__(*args, **kwargs)

        self.algorithm = 'HS256'

    def generate(self):
        data = self.context.copy()
        data['username'] = self.username

        return jwt.encode(data,
                          self.secret_key,
                          algorithm=self.algorithm)

    def validate(self, token, **validation_context):
        context = jwt.decode(token,
                             self.secret_key,
                             algorithms=[self.algorithm])

        if ('ip' in validation_context and
            not context['ip'] == validation_context['ip']):
            return False

        return True
        
{'fraction_non_alphanumeric': 0.11525974025974026, 'fraction_numerical': 0.007034632034632035, 'mean_word_length': 1.827217125382263, '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': '78787', 'n_tokens_mistral': 511, 'n_tokens_neox': 489, 'n_words': 127}