sources: ignore non existent files in OverrideSource

This commit is contained in:
Corentin Sechet 2022-04-11 15:34:07 +02:00
parent 51253e4a37
commit 554d9b0d09
1 changed files with 5 additions and 3 deletions

View File

@ -1,6 +1,7 @@
"""Source for remote files"""
from abc import ABC, abstractmethod
from contextlib import asynccontextmanager
from pathlib import Path
from re import Pattern
from re import compile as re_compile
from typing import AsyncGenerator, AsyncIterable, Optional, cast
@ -132,9 +133,10 @@ class OverrideSource(Source):
for pattern, replace in self._mappings:
if pattern.match(url):
mapped_path = pattern.sub(replace, url)
with open(mapped_path, "rb") as mapped_file:
return mapped_file.read()
mapped_path = Path(pattern.sub(replace, url))
if mapped_path.is_file():
with open(mapped_path, "rb") as mapped_file:
return mapped_file.read()
return await self._next_source.get_url(url)