<commit_before># -*- coding: UTF-8 -*-
# Copyright 2017-2021 Rumma & Ko Ltd
# License: BSD (see file COPYING for details)

from datetime import timedelta
from lino.utils import get_client_ip_address
from lino.api import ad

class IPRecord(object):
    def __init__(self, addr):
        self.addr = addr
        self.login_failures = 0
        self.blacklisted_since = None
        self.last_login = None
        self.last_failure = None
        self.last_request = None

    def __repr__(self):  # just for debugging
        return "{} {} {} {}".format(
            self.addr, self.login_failures,
            self.last_failure, self.blacklisted_since)


class Plugin(ad.Plugin):

    max_blacklist_time = timedelta(minutes=1)
    max_failed_auth_per_ip = 4 # Should be set in settings.SITE?
    ip_records = {}

    def get_ip_record(self, request):
        addr = get_client_ip_address(request)
        rec = self.ip_records.get(addr, None)
        if rec is None:
            rec = IPRecord(addr)
            self.ip_records[addr] = rec
        return rec<commit_msg>remove ipdict.IPRecord.last_request<commit_after># -*- coding: UTF-8 -*-
# Copyright 2017-2021 Rumma & Ko Ltd
# License: BSD (see file COPYING for details)

from datetime import timedelta
from lino.utils import get_client_ip_address
from lino.api import ad

class IPRecord(object):
    def __init__(self, addr):
        self.addr = addr
        self.login_failures = 0
        self.blacklisted_since = None
        # self.last_login = None
        # self.last_failure = None
        # self.last_request = None

    def __repr__(self):  # just for debugging
        return "{} {} {}".format(
            self.addr, self.login_failures, self.blacklisted_since)


class Plugin(ad.Plugin):

    max_blacklist_time = timedelta(minutes=1)
    max_failed_auth_per_ip = 4 # Should be set in settings.SITE?
    ip_records = {}

    def get_ip_record(self, request):
        addr = get_client_ip_address(request)
        rec = self.ip_records.get(addr, None)
        if rec is None:
            rec = IPRecord(addr)
            self.ip_records[addr] = rec
        return rec
{'fraction_non_alphanumeric': 0.09418931583880037, 'fraction_numerical': 0.011246485473289597, 'mean_word_length': 2.606418918918919, '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': '7634798', 'n_tokens_mistral': 690, 'n_tokens_neox': 661, 'n_words': 169}