<commit_before>import pickle
import uuid
from datetime import datetime
from datetime import timedelta

from werkzeug.datastructures import CallbackDict
from flask.sessions import SessionMixin
from flask.sessions import SessionInterface


class MongoDBSession(CallbackDict, SessionMixin):
    def __init__(self, initial=None, sid=None, new=True):
        def on_update(this):
            this.modified = True
        if initial:
            initial = pickle.loads(initial)
        CallbackDict.__init__(self, initial, on_update)
        self.sid = sid
        self.new = new
        self.modified = False

    def pickle(self):
        return pickle.dumps(dict(self))


class MongoDBSessionInterface(SessionInterface):
    session_class = MongoDBSession

    def __init__(self, app, mongo, collection_name):
        self._mongo = mongo
        self._collection_name = collection_name

        if app is not None:
            self.app = app
            self.init_app(app)
        else:
            self.app = None

    def init_app(self, app):
        if not hasattr(app, 'extensions'):
            app.extensions = {}
        app.extensions['mongodb-session'] = self

    def open_session(self, app, request):
        sid = request.cookies.get(app.session_cookie_name)
        if not sid:
            sid = self.__generate_sid()
            return self.session_class(sid=sid)

        doc = self.__get_collection().find_one({'_id': sid})
        # Check if exists and not expired.
        # It's ok to remove tzinfo here, because utcnow() returns UTC time,
        # despite it's in naive form (without tzinfo).
        if doc and doc['exp'].replace(tzinfo=None) > datetime.utcnow():
            session = self.session_class(initial=doc['d'], sid=sid)
        else:
            # If the SID doesn't exist - create a new one to avoid possibility
            # of user-generated SID with invalid format (e.g. "abc123").
            sid = self.__generate_sid()
            session = self.session_class(sid=sid)
        return session

    def save_session(self, app, session, response):
        # cookie_domain = self.get_cookie_domain(app)<commit_msg>The key in extensions dict changed<commit_after>import pickle
import uuid
from datetime import datetime
from datetime import timedelta

from werkzeug.datastructures import CallbackDict
from flask.sessions import SessionMixin
from flask.sessions import SessionInterface


class MongoDBSession(CallbackDict, SessionMixin):
    def __init__(self, initial=None, sid=None, new=True):
        def on_update(this):
            this.modified = True
        if initial:
            initial = pickle.loads(initial)
        CallbackDict.__init__(self, initial, on_update)
        self.sid = sid
        self.new = new
        self.modified = False

    def pickle(self):
        return pickle.dumps(dict(self))


class MongoDBSessionInterface(SessionInterface):
    session_class = MongoDBSession

    def __init__(self, app, mongo, collection_name):
        self._mongo = mongo
        self._collection_name = collection_name

        if app is not None:
            self.app = app
            self.init_app(app)
        else:
            self.app = None

    def init_app(self, app):
        if not hasattr(app, 'extensions'):
            app.extensions = {}
        app.extensions['mongodb-sessions'] = self

    def open_session(self, app, request):
        sid = request.cookies.get(app.session_cookie_name)
        if not sid:
            sid = self.__generate_sid()
            return self.session_class(sid=sid)

        doc = self.__get_collection().find_one({'_id': sid})
        # Check if exists and not expired.
        # It's ok to remove tzinfo here, because utcnow() returns UTC time,
        # despite it's in naive form (without tzinfo).
        if doc and doc['exp'].replace(tzinfo=None) > datetime.utcnow():
            session = self.session_class(initial=doc['d'], sid=sid)
        else:
            # If the SID doesn't exist - create a new one to avoid possibility
            # of user-generated SID with invalid format (e.g. "abc123").
            sid = self.__generate_sid()
            session = self.session_class(sid=sid)
        return session

    def save_session(self, app, session, response):
        # cookie_domain = self.get_cookie_domain(app)
{'fraction_non_alphanumeric': 0.08985641500694766, 'fraction_numerical': 0.0013895321908290875, 'mean_word_length': 2.5, 'pattern_counts': {'":': 0, '<': 3, '<?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': '6322591', 'n_tokens_mistral': 1237, 'n_tokens_neox': 1193, 'n_words': 342}