File tree Expand file tree Collapse file tree 1 file changed +3
-10
lines changed Expand file tree Collapse file tree 1 file changed +3
-10
lines changed Original file line number Diff line number Diff line change
1
+ from contextlib import suppress
1
2
from datetime import datetime
2
3
from importlib import metadata
3
4
from urllib .parse import urljoin
4
- import errno
5
5
import os
6
6
import urllib .request
7
7
@@ -30,11 +30,7 @@ def setup(app):
30
30
31
31
app .add_config_value ("cache_path" , "_cache" , "" )
32
32
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 )
38
34
39
35
path = os .path .join (app .config .cache_path , "spec.html" )
40
36
spec = fetch_or_load (path )
@@ -61,13 +57,10 @@ def fetch_or_load(spec_path):
61
57
),
62
58
}
63
59
64
- try :
60
+ with suppress ( FileNotFoundError ) :
65
61
modified = datetime .utcfromtimestamp (os .path .getmtime (spec_path ))
66
62
date = modified .strftime ("%a, %d %b %Y %I:%M:%S UTC" )
67
63
headers ["If-Modified-Since" ] = date
68
- except OSError as error :
69
- if error .errno != errno .ENOENT :
70
- raise
71
64
72
65
request = urllib .request .Request (VALIDATION_SPEC , headers = headers )
73
66
response = urllib .request .urlopen (request , cafile = certifi .where ())
You can’t perform that action at this time.
0 commit comments