Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
from watchdog.events import PatternMatchingEventHandler
# Altenative: https://github.com/WoLpH/portalocker
from .base_core import _BaseCore
try:
FileNotFoundError
except NameError: # we're on python 2
FileNotFoundError = IOError # skipcq: PYL-W0622
DEF_CACHIER_DIR = '~/.cachier/'
class _PickleCore(_BaseCore):
"""The pickle core class for cachier.
Parameters
----------
stale_after : datetime.timedelta, optional
See _BaseCore documentation.
next_time : bool, optional
See _BaseCore documentation.
pickle_reload : bool, optional
See core.cachier() documentation.
cache_dir : str, optional.
See core.cachier() documentation.
"""
class CacheChangeHandler(PatternMatchingEventHandler):
"""Handles cache-file modification events."""
from pymongo.errors import OperationFailure
from bson.binary import Binary # to save binary data to mongodb
except ImportError: # pragma: no cover
pass
from .base_core import _BaseCore
MONGO_SLEEP_DURATION_IN_SEC = 1
class RecalculationNeeded(Exception):
pass
class _MongoCore(_BaseCore):
_INDEX_NAME = 'func_1_key_1'
def __init__(self, mongetter, stale_after, next_time):
if 'pymongo' not in sys.modules:
warnings.warn((
"Cachier warning: pymongo was not found. "
"MongoDB cores will not function."))
_BaseCore.__init__(self, stale_after, next_time)
self.mongetter = mongetter
self.mongo_collection = self.mongetter()
index_inf = self.mongo_collection.index_information()
if _MongoCore._INDEX_NAME not in index_inf:
func1key1 = IndexModel(
keys=[('func', ASCENDING), ('key', ASCENDING)],
name=_MongoCore._INDEX_NAME)