From 554d9b0d0987757a0e40fb0e68fc23b45d67e675 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Corentin=20S=C3=A9chet?= Date: Mon, 11 Apr 2022 15:34:07 +0200 Subject: [PATCH] sources: ignore non existent files in OverrideSource --- frontools/sources.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/frontools/sources.py b/frontools/sources.py index c83cc61..0e948d4 100644 --- a/frontools/sources.py +++ b/frontools/sources.py @@ -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)