<commit_before># TODO: Make session a dict of class names and session...
# TODO: Make sessions a dict of dict of classname and sessions
# TODO: Test to make sure session and sessions aren't shared between Subclasses
from .exceptions import PillowtalkSessionError

class SessionManagerHook(type):
    #
    def __init__(cls, name, bases, clsdict):
        cls.session = None
        cls.sessions = {}
        super(SessionManagerHook, cls).__init__(name, bases, clsdict)

    def __getattr__(cls, item):
        sessions = object.__getattribute__(cls, "sessions")
        if item in sessions:
            cls.set(item)
        else:
            try:
                return object.__getattribute__(cls, item)
            except AttributeError:
                msg = "Attribute \"{0}\" not found.".format(item)
                if sessions is None or sessions == []:
                    msg += " There are no sessions available."
                else:
                    msg += " Available sessions: {0}.".format(sessions.keys())
                raise AttributeError(msg)


class SessionManager(object, metaclass=SessionManagerHook):
    """ Session manager """

    session = None
    sessions = {}

    @classmethod
    def register_connector(cls, api_connector_instance, session_name=None):
        cls.session = api_connector_instance
        cls._add_session(cls.session, session_name)
        cls.set(session_name)

    @classmethod
    def _add_session(cls, api_connector, name):
        if cls.sessions is None:
            cls.sessions = {}
        cls.sessions[name] = api_connector

    @classmethod
    def set(cls, name):
        if cls.sessions is None:
            raise PillowtalkSessionError("No sessions found.")
        if name not in cls.sessions:
            raise PillowtalkSessionError("Session named {} not found. Choose from {}".format(name, cls.sessions.keys()))
        cls.session = cls.sessions[name]

    @classmethod
    def empty(cls):
        return cls.sessions is None or cls.sessions == {}

    @classmethod
    def session_name(cls):
        for name, session in cls.sessions.items():
            if cls.session == session:
                return name

    @classmethod
    def close(cls):
        cls.session = None

    @classmethod
    def reset(cls):
        cls.sessions = {}
        cls.session = None<commit_msg>update to documentation<commit_after># TODO: Make session a dict of class names and session...
# TODO: Make sessions a dict of dict of classname and sessions
# TODO: Test to make sure session and sessions aren't shared between Subclasses
from .exceptions import PillowtalkSessionError

class SessionManagerHook(type):
    #
    def __init__(cls, name, bases, clsdict):
        cls.session = None
        cls.sessions = {}
        super(SessionManagerHook, cls).__init__(name, bases, clsdict)

    def __getattr__(cls, item):
        sessions = object.__getattribute__(cls, "sessions")
        if item in sessions:
            cls.set(item)
        else:
            try:
                return object.__getattribute__(cls, item)
            except AttributeError:
                msg = "Attribute \"{0}\" not found.".format(item)
                if sessions is None or sessions == []:
                    msg += " There are no sessions available."
                else:
                    msg += " Available sessions: {0}.".format(sessions.keys())
                raise AttributeError(msg)


class SessionManager(object, metaclass=SessionManagerHook):
    """ Session manager """

    session = None
    sessions = {}

    @classmethod
    def register_connector(cls, api_connector_instance, session_name=None):
        """ registers an api_connector instance with session_name """
        cls.session = api_connector_instance
        cls._add_session(cls.session, session_name)
        cls.set(session_name)

    @classmethod
    def _add_session(cls, api_connector, name):
        if cls.sessions is None:
            cls.sessions = {}
        cls.sessions[name] = api_connector

    @classmethod
    def set(cls, name):
        """ set session by name """
        if cls.sessions is None:
            raise PillowtalkSessionError("No sessions found.")
        if name not in cls.sessions:
            raise PillowtalkSessionError("Session named {} not found. Choose from {}".format(name, cls.sessions.keys()))
        cls.session = cls.sessions[name]

    @classmethod
    def empty(cls):
        """ Checks if sessions is empty or None """
        return cls.sessions is None or cls.sessions == {}

    @classmethod
    def session_name(cls):
        """ gets current session name"""
        for name, session in cls.sessions.items():
            if cls.session == session:
                return name

    @classmethod
    def close(cls):
        """ closes the current session """
        cls.session = None

    @classmethod
    def reset(cls):
        """ resets the sessions and current session """
        cls.sessions = {}
        cls.session = None
{'fraction_non_alphanumeric': 0.09652971679297966, 'fraction_numerical': 0.0007977662544874351, 'mean_word_length': 2.2628497072218607, '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': '3910094', 'n_tokens_mistral': 1347, 'n_tokens_neox': 1329, 'n_words': 402}