# Path: resources/lib/storageengine/storage.py
# class TimedStorage(_Storage):
#     """A dict with the ability to persist to disk and TTL for items."""
# 
#     def dump(self, fileobj):
#         super(TimedStorage, self).dump(fileobj)
# 
#     def __init__(self, filename, file_format='pickle', TTL=None):
#         """TTL if provided should be a datetime.timedelta. Any entries
#         older than the provided TTL will be removed upon load and upon item
#         access.
#         """
#         self.TTL = TTL
#         _Storage.__init__(self, filename, file_format=file_format)
# 
#     def __setitem__(self, key, val, raw=False):
#         if raw:
#             self._items[key] = val
#         else:
#             self._items[key] = (val, time.time())
# 
#     def __getitem__(self, key):
#         val, timestamp = self._items[key]
#         if self.TTL and (datetime.utcnow() -
#                              datetime.utcfromtimestamp(timestamp) > self.TTL):
#             del self._items[key]
#             return self._items[key][0]  # Will raise KeyError
#         return val
# 
#     def initial_update(self, mapping):
#         '''Initially fills the underlying dictionary with keys, values and
#         timestamps.
#         '''
#         for key, val in mapping.items():
#             _, timestamp = val
#             if not self.TTL or (datetime.utcnow() -
#                                     datetime.utcfromtimestamp(timestamp) < self.TTL):
#                 self.__setitem__(key, val, raw=True)


import json
import os
import stat
import re
import xbmc
import xbmcaddon
import xbmcgui
from datetime import timedelta
from xml.etree.ElementTree import ElementTree
from resources.lib.storageengine.storage import TimedStorage
        created.

        .. seealso:: :class:`xbmcswift2.TimedStorage` for more details.

        :param name: The name  of the storage to retrieve.
        :param file_format: Choices are 'pickle', 'csv', and 'json'. Pickle is
                            recommended as it supports python objects.

                            .. note:: If a storage already exists for the given
                                      name, the file_format parameter is
                                      ignored. The format will be determined by
                                      the existing storage file.
        :param TTL: The time to live for storage items specified in minutes or None
                    for no expiration. Since storage items aren't expired until a
                    storage is loaded form disk, it is possible to call
                    get_storage() with a different TTL than when the storage was
                    created. The currently specified TTL is always honored.
        """

        if not hasattr(self, '_unsynced_storages'):
            self._unsynced_storages = {}
        filename = os.path.join(self.storage_path, name)
        try:
            storage = self._unsynced_storages[filename]
            self.logger.info('Loaded storage "%s" from memory' % name)
        except KeyError:
            if TTL:
                TTL = timedelta(minutes=TTL)

            try:

# Path: resources/lib/storageengine/storage.py
# class TimedStorage(_Storage):
#     """A dict with the ability to persist to disk and TTL for items."""
# 
#     def dump(self, fileobj):
#         super(TimedStorage, self).dump(fileobj)
# 
#     def __init__(self, filename, file_format='pickle', TTL=None):
#         """TTL if provided should be a datetime.timedelta. Any entries
#         older than the provided TTL will be removed upon load and upon item
#         access.
#         """
#         self.TTL = TTL
#         _Storage.__init__(self, filename, file_format=file_format)
# 
#     def __setitem__(self, key, val, raw=False):
#         if raw:
#             self._items[key] = val
#         else:
#             self._items[key] = (val, time.time())
# 
#     def __getitem__(self, key):
#         val, timestamp = self._items[key]
#         if self.TTL and (datetime.utcnow() -
#                              datetime.utcfromtimestamp(timestamp) > self.TTL):
#             del self._items[key]
#             return self._items[key][0]  # Will raise KeyError
#         return val
# 
#     def initial_update(self, mapping):
#         '''Initially fills the underlying dictionary with keys, values and
#         timestamps.
#         '''
#         for key, val in mapping.items():
#             _, timestamp = val
#             if not self.TTL or (datetime.utcnow() -
#                                     datetime.utcfromtimestamp(timestamp) < self.TTL):
#                 self.__setitem__(key, val, raw=True)


# Path: resources/lib/core/corefunctions.py
import json
import os
import stat
import re
import xbmc
import xbmcaddon
import xbmcgui
from datetime import timedelta
from xml.etree.ElementTree import ElementTree
from resources.lib.storageengine.storage import TimedStorage

        created.

        .. seealso:: :class:`xbmcswift2.TimedStorage` for more details.

        :param name: The name  of the storage to retrieve.
        :param file_format: Choices are 'pickle', 'csv', and 'json'. Pickle is
                            recommended as it supports python objects.

                            .. note:: If a storage already exists for the given
                                      name, the file_format parameter is
                                      ignored. The format will be determined by
                                      the existing storage file.
        :param TTL: The time to live for storage items specified in minutes or None
                    for no expiration. Since storage items aren't expired until a
                    storage is loaded form disk, it is possible to call
                    get_storage() with a different TTL than when the storage was
                    created. The currently specified TTL is always honored.
        """

        if not hasattr(self, '_unsynced_storages'):
            self._unsynced_storages = {}
        filename = os.path.join(self.storage_path, name)
        try:
            storage = self._unsynced_storages[filename]
            self.logger.info('Loaded storage "%s" from memory' % name)
        except KeyError:
            if TTL:
                TTL = timedelta(minutes=TTL)

            try:

                storage = TimedStorage(filename, file_format, TTL)