<commit_before># -*- coding: utf-8 -*-
# -*- test-case-name: go.api.go_api.tests.test_session -*-

from django.conf import settings
from django.contrib.sessions.backends.base import SessionBase, CreateError
from vumi.persist.redis_manager import RedisManager

from go.api.go_api.session_manager import SessionManager


class SessionStore(SessionBase):
    """
    Implements redis session store on top of `go.api.go_api.session_manager`.
    """
    def __init__(self, session_key=None):
        super(SessionStore, self).__init__(session_key)
        redis_config = settings.VUMI_API_CONFIG.get('redis_manager', {})
        redis = RedisManager.from_config(redis_config)
        self.session_manager = SessionManager(
            redis.sub_manager('session_manager'))

    def encode(self, data):
        """Replace Django's pickle serialization with a null-op.

        The SessionManager can store any JSON serializable object.
        """
        return data

    def decode(self, data):
        """Replace Django's pickle serialization with a null-op.

        The SessionManager can store any JSON serializable object.
        """
        return data

    def load(self):<commit_msg>Use base.utils.get_redis_manager() in go_api.session as well.<commit_after># -*- coding: utf-8 -*-
# -*- test-case-name: go.api.go_api.tests.test_session -*-

from django.contrib.sessions.backends.base import SessionBase, CreateError

from go.base.utils import get_redis_manager
from go.api.go_api.session_manager import SessionManager


class SessionStore(SessionBase):
    """
    Implements redis session store on top of `go.api.go_api.session_manager`.
    """
    def __init__(self, session_key=None):
        super(SessionStore, self).__init__(session_key)
        self.session_manager = SessionManager(
            get_redis_manager().sub_manager('session_manager'))

    def encode(self, data):
        """Replace Django's pickle serialization with a null-op.

        The SessionManager can store any JSON serializable object.
        """
        return data

    def decode(self, data):
        """Replace Django's pickle serialization with a null-op.

        The SessionManager can store any JSON serializable object.
        """
        return data

    def load(self):
{'fraction_non_alphanumeric': 0.09995596653456627, 'fraction_numerical': 0.0008806693086745927, 'mean_word_length': 3.153564899451554, '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': '7426835', 'n_tokens_mistral': 656, 'n_tokens_neox': 636, 'n_words': 168}