<commit_before>from sqlalchemy import Column, ForeignKey, Integer, String, UnicodeText, \
        DateTime, Unicode, desc, func
import datetime
import hashlib

import ctfengine.config
import ctfengine.database


class FlagEntry(ctfengine.database.Base):
    __tablename__ = "flag_entries"
    id = Column(Integer, primary_key=True)
    handle = Column(Integer, ForeignKey('handles.id'))
    hostname = Column(Unicode(255))
    datetime = Column(DateTime(), default=datetime.datetime.now)
    ip = Column(String(255))
    user_agent = Column(Unicode(255))

    def __init__(self, handle, hostname, ip="", user_agent=""):
        self.handle = handle
        self.hostname = hostname
        self.ip = ip
        self.user_agent = user_agent

    def __repr__(self):
        return '<FlagEntry: {0:d}: {1}: {2}>'.format(self.handle,
                self.hostname, self.datetime)

    def serialize(self):
        return {
            'handle': self.handle,
            'hostname': self.hostname,
            'datetime': str(self.datetime),
        }


class Handle(ctfengine.database.Base):
    __tablename__ = "handles"
    id = Column(Integer, primary_key=True)
    handle = Column(UnicodeText())
    score = Column(Integer)

    def __init__(self, handle, score):
        self.handle = handle
        self.score = score

    @staticmethod
    def get(handle):
        return Handle.query.filter(Handle.handle == handle).first()

    @staticmethod
    def topscores(lim=25):
        return Handle.query.order_by(desc(Handle.score)).limit(lim)

    def __repr__(self):
        return '<Handle: {0}: {1:d}>'.format(self.handle, self.score)

    def serialize(self):
        return {
            'handle': self.handle,
            'score': self.score,
        }


class Flag(ctfengine.database.Base):
    __tablename__ = "flags"
    id = Column(Integer, primary_key=True)
    hostname = Column(UnicodeText())
    ip = Column(String)
    flag = Column(String(128), index=True, nullable=False)
    points = Column(Integer)

    def __init__(self, hostname, ip, flag, points):
        h = hashlib.sha512()
        h.update(flag + ctfengine.config.SALT)

        self.hostname = hostname
        self.ip = ip
        self.flag = h.hexdigest()
        self.points = points

    @staticmethod
    def get(flag):<commit_msg>size limit on IP address field<commit_after>from sqlalchemy import Column, ForeignKey, Integer, String, UnicodeText, \
        DateTime, Unicode, desc, func
import datetime
import hashlib

import ctfengine.config
import ctfengine.database


class FlagEntry(ctfengine.database.Base):
    __tablename__ = "flag_entries"
    id = Column(Integer, primary_key=True)
    handle = Column(Integer, ForeignKey('handles.id'))
    hostname = Column(Unicode(255))
    datetime = Column(DateTime(), default=datetime.datetime.now)
    ip = Column(String(255))
    user_agent = Column(Unicode(255))

    def __init__(self, handle, hostname, ip="", user_agent=""):
        self.handle = handle
        self.hostname = hostname
        self.ip = ip
        self.user_agent = user_agent

    def __repr__(self):
        return '<FlagEntry: {0:d}: {1}: {2}>'.format(self.handle,
                self.hostname, self.datetime)

    def serialize(self):
        return {
            'handle': self.handle,
            'hostname': self.hostname,
            'datetime': str(self.datetime),
        }


class Handle(ctfengine.database.Base):
    __tablename__ = "handles"
    id = Column(Integer, primary_key=True)
    handle = Column(UnicodeText())
    score = Column(Integer)

    def __init__(self, handle, score):
        self.handle = handle
        self.score = score

    @staticmethod
    def get(handle):
        return Handle.query.filter(Handle.handle == handle).first()

    @staticmethod
    def topscores(lim=25):
        return Handle.query.order_by(desc(Handle.score)).limit(lim)

    def __repr__(self):
        return '<Handle: {0}: {1:d}>'.format(self.handle, self.score)

    def serialize(self):
        return {
            'handle': self.handle,
            'score': self.score,
        }


class Flag(ctfengine.database.Base):
    __tablename__ = "flags"
    id = Column(Integer, primary_key=True)
    hostname = Column(UnicodeText())
    ip = Column(String(255))
    flag = Column(String(128), index=True, nullable=False)
    points = Column(Integer)

    def __init__(self, hostname, ip, flag, points):
        h = hashlib.sha512()
        h.update(flag + ctfengine.config.SALT)

        self.hostname = hostname
        self.ip = ip
        self.flag = h.hexdigest()
        self.points = points

    @staticmethod
    def get(flag):
{'fraction_non_alphanumeric': 0.12387096774193548, 'fraction_numerical': 0.01010752688172043, 'mean_word_length': 2.75686591276252, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '3055423', 'n_tokens_mistral': 1456, 'n_tokens_neox': 1409, 'n_words': 310}