File tree Expand file tree Collapse file tree 2 files changed +19
-6
lines changed
openapi_spec_validator/handlers Expand file tree Collapse file tree 2 files changed +19
-6
lines changed Original file line number Diff line number Diff line change 33from yaml import load
44
55from openapi_spec_validator .handlers .base import BaseHandler
6+ from openapi_spec_validator .handlers .utils import uri_to_path
67from openapi_spec_validator .loaders import ExtendedSafeLoader
78
89
@@ -19,12 +20,12 @@ def __call__(self, f):
1920class FileHandler (FileObjectHandler ):
2021 """OpenAPI spec validator file path handler."""
2122
22- def __call__ (self , f ):
23- if isinstance (f , StringIO ):
24- return super (FileHandler , self ).__call__ (f )
23+ def __call__ (self , uri ):
24+ if isinstance (uri , StringIO ):
25+ return super (FileHandler , self ).__call__ (uri )
2526
26- assert f .startswith ("file" )
27+ assert uri .startswith ("file" )
2728
28- filename = f [ 7 :]
29- with open (filename ) as fh :
29+ filepath = uri_to_path ( uri )
30+ with open (filepath ) as fh :
3031 return super (FileHandler , self ).__call__ (fh )
Original file line number Diff line number Diff line change 1+ import os .path
2+
3+ from six .moves .urllib .parse import urlparse , unquote
4+ from six .moves .urllib .request import url2pathname
5+
6+
7+ def uri_to_path (uri ):
8+ parsed = urlparse (uri )
9+ host = "{0}{0}{mnt}{0}" .format (os .path .sep , mnt = parsed .netloc )
10+ return os .path .normpath (
11+ os .path .join (host , url2pathname (unquote (parsed .path )))
12+ )
You can’t perform that action at this time.
0 commit comments