From 7ae8c359e0b956092481b2715f87f5e4ef8c01dd Mon Sep 17 00:00:00 2001 From: Brett Smith Date: Wed, 17 May 2017 12:52:37 -0400 Subject: [PATCH] CacheFile opens the file immediately. This is necessary to work correctly with the error-catching logic of LoaderChain. --- oxrlib/cache.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/oxrlib/cache.py b/oxrlib/cache.py index 6792c3c..8feb303 100644 --- a/oxrlib/cache.py +++ b/oxrlib/cache.py @@ -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: