CacheFile opens the file immediately.

This is necessary to work correctly with the error-catching logic of LoaderChain.
This commit is contained in:
Brett Smith 2017-05-17 12:52:37 -04:00
parent cdc748c14f
commit 7ae8c359e0

View file

@ -6,7 +6,10 @@ from . import errors
class CacheFileBase:
def __init__(self, path, *args, **kwargs):
self.path = path
self.open = functools.partial(path.open, *args, **kwargs)
try:
self.open_file = path.open(*args, **kwargs)
except OSError as error:
self._translate_error(error, 'init')
def _translate_error(self, error, when):
for orig_type, mapped_type in self.ERRORS_MAP:
@ -15,12 +18,7 @@ class CacheFileBase:
raise error
def __enter__(self):
try:
self.open_file = self.open()
except OSError as error:
self._translate_error(error, 'enter')
else:
return self.open_file
return self.open_file
def __exit__(self, exc_type, exc_value, exc_tb):
try: