summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Berman <Julian@GrayVines.com>2021-08-25 10:47:18 +0100
committerJulian Berman <Julian@GrayVines.com>2021-08-25 10:47:18 +0100
commit5a05f6f7f424300f0990f80f8a4cb86aba3d55df (patch)
tree35ac841391e1079e11297b0e30e965f0ff33f57a
parentce6cb3f9911adb20d8e9b7a091c475e9d77f8190 (diff)
downloadjsonschema-5a05f6f7f424300f0990f80f8a4cb86aba3d55df.tar.gz
FileNotFoundError and FileExistsError in more places.
-rw-r--r--docs/jsonschema_role.py13
-rw-r--r--jsonschema/cli.py5
-rw-r--r--jsonschema/tests/test_cli.py3
3 files changed, 5 insertions, 16 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())
diff --git a/jsonschema/cli.py b/jsonschema/cli.py
index 4ce2a35..ce35684 100644
--- a/jsonschema/cli.py
+++ b/jsonschema/cli.py
@@ -5,7 +5,6 @@ The ``jsonschema`` command line.
from json import JSONDecodeError
from textwrap import dedent
import argparse
-import errno
import json
import sys
import traceback
@@ -44,9 +43,7 @@ class _Outputter(object):
def load(self, path):
try:
file = open(path)
- except OSError as error:
- if error.errno != errno.ENOENT:
- raise
+ except FileNotFoundError:
self.filenotfound_error(path=path, exc_info=sys.exc_info())
raise _CannotLoadFile()
diff --git a/jsonschema/tests/test_cli.py b/jsonschema/tests/test_cli.py
index 45f942f..eafc05d 100644
--- a/jsonschema/tests/test_cli.py
+++ b/jsonschema/tests/test_cli.py
@@ -4,7 +4,6 @@ from json import JSONDecodeError
from pathlib import Path
from textwrap import dedent
from unittest import TestCase
-import errno
import json
import os
import subprocess
@@ -50,7 +49,7 @@ def fake_open(all_contents):
def open(path):
contents = all_contents.get(path)
if contents is None:
- raise OSError(errno.ENOENT, os.strerror(errno.ENOENT), path)
+ raise FileNotFoundError(path)
return StringIO(contents)
return open