<commit_before>from sqlalchemy import (
    Table,
    Column,
    Integer,
    Text,
    ForeignKey,
    Boolean
    )

from sqlalchemy.ext.declarative import declarative_base

from sqlalchemy.orm import (
    scoped_session,
    sessionmaker,
    relationship,
    validates,
    )


from zope.sqlalchemy import ZopeTransactionExtension


DBSession = scoped_session(sessionmaker(extension=ZopeTransactionExtension()))
Base = declarative_base()


usertaste_table = Table('user_profile', Base.metadata,
                        Column('users', Integer, ForeignKey('users.id')),
                        Column('profile', Integer, ForeignKey('profile.id'))
                        )


userdiet_table = Table('user_diet', Base.metadata,
                       Column('users', Integer, ForeignKey('users.id')),
                       Column('profile', Integer, ForeignKey('diet.id'))
                       )


usercost_table = Table('user_cost', Base.metadata,
                       Column('users', Integer, ForeignKey('users.id')),
                       Column('profile', Integer, ForeignKey('cost.id'))
                       )


groupdiscussion_table = Table('group_discussion', Base.metadata,
                              Column('group', Integer, ForeignKey('group.id')),
                              Column('discussion', Integer, ForeignKey(
                                     'discussion.id'))
                              )

groupage_table = Table('group_age', Base.metadata, Column('group', Integer,
                       ForeignKey('group.id')), Column('agegroup', Integer,
                       ForeignKey('agegroup.id'))
                       )

groupuser_table = Table('group_user', Base.metadata, Column('group', Integer,
                        ForeignKey('group.id')), Column('users', Integer,
                        ForeignKey('users.id'))
                        )


class Table(object):
    id = Column(Integer, primary_key=True, autoincrement=True)

    @classmethod
    def write(cls, session=None, **kwargs):
        if session is None:
            session = DBSession
        instance = cls(**kwargs)
        session.add(instance)
        return instance


class User(Base, Table):
    __tablename__ = 'users'
    username = Column(Text, nullable=False, unique=True)
    firstname = Column(Text, nullable=False)
    lastname = Column(Text, nullable=False)
    password = Column(Text, nullable=False)
    email = Column(Text, nullable=False, unique=True)
    confirmed = Column(Boolean)
    age = Column(Integer, ForeignKey('agegroup.id'))
    user_location = Column(Integer, ForeignKey('location.id'))
    food_profile = relationship('Profile', secondary=usertaste_table)
    diet_restrict = relationship('Diet', secondary=userdiet_table)
    cost_restrict = relationship('Cost', secondary=usercost_table)
    user_groups = relationship('Group', secondary=groupuser_table)
    restaurants = Column(Text)

    @validates('email')
    def validate_email(self, key, email):
        try:
            assert '@' in email
            assert '.' in email
            return email
        except:
            raise TypeError('Please enter a vaild email address')

    @classmethod
    def lookup_user(cls, username, session=None):
        if session is None:
            session = DBSession
        return session.query(cls).filter(username=username).all()

    def __repr__(self):
        return "<User({} {}, username={})>".format(self.firstname,
                                                   self.lastname,
                                                   self.username)


class Profile(Base, Table):
    __tablename__ = 'profile'
    taste = Column(Text)

    def __repr__(self):
        return "<Taste(%s)>" % (self.taste)


class AgeGroup(Base, Table):
    __tablename__ = 'agegroup'
    age_group = Column(Text)

    def __repr__(self):
        return "<Age(%s)>" % (self.age_group)


class Location(Base, Table):
    __tablename__ = 'location'
    city = Column(Text)

    def __repr__(self):
        return "<Location(%s)>" % (self.city)


class Cost(Base, Table):
    __tablename__ = 'cost'
    cost = Column(Text)

    def __repr__(self):
        return "<Cost(%s)>" % (self.cost)


class Diet(Base, Table):
    __tablename__ = 'diet'
    diet = Column(Text)

    def __repr__(self):
        return "<Dietary Preference(%s)>" % (self.diet)


class Group(Base, Table):
    __tablename__ = 'group'
    name = Column(Text, nullable=False)
    description = Column(Text, nullable=False)
    location = Column(Integer, ForeignKey('location.id'))
    discussion = relationship('Discussion', secondary=groupdiscussion_table)
    group_admin = relationship("Admin", uselist=False)

    def __repr__(self):
        return "<Group(%s, location=%s)>" % (self.name, self.location)


class Discussion(Base, Table):
    __tablename__ = 'discussion'
    discussion_title = Column(Text)

    def __repr__(self):
        return "<Discussion(%s)>" % (self.discussion_title)


class Post(Base, Table):
    __tablename__ = 'post'
    discussionpost = Column(Integer, ForeignKey('discussion.id'))

    def __repr__(self):
        return "<Post(%s)>" % (self.discussionpost)


class Admin(Base, Table):
    __tablename__ = 'admin'
    users = Column(Integer, ForeignKey('users.id'))
    group_id = Column(Integer, ForeignKey('group.id'))

    def __repr__(self):
        return "<Admin(%s)>" % (self.users)<commit_msg>update Table class to _Table<commit_after>from sqlalchemy import (
    Table,
    Column,
    Integer,
    Text,
    ForeignKey,
    Boolean
    )

