Skip to content

Commit 155b8c1

Browse files
committed
FileNotFoundError and FileExistsError in more places.
1 parent 25e4517 commit 155b8c1

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

sphinx_json_schema_spec/__init__.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
from contextlib import suppress
12
from datetime import datetime
23
from importlib import metadata
34
from urllib.parse import urljoin
4-
import errno
55
import os
66
import urllib.request
77

@@ -30,11 +30,7 @@ def setup(app):
3030

3131
app.add_config_value("cache_path", "_cache", "")
3232

33-
try:
34-
os.makedirs(app.config.cache_path)
35-
except OSError as error:
36-
if error.errno != errno.EEXIST:
37-
raise
33+
os.makedirs(app.config.cache_path, exist_ok=True)
3834

3935
path = os.path.join(app.config.cache_path, "spec.html")
4036
spec = fetch_or_load(path)
@@ -61,13 +57,10 @@ def fetch_or_load(spec_path):
6157
),
6258
}
6359

64-
try:
60+
with suppress(FileNotFoundError):
6561
modified = datetime.utcfromtimestamp(os.path.getmtime(spec_path))
6662
date = modified.strftime("%a, %d %b %Y %I:%M:%S UTC")
6763
headers["If-Modified-Since"] = date
68-
except OSError as error:
69-
if error.errno != errno.ENOENT:
70-
raise
7164

7265
request = urllib.request.Request(VALIDATION_SPEC, headers=headers)
7366
response = urllib.request.urlopen(request, cafile=certifi.where())

0 commit comments

Comments
 (0)