# Path: axolotl/state/sessionstore.py
# class SessionStore(object):
#     __metaclass__ = abc.ABCMeta
# 
#     @abc.abstractmethod
#     def loadSession(self, recepientId, deviceId):
#         pass
# 
#     @abc.abstractmethod
#     def getSubDeviceSessions(self, recepientId):
#         pass
# 
#     @abc.abstractmethod
#     def storeSession(self, recepientId, deviceId, sessionRecord):
#         pass
# 
#     @abc.abstractmethod
#     def containsSession(self, recepientId, deviceId):
#         pass
# 
#     @abc.abstractmethod
#     def deleteSession(self, recepientId, deviceId):
#         pass
# 
#     @abc.abstractmethod
#     def deleteAllSessions(self, recepientId):
#         pass
# 
# Path: axolotl/state/sessionrecord.py
# class SessionRecord:
#     ARCHIVED_STATES_MAX_LENGTH = 40
# 
#     def __init__(self, sessionState=None, serialized=None):
#         """
#         :type sessionState: SessionState
#         :type serialized: str
#         """
#         self.previousStates = []
#         if sessionState:
#             self.sessionState = sessionState
#             self.fresh = False
#         elif serialized:
#             record = storageprotos.RecordStructure()
#             record.ParseFromString(serialized)
#             self.sessionState = SessionState(record.currentSession)
#             self.fresh = False
#             for previousStructure in record.previousSessions:
#                 self.previousStates.append(SessionState(previousStructure))
# 
#         else:
#             self.fresh = True
#             self.sessionState = SessionState()
# 
#     def hasSessionState(self, version, aliceBaseKey):
#         if self.sessionState.getSessionVersion() == version and aliceBaseKey == self.sessionState.getAliceBaseKey():
#             return True
# 
#         for state in self.previousStates:
#             if state.getSessionVersion() == version and aliceBaseKey == state.getAliceBaseKey():
#                 return True
# 
#         return False
# 
#     def getSessionState(self):
#         return self.sessionState
# 
#     def getPreviousSessionStates(self):
#         return self.previousStates
# 
#     def isFresh(self):
#         return self.fresh
# 
#     def archiveCurrentState(self):
#         self.promoteState(SessionState())
# 
#     def promoteState(self, promotedState):
#         self.previousStates.insert(0, self.sessionState)
#         self.sessionState = promotedState
#         if len(self.previousStates) > self.__class__.ARCHIVED_STATES_MAX_LENGTH:
#             self.previousStates.pop()
# 
#     def setState(self, sessionState):
#         self.sessionState = sessionState
# 
#     def serialize(self):
#         previousStructures = [previousState.getStructure() for previousState in self.previousStates]
#         record = storageprotos.RecordStructure()
#         record.currentSession.MergeFrom(self.sessionState.getStructure())
#         record.previousSessions.extend(previousStructures)
# 
#         return record.SerializeToString()


from ..state.sessionstore import SessionStore
from ..state.sessionrecord import SessionRecord
# -*- coding: utf-8 -*-



class InMemorySessionStore(SessionStore):
    def __init__(self):
        self.sessions = {}

    def loadSession(self, recepientId, deviceId):
        if self.containsSession(recepientId, deviceId):
            return SessionRecord(serialized=self.sessions[(recepientId, deviceId)])
        else:

# Path: axolotl/state/sessionstore.py
# class SessionStore(object):
#     __metaclass__ = abc.ABCMeta
# 
#     @abc.abstractmethod
#     def loadSession(self, recepientId, deviceId):
#         pass
# 
#     @abc.abstractmethod
#     def getSubDeviceSessions(self, recepientId):
#         pass
# 
#     @abc.abstractmethod
#     def storeSession(self, recepientId, deviceId, sessionRecord):
#         pass
# 
#     @abc.abstractmethod
#     def containsSession(self, recepientId, deviceId):
#         pass
# 
#     @abc.abstractmethod
#     def deleteSession(self, recepientId, deviceId):
#         pass
# 
#     @abc.abstractmethod
#     def deleteAllSessions(self, recepientId):
#         pass
# 
# Path: axolotl/state/sessionrecord.py
# class SessionRecord:
#     ARCHIVED_STATES_MAX_LENGTH = 40
# 
#     def __init__(self, sessionState=None, serialized=None):
#         """
#         :type sessionState: SessionState
#         :type serialized: str
#         """
#         self.previousStates = []
#         if sessionState:
#             self.sessionState = sessionState
#             self.fresh = False
#         elif serialized:
#             record = storageprotos.RecordStructure()
#             record.ParseFromString(serialized)
#             self.sessionState = SessionState(record.currentSession)
#             self.fresh = False
#             for previousStructure in record.previousSessions:
#                 self.previousStates.append(SessionState(previousStructure))
# 
#         else:
#             self.fresh = True
#             self.sessionState = SessionState()
# 
#     def hasSessionState(self, version, aliceBaseKey):
#         if self.sessionState.getSessionVersion() == version and aliceBaseKey == self.sessionState.getAliceBaseKey():
#             return True
# 
#         for state in self.previousStates:
#             if state.getSessionVersion() == version and aliceBaseKey == state.getAliceBaseKey():
#                 return True
# 
#         return False
# 
#     def getSessionState(self):
#         return self.sessionState
# 
#     def getPreviousSessionStates(self):
#         return self.previousStates
# 
#     def isFresh(self):
#         return self.fresh
# 
#     def archiveCurrentState(self):
#         self.promoteState(SessionState())
# 
#     def promoteState(self, promotedState):
#         self.previousStates.insert(0, self.sessionState)
#         self.sessionState = promotedState
#         if len(self.previousStates) > self.__class__.ARCHIVED_STATES_MAX_LENGTH:
#             self.previousStates.pop()
# 
#     def setState(self, sessionState):
#         self.sessionState = sessionState
# 
#     def serialize(self):
#         previousStructures = [previousState.getStructure() for previousState in self.previousStates]
#         record = storageprotos.RecordStructure()
#         record.currentSession.MergeFrom(self.sessionState.getStructure())
#         record.previousSessions.extend(previousStructures)
# 
#         return record.SerializeToString()


# Path: axolotl/tests/inmemorysessionstore.py
from ..state.sessionstore import SessionStore
from ..state.sessionrecord import SessionRecord

# -*- coding: utf-8 -*-



class InMemorySessionStore(SessionStore):
    def __init__(self):
        self.sessions = {}

    def loadSession(self, recepientId, deviceId):
        if self.containsSession(recepientId, deviceId):
            return SessionRecord(serialized=self.sessions[(recepientId, deviceId)])
        else:

            return SessionRecord()