<commit_before>_session_factory = None


class SQLResource(object):
    """Base class for resources based on SQLAlchemy ORM models.

    """

    #: A SQLAlchemy query which is used to find a SQLAlchemy object.
    context_query = None

    def __init__(self, request):
        global _session_factory
        assert _session_factory is not None, \
                "config.set_sqlalchemy_session_factory must be called."
        params = request.matchdict
        self.context = _session_factory.execute(self.context_query, params).first()
        if self.context is None:
            raise KeyError('Resource not found')<commit_msg>Use an ABC for SQLResource<commit_after>import abc

_session_factory = None


class SQLResource(object):
    """Base class for resources based on SQLAlchemy ORM models.
    """

    __metaclass__ = abc.ABCMeta

    @abc.abstractproperty
    def context_query(self):
        """A SQLAlchemy query which is used to find a SQLAlchemy object.
        """
        raise NotImplemented()

    def __init__(self, request):
        global _session_factory
        assert _session_factory is not None, \
                "config.set_sqlalchemy_session_factory must be called."
        params = request.matchdict
        self.context = _session_factory.execute(self.context_query, params).first()
        if self.context is None:
            raise KeyError('Resource not found')
{'fraction_non_alphanumeric': 0.07428571428571429, 'fraction_numerical': 0.0, 'mean_word_length': 2.796747967479675, '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': '2105562', 'n_tokens_mistral': 389, 'n_tokens_neox': 371, 'n_words': 116}