<commit_before>import datetime
import rfc822
import time
import uuid

from aspen import Response


BEGINNING_OF_EPOCH = rfc822.formatdate(0)
TIMEOUT = 60 * 60 * 24 * 7 # one week


class User:

    def __init__(self, session):
        """Takes a dict of user info.
        """
        self.session = session

    @classmethod
    def from_session_token(cls, token):
        session = cls.load_session("WHERE session_token=%s", token)
        return cls(session)

    @classmethod
    def from_id(cls, participant_id):
        from gittip import db
        session = cls.load_session("WHERE id=%s", participant_id)
        session['session_token'] = uuid.uuid4().hex
        db.execute( "UPDATE participants SET session_token=%s WHERE id=%s"
                  , (session['session_token'], participant_id)
                   )
        return cls(session)

    @staticmethod
    def load_session(where, val):
        from gittip import db
        SQL = "SELECT * FROM participants " + where
        rec = db.fetchone(SQL, (val,))
        out = {}
        if rec is not None:
            out = rec
        return out

    def __str__(self):
        return '<User: %s>' % getattr(self, 'id', 'Anonymous')
    __repr__ = __str__

    def __getattr__(self, name):
        return self.session.get(name)

    @property
    def ADMIN(self):
        return bool(self.session.get('is_admin', False))

    @property
    def ANON(self):
        return 'id' not in self.session

    @property<commit_msg>Prevent suspicious from logging in (#370)<commit_after>import datetime
import rfc822
import time
import uuid

from aspen import Response


BEGINNING_OF_EPOCH = rfc822.formatdate(0)
TIMEOUT = 60 * 60 * 24 * 7 # one week


class User:

    def __init__(self, session):
        """Takes a dict of user info.
        """
        self.session = session

    @classmethod
    def from_session_token(cls, token):
        session = cls.load_session("session_token=%s", token)
        return cls(session)

    @classmethod
    def from_id(cls, participant_id):
        from gittip import db
        session = cls.load_session("id=%s", participant_id)
        session['session_token'] = uuid.uuid4().hex
        db.execute( "UPDATE participants SET session_token=%s WHERE id=%s"
                  , (session['session_token'], participant_id)
                   )
        return cls(session)

    @staticmethod
    def load_session(where, val):
        from gittip import db
        SQL =("SELECT * FROM participants WHERE is_suspicious IS NOT true "
              "AND " + where)
        rec = db.fetchone(SQL, (val,))
        out = {}
        if rec is not None:
            out = rec
        return out

    def __str__(self):
        return '<User: %s>' % getattr(self, 'id', 'Anonymous')
    __repr__ = __str__

    def __getattr__(self, name):
        return self.session.get(name)

    @property
    def ADMIN(self):
        return bool(self.session.get('is_admin', False))

    @property
    def ANON(self):
        return 'id' not in self.session

    @property
{'fraction_non_alphanumeric': 0.10400262467191601, 'fraction_numerical': 0.010826771653543307, 'mean_word_length': 2.343201754385965, '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': '5685456', 'n_tokens_mistral': 952, 'n_tokens_neox': 909, 'n_words': 258}