1+ from __future__ import absolute_import
12import collections
23import shutil
34import json
5+
6+ import six
7+ from six .moves import urllib
8+
49import ruamel .yaml as yaml
510try :
611 from ruamel .yaml import CSafeLoader as SafeLoader
1621from rdflib import Graph , URIRef
1722import rdflib .namespace
1823from rdflib .namespace import RDF , RDFS
19- import urlparse
2024import logging
2125from schema_salad .utils import aslist
2226from typing import (cast , Any , Dict , Iterable , List , Optional , Text , Tuple ,
@@ -34,16 +38,16 @@ def pred(datatype, # type: Dict[str, Union[Dict, str]]
3438 namespaces # type: Dict[str, rdflib.namespace.Namespace]
3539 ):
3640 # type: (...) -> Union[Dict, Text]
37- split = urlparse .urlsplit (name )
41+ split = urllib . parse .urlsplit (name )
3842
39- vee = None # type: Optional[Union[str, unicode] ]
43+ vee = None # type: Optional[Text ]
4044
4145 if split .scheme != '' :
4246 vee = name
43- (ns , ln ) = rdflib .namespace .split_uri (unicode (vee ))
47+ (ns , ln ) = rdflib .namespace .split_uri (six . text_type (vee ))
4448 name = ln
4549 if ns [0 :- 1 ] in namespaces :
46- vee = unicode (namespaces [ns [0 :- 1 ]][ln ])
50+ vee = six . text_type (namespaces [ns [0 :- 1 ]][ln ])
4751 _logger .debug ("name, v %s %s" , name , vee )
4852
4953 v = None # type: Optional[Dict]
@@ -102,11 +106,11 @@ def process_type(t, # type: Dict[str, Any]
102106 classnode = URIRef (recordname )
103107 g .add ((classnode , RDF .type , RDFS .Class ))
104108
105- split = urlparse .urlsplit (recordname )
109+ split = urllib . parse .urlsplit (recordname )
106110 predicate = recordname
107111 if t .get ("inVocab" , True ):
108112 if split .scheme :
109- (ns , ln ) = rdflib .namespace .split_uri (unicode (recordname ))
113+ (ns , ln ) = rdflib .namespace .split_uri (six . text_type (recordname ))
110114 predicate = recordname
111115 recordname = ln
112116 else :
@@ -129,15 +133,15 @@ def process_type(t, # type: Dict[str, Any]
129133 _logger .debug ("Processing field %s" , i )
130134
131135 v = pred (t , i , fieldname , context , defaultPrefix ,
132- namespaces ) # type: Union[Dict[Any, Any], unicode , None]
136+ namespaces ) # type: Union[Dict[Any, Any], Text , None]
133137
134- if isinstance (v , basestring ):
138+ if isinstance (v , six . string_types ):
135139 v = v if v [0 ] != "@" else None
136140 elif v is not None :
137141 v = v ["_@id" ] if v .get ("_@id" , "@" )[0 ] != "@" else None
138142
139143 if bool (v ):
140- (ns , ln ) = rdflib .namespace .split_uri (unicode (v ))
144+ (ns , ln ) = rdflib .namespace .split_uri (six . text_type (v ))
141145 if ns [0 :- 1 ] in namespaces :
142146 propnode = namespaces [ns [0 :- 1 ]][ln ]
143147 else :
@@ -188,8 +192,8 @@ def salad_to_jsonld_context(j, schema_ctx):
188192 return (context , g )
189193
190194
191- def fix_jsonld_ids (obj , # type: Union[Dict[unicode , Any], List[Dict[unicode , Any]]]
192- ids # type: List[unicode ]
195+ def fix_jsonld_ids (obj , # type: Union[Dict[Text , Any], List[Dict[Text , Any]]]
196+ ids # type: List[Text ]
193197 ):
194198 # type: (...) -> None
195199 if isinstance (obj , dict ):
@@ -203,22 +207,22 @@ def fix_jsonld_ids(obj, # type: Union[Dict[unicode, Any], List[Dict[unicode,
203207 fix_jsonld_ids (entry , ids )
204208
205209
206- def makerdf (workflow , # type: Union[str, unicode]
207- wf , # type: Union[List[Dict[unicode , Any]], Dict[unicode , Any]]
210+ def makerdf (workflow , # type: Text
211+ wf , # type: Union[List[Dict[Text , Any]], Dict[Text , Any]]
208212 ctx , # type: ContextType
209213 graph = None # type: Graph
210214 ):
211215 # type: (...) -> Graph
212216 prefixes = {}
213217 idfields = []
214- for k , v in ctx .iteritems ():
218+ for k , v in six .iteritems (ctx ):
215219 if isinstance (v , dict ):
216220 url = v ["@id" ]
217221 else :
218222 url = v
219223 if url == "@id" :
220224 idfields .append (k )
221- doc_url , frg = urlparse .urldefrag (url )
225+ doc_url , frg = urllib . parse .urldefrag (url )
222226 if "/" in frg :
223227 p = frg .split ("/" )[0 ]
224228 prefixes [p ] = u"%s#%s/" % (doc_url , p )
@@ -242,7 +246,7 @@ def makerdf(workflow, # type: Union[str, unicode]
242246 for sub , pred , obj in g .triples ((None , URIRef ("@id" ), None )):
243247 g .remove ((sub , pred , obj ))
244248
245- for k2 , v2 in prefixes .iteritems ():
249+ for k2 , v2 in six .iteritems (prefixes ):
246250 g .namespace_manager .bind (k2 , v2 )
247251
248252 return g
0 commit comments