18
18
from typing import (Union , Any , AnyStr , cast , Callable , Dict , Sequence , Text ,
19
19
Tuple , Type , IO )
20
20
21
- from schema_salad .ref_resolver import Loader , Fetcher
21
+ from schema_salad .ref_resolver import Loader , Fetcher , file_uri , uri_file_path
22
22
import schema_salad .validate as validate
23
23
import schema_salad .jsonld_context
24
24
import schema_salad .makedoc
@@ -258,7 +258,7 @@ def __call__(self, parser, namespace, values, option_string=None):
258
258
setattr (namespace ,
259
259
self .dest , # type: ignore
260
260
{"class" : self .objclass ,
261
- "location" : "file://%s" % os .path .abspath (cast (AnyStr , values ))})
261
+ "location" : file_uri ( str ( os .path .abspath (cast (AnyStr , values )) ))})
262
262
263
263
class FSAppendAction (argparse .Action ):
264
264
objclass = None # type: Text
@@ -281,7 +281,7 @@ def __call__(self, parser, namespace, values, option_string=None):
281
281
g )
282
282
g .append (
283
283
{"class" : self .objclass ,
284
- "location" : "file://%s" % os .path .abspath (cast (AnyStr , values ))})
284
+ "location" : file_uri ( str ( os .path .abspath (cast (AnyStr , values )) ))})
285
285
286
286
class FileAction (FSAction ):
287
287
objclass = "File"
@@ -471,7 +471,7 @@ def load_job_order(args, t, stdin, print_input_deps=False, relative_deps=False,
471
471
472
472
if print_input_deps :
473
473
printdeps (job_order_object , loader , stdout , relative_deps , "" ,
474
- basedir = u"file://%s/" % input_basedir )
474
+ basedir = file_uri ( input_basedir + "/" ) )
475
475
return 0
476
476
477
477
def pathToLoc (p ):
@@ -498,7 +498,7 @@ def makeRelative(base, ob):
498
498
pass
499
499
else :
500
500
if u .startswith ("file://" ):
501
- u = u [ 7 :]
501
+ u = uri_file_path ( u )
502
502
ob ["location" ] = os .path .relpath (u , base )
503
503
504
504
def printdeps (obj , document_loader , stdout , relative_deps , uri , basedir = None ):
@@ -519,7 +519,7 @@ def loadref(b, u):
519
519
if relative_deps == "primary" :
520
520
base = basedir if basedir else os .path .dirname (uri )
521
521
elif relative_deps == "cwd" :
522
- base = "file://" + os .getcwd ()
522
+ base = file_uri ( os .getcwd () )
523
523
else :
524
524
raise Exception (u"Unknown relative_deps %s" % relative_deps )
525
525
@@ -720,7 +720,7 @@ def main(argsl=None, # type: List[str]
720
720
if out is not None :
721
721
def locToPath (p ):
722
722
if p ["location" ].startswith ("file://" ):
723
- p ["path" ] = p ["location" ][ 7 :]
723
+ p ["path" ] = uri_file_path ( p ["location" ])
724
724
725
725
adjustDirObjs (out , locToPath )
726
726
adjustFileObjs (out , locToPath )
0 commit comments