This commit is contained in:
killiandesse 2026-01-07 16:35:19 -08:00 committed by GitHub
commit debf15634e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 2 additions and 18 deletions

View File

@ -34,20 +34,6 @@ def _path(filename: str) -> _ResourceType:
return importlib.resources.files(qutebrowser) / filename
@contextlib.contextmanager
def _keyerror_workaround() -> Iterator[None]:
"""Re-raise KeyErrors as FileNotFoundErrors.
WORKAROUND for zipfile.Path resources raising KeyError when a file was notfound:
https://bugs.python.org/issue43063
Only needed for Python 3.9.
"""
try:
yield
except KeyError as e:
raise FileNotFoundError(str(e))
def _glob(
resource_path: _ResourceType,
@ -102,8 +88,7 @@ def read_file(filename: str) -> str:
return _cache[filename]
path = _path(filename)
with _keyerror_workaround():
return path.read_text(encoding='utf-8')
return path.read_text(encoding='utf-8')
def read_file_binary(filename: str) -> bytes:
@ -119,5 +104,4 @@ def read_file_binary(filename: str) -> bytes:
return _bin_cache[filename]
path = _path(filename)
with _keyerror_workaround():
return path.read_bytes()
return path.read_bytes()