From bdad6ec83f1eacb4e5176e8e3aa88117ad39da3d Mon Sep 17 00:00:00 2001 From: squidfunk Date: Thu, 20 Feb 2025 08:17:05 +0700 Subject: [PATCH] Formatting --- material/plugins/privacy/plugin.py | 20 +++++++++++--------- src/plugins/privacy/plugin.py | 20 +++++++++++--------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/material/plugins/privacy/plugin.py b/material/plugins/privacy/plugin.py index 7cd1c4b5bc1..fc47fcada21 100644 --- a/material/plugins/privacy/plugin.py +++ b/material/plugins/privacy/plugin.py @@ -259,7 +259,7 @@ def _parse_fragment(self, fragment: str): # quote, we need to catch this here, as we're using pretty basic # regular expression based extraction raise PluginError( - f"Could not parse due to possible syntax error in HTML: \n\n" + "Couldn't parse due to possible syntax error in HTML: \n\n" + fragment ) @@ -413,11 +413,11 @@ def _fetch(self, file: File, config: MkDocsConfig): try: res = requests.get( file.url, - headers={ - # Set user agent explicitly, so Google Fonts gives us *.woff2 - # files, which according to caniuse.com is the only format we - # need to download as it covers the entire range of browsers - # we're officially supporting. + headers = { + # Set user agent explicitly, so Google Fonts gives us + # *.woff2 files, which according to caniuse.com is the + # only format we need to download as it covers the range + # range of browsers we're officially supporting. "User-Agent": " ".join( [ "Mozilla/5.0 (Windows NT 10.0; Win64; x64)", @@ -429,9 +429,11 @@ def _fetch(self, file: File, config: MkDocsConfig): timeout=DEFAULT_TIMEOUT_IN_SECS, ) res.raise_for_status() - except Exception as error: # this could be a ConnectionError or an HTTPError - log.warning(f"Could not retrieve {file.url}: {error}") - return False + + # Intercept errors of type `ConnectionError` and `HTTPError` + except Exception as error: + log.warning(f"Couldn't retrieve {file.url}: {error}") + return # Compute expected file extension and append if missing mime = res.headers["content-type"].split(";")[0] diff --git a/src/plugins/privacy/plugin.py b/src/plugins/privacy/plugin.py index 7cd1c4b5bc1..fc47fcada21 100644 --- a/src/plugins/privacy/plugin.py +++ b/src/plugins/privacy/plugin.py @@ -259,7 +259,7 @@ def _parse_fragment(self, fragment: str): # quote, we need to catch this here, as we're using pretty basic # regular expression based extraction raise PluginError( - f"Could not parse due to possible syntax error in HTML: \n\n" + "Couldn't parse due to possible syntax error in HTML: \n\n" + fragment ) @@ -413,11 +413,11 @@ def _fetch(self, file: File, config: MkDocsConfig): try: res = requests.get( file.url, - headers={ - # Set user agent explicitly, so Google Fonts gives us *.woff2 - # files, which according to caniuse.com is the only format we - # need to download as it covers the entire range of browsers - # we're officially supporting. + headers = { + # Set user agent explicitly, so Google Fonts gives us + # *.woff2 files, which according to caniuse.com is the + # only format we need to download as it covers the range + # range of browsers we're officially supporting. "User-Agent": " ".join( [ "Mozilla/5.0 (Windows NT 10.0; Win64; x64)", @@ -429,9 +429,11 @@ def _fetch(self, file: File, config: MkDocsConfig): timeout=DEFAULT_TIMEOUT_IN_SECS, ) res.raise_for_status() - except Exception as error: # this could be a ConnectionError or an HTTPError - log.warning(f"Could not retrieve {file.url}: {error}") - return False + + # Intercept errors of type `ConnectionError` and `HTTPError` + except Exception as error: + log.warning(f"Couldn't retrieve {file.url}: {error}") + return # Compute expected file extension and append if missing mime = res.headers["content-type"].split(";")[0]