diff options
author | Julian Berman <Julian@GrayVines.com> | 2021-08-25 10:47:18 +0100 |
---|---|---|
committer | Julian Berman <Julian@GrayVines.com> | 2021-08-25 10:47:18 +0100 |
commit | 5a05f6f7f424300f0990f80f8a4cb86aba3d55df (patch) | |
tree | 35ac841391e1079e11297b0e30e965f0ff33f57a /docs | |
parent | ce6cb3f9911adb20d8e9b7a091c475e9d77f8190 (diff) | |
download | jsonschema-5a05f6f7f424300f0990f80f8a4cb86aba3d55df.tar.gz |
FileNotFoundError and FileExistsError in more places.
Diffstat (limited to 'docs')
-rw-r--r-- | docs/jsonschema_role.py | 13 |
1 files changed, 3 insertions, 10 deletions
diff --git a/docs/jsonschema_role.py b/docs/jsonschema_role.py index 1867f8a..7610c06 100644 --- a/docs/jsonschema_role.py +++ b/docs/jsonschema_role.py @@ -1,7 +1,7 @@ +from contextlib import suppress from datetime import datetime from importlib import metadata from urllib.parse import urljoin -import errno import os import urllib.request @@ -30,11 +30,7 @@ def setup(app): app.add_config_value("cache_path", "_cache", "") - try: - os.makedirs(app.config.cache_path) - except OSError as error: - if error.errno != errno.EEXIST: - raise + os.makedirs(app.config.cache_path, exist_ok=True) path = os.path.join(app.config.cache_path, "spec.html") spec = fetch_or_load(path) @@ -61,13 +57,10 @@ def fetch_or_load(spec_path): ), } - try: + with suppress(FileNotFoundError): modified = datetime.utcfromtimestamp(os.path.getmtime(spec_path)) date = modified.strftime("%a, %d %b %Y %I:%M:%S UTC") headers["If-Modified-Since"] = date - except OSError as error: - if error.errno != errno.ENOENT: - raise request = urllib.request.Request(VALIDATION_SPEC, headers=headers) response = urllib.request.urlopen(request, cafile=certifi.where()) |