<commit_before>#!/usr/bin/env python
#fileencoding=utf-8

import re
import time
import random
import string
import hashlib
import logging

from tornado.web import RequestHandler
from tornado.web import HTTPError
from tornado.escape import json_decode
from tornado.options import options

from bson.json_util import dumps, loads
from bson.objectid import ObjectId
from pymongo.errors import DuplicateKeyError

from lib.mail import send as send_mail

from lib import data_file

class BaseHandler(RequestHandler):
    allow_anony = False
    prefix = ''
    roles = [
        ('Admin', 100),
        ('Editor', 101),
        ('Subscriber', 102),
    ]

    def has_permission(self, path):
        if path  == '/users' or path.startswith('/user/'):
            return self.current_user and self.r % 100 == 0
        return True

    def prepare(self):
        uri = self.request.uri
        path = self.request.path
        user = self.current_user
        logging.info('user:%s is accessing %s', user, uri)

        if user is None and not self.allow_anony:
            self.redirect(self.get_login_url())
            return

        if not self.allow_anony and not self.has_permission(path):
            raise HTTPError(403)

    def get_login_url(self):
        return '/signin'

    def get_logout_url(self):
        return '/signout'

    def get_main_domain(self):
        return self.request.host.split(':')[0]

    def get_current_user(self):
        if options.debug:
            return dict(role=0, email='<EMAIL>')

        user_json = self.get_secure_cookie("user")
        if user_json:
            user = json_decode(user_json)
            if user['login_sn'] == self.get_cookie("login_sn"):
                return user
            else:
                self.clear_cookie('user', domain=self.get_main_domain())
        else:
            self.clear_cookie('user', domain=self.get_main_domain())

        return None

    def has_argument(self, name):<commit_msg>Make banning take effect immediately.<commit_after>#!/usr/bin/env python
#fileencoding=utf-8

import re
import time
import random
import string
import hashlib
import logging

from tornado.web import RequestHandler
from tornado.web import HTTPError
from tornado.escape import json_decode
from tornado.options import options

from bson.json_util import dumps, loads
from bson.objectid import ObjectId
from pymongo.errors import DuplicateKeyError

from lib.mail import send as send_mail

from lib import data_file

class BaseHandler(RequestHandler):
    allow_anony = False
    prefix = ''
    roles = [
        ('Admin', 100),
        ('Editor', 101),
        ('Subscriber', 102),
    ]

    def has_permission(self, path):
        if path  == '/users' or path.startswith('/user/'):
            return self.current_user and self.r % 100 == 0
        return True

    def prepare(self):
        uri = self.request.uri
        path = self.request.path
        user = self.current_user
        logging.info('user:%s is accessing %s', user, uri)

        if user is None and not self.allow_anony:
            self.redirect(self.get_login_url())
            return

        if not self.allow_anony and not self.has_permission(path):
            raise HTTPError(403)

    def get_login_url(self):
        return '/signin'

    def get_logout_url(self):
        return '/signout'

    def get_main_domain(self):
        return self.request.host.split(':')[0]

    def get_current_user(self):
        if options.debug:
            return dict(role=0, email='<EMAIL>')

        user_json = self.get_secure_cookie("user")
        if user_json:
            user = json_decode(user_json)
            user_db = self.db.user.find_one({'mail': user['email']})
            if user_db and user_db['valid'] and user['login_sn'] == self.get_cookie("login_sn"):
                return user

        self.clear_cookie('user', domain=self.get_main_domain())
        return None

    def has_argument(self, name):
{'fraction_non_alphanumeric': 0.09952008082849205, 'fraction_numerical': 0.00959838343015913, 'mean_word_length': 2.5707844905320107, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4347147', 'n_tokens_mistral': 1214, 'n_tokens_neox': 1157, 'n_words': 314}