from sqlalchemy.ext.declarative import declarative_base

from sqlalchemy.orm import (
    scoped_session,
    sessionmaker,
    relationship,
    validates,
    )


from zope.sqlalchemy import ZopeTransactionExtension


DBSession = scoped_session(sessionmaker(extension=ZopeTransactionExtension()))
Base = declarative_base()


usertaste_table = Table('user_profile', Base.metadata,
                        Column('users', Integer, ForeignKey('users.id')),
                        Column('profile', Integer, ForeignKey('profile.id'))
                        )


userdiet_table = Table('user_diet', Base.metadata,
                       Column('users', Integer, ForeignKey('users.id')),
                       Column('profile', Integer, ForeignKey('diet.id'))
                       )


usercost_table = Table('user_cost', Base.metadata,
                       Column('users', Integer, ForeignKey('users.id')),
                       Column('profile', Integer, ForeignKey('cost.id'))
                       )


groupdiscussion_table = Table('group_discussion', Base.metadata,
                              Column('group', Integer, ForeignKey('group.id')),
                              Column('discussion', Integer, ForeignKey(
                                     'discussion.id'))
                              )

groupage_table = Table('group_age', Base.metadata, Column('group', Integer,
                       ForeignKey('group.id')), Column('agegroup', Integer,
                       ForeignKey('agegroup.id'))
                       )

groupuser_table = Table('group_user', Base.metadata, Column('group', Integer,
                        ForeignKey('group.id')), Column('users', Integer,
                        ForeignKey('users.id'))
                        )


class _Table(object):
    id = Column(Integer, primary_key=True, autoincrement=True)

    @classmethod
    def write(cls, session=None, **kwargs):
        if session is None:
            session = DBSession
        instance = cls(**kwargs)
        session.add(instance)
        return instance


class User(Base, _Table):
    __tablename__ = 'users'
    username = Column(Text, nullable=False, unique=True)
    firstname = Column(Text, nullable=False)
    lastname = Column(Text, nullable=False)
    password = Column(Text, nullable=False)
    email = Column(Text, nullable=False, unique=True)
    confirmed = Column(Boolean)
    age = Column(Integer, ForeignKey('agegroup.id'))
    user_location = Column(Integer, ForeignKey('location.id'))
    food_profile = relationship('Profile', secondary=usertaste_table)
    diet_restrict = relationship('Diet', secondary=userdiet_table)
    cost_restrict = relationship('Cost', secondary=usercost_table)
    user_groups = relationship('Group', secondary=groupuser_table)
    restaurants = Column(Text)

    @validates('email')
    def validate_email(self, key, email):
        try:
            assert '@' in email
            assert '.' in email
            return email
        except:
            raise TypeError('Please enter a vaild email address')

    @classmethod
    def lookup_user(cls, username, session=None):
        if session is None:
            session = DBSession
        return session.query(cls).filter(username=username).all()

    def __repr__(self):
        return "<User({} {}, username={})>".format(self.firstname,
                                                   self.lastname,
                                                   self.username)


class Profile(Base, _Table):
    __tablename__ = 'profile'
    taste = Column(Text)

    def __repr__(self):
        return "<Taste(%s)>" % (self.taste)


class AgeGroup(Base, _Table):
    __tablename__ = 'agegroup'
    age_group = Column(Text)

    def __repr__(self):
        return "<Age(%s)>" % (self.age_group)


class Location(Base, _Table):
    __tablename__ = 'location'
    city = Column(Text)

    def __repr__(self):
        return "<Location(%s)>" % (self.city)


class Cost(Base, _Table):
    __tablename__ = 'cost'
    cost = Column(Text)

    def __repr__(self):
        return "<Cost(%s)>" % (self.cost)


class Diet(Base, _Table):
    __tablename__ = 'diet'
    diet = Column(Text)

    def __repr__(self):
        return "<Dietary Preference(%s)>" % (self.diet)


class Group(Base, _Table):
    __tablename__ = 'group'
    name = Column(Text, nullable=False)
    description = Column(Text, nullable=False)
    location = Column(Integer, ForeignKey('location.id'))
    discussion = relationship('Discussion', secondary=groupdiscussion_table)
    group_admin = relationship("Admin", uselist=False)

    def __repr__(self):
        return "<Group(%s, location=%s)>" % (self.name, self.location)


class Discussion(Base, _Table):
    __tablename__ = 'discussion'
    discussion_title = Column(Text)

    def __repr__(self):
        return "<Discussion(%s)>" % (self.discussion_title)


class Post(Base, _Table):
    __tablename__ = 'post'
    discussionpost = Column(Integer, ForeignKey('discussion.id'))

    def __repr__(self):
        return "<Post(%s)>" % (self.discussionpost)


class Admin(Base, _Table):
    __tablename__ = 'admin'
    users = Column(Integer, ForeignKey('users.id'))
    group_id = Column(Integer, ForeignKey('group.id'))

    def __repr__(self):
        return "<Admin(%s)>" % (self.users)
{'fraction_non_alphanumeric': 0.12334801762114538, 'fraction_numerical': 0.0, 'mean_word_length': 2.514027732989358, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1643974', 'n_tokens_mistral': 3127, 'n_tokens_neox': 3019, 'n_words': 643}