Skip to content

Commit

Permalink
use f-strings
Browse files Browse the repository at this point in the history
  • Loading branch information
Archmonger committed Feb 10, 2022
1 parent 3bb4088 commit 8a0930e
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/whitenoise/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def update_files_dictionary(self, root, prefix):
def add_file_to_dictionary(self, url, path, stat_cache=None):
if self.is_compressed_variant(path, stat_cache=stat_cache):
return
if self.index_file and url.endswith("/" + self.index_file):
if self.index_file and url.endswith(f"/{self.index_file}"):
index_url = url[: -len(self.index_file)]
index_no_slash = index_url.rstrip("/")
self.files[url] = self.redirect(url, index_url)
Expand Down Expand Up @@ -142,15 +142,15 @@ def find_file_at_path_with_indexes(self, path, url):
if url.endswith("/"):
path = os.path.join(path, self.index_file)
return self.get_static_file(path, url)
elif url.endswith("/" + self.index_file):
elif url.endswith(f"/{self.index_file}"):
if os.path.isfile(path):
return self.redirect(url, url[: -len(self.index_file)])
else:
try:
return self.get_static_file(path, url)
except IsDirectoryError:
if os.path.isfile(os.path.join(path, self.index_file)):
return self.redirect(url, url + "/")
return self.redirect(url, f"{url}/")
raise MissingFileError(path)

@staticmethod
Expand Down Expand Up @@ -191,7 +191,7 @@ def get_static_file(self, path, url, stat_cache=None):
path,
headers.items(),
stat_cache=stat_cache,
encodings={"gzip": path + ".gz", "br": path + ".br"},
encodings={"gzip": f"{path}.gz", "br": f"{path}.br"},
)

def add_mime_headers(self, headers, path, url):
Expand Down Expand Up @@ -224,8 +224,8 @@ def redirect(self, from_url, to_url):
We use relative redirects as we don't know the absolute URL the app is
being hosted under
"""
if to_url == from_url + "/":
relative_url = from_url.split("/")[-1] + "/"
if to_url == f"{from_url}/":
relative_url = f'{from_url.split("/")[-1]}/'
elif from_url == to_url + self.index_file:
relative_url = "./"
else:
Expand Down

0 comments on commit 8a0930e

Please sign in to comment.