28
28
from .ref_resolver import Loader , file_uri
29
29
_logger = logging .getLogger ("salad" )
30
30
31
- from rdflib .plugin import register , Parser
31
+ from rdflib .plugin import register
32
+ from rdflib .parser import Parser
32
33
register ('json-ld' , Parser , 'rdflib_jsonld.parser' , 'JsonLDParser' )
33
34
34
35
@@ -39,7 +40,7 @@ def printrdf(workflow, # type: str
39
40
):
40
41
# type: (...) -> None
41
42
g = jsonld_context .makerdf (workflow , wf , ctx )
42
- print (g .serialize (format = sr , encoding = 'utf-8' ).decode ('utf-8' ))
43
+ print (g .serialize (format = sr , encoding = 'utf-8' ).decode ('utf-8' )) # type: ignore
43
44
44
45
def regex_chunk (lines , regex ):
45
46
# type: (List[str], Pattern[str]) -> List[List[str]]
@@ -61,21 +62,20 @@ def chunk_messages(message): # type: (str) -> List[Tuple[int, str]]
61
62
for chun in regex_chunk (message .splitlines (), file_regex ):
62
63
fst = chun [0 ]
63
64
mat = file_regex .match (fst )
64
- place = mat .group (1 )
65
- indent = len (mat .group (2 ))
66
-
67
- lst = [mat .group (3 )]+ chun [1 :]
68
- if [x for x in lst if item_regex .match (x )]:
69
- for item in regex_chunk (lst , item_regex ):
70
- msg = re .sub (item_regex , '' , "\n " .join (item ))
71
- arr .append ((indent , place + ' ' + re .sub (r'[\n\s]+' ,
72
- ' ' ,
73
- msg )))
74
- else :
75
- msg = re .sub (item_regex , '' , "\n " .join (lst ))
76
- arr .append ((indent , place + ' ' + re .sub (r'[\n\s]+' ,
77
- ' ' ,
78
- msg )))
65
+ if mat :
66
+ place = mat .group (1 )
67
+ indent = len (mat .group (2 ))
68
+
69
+ lst = [mat .group (3 )]+ chun [1 :]
70
+ if [x for x in lst if item_regex .match (x )]:
71
+ for item in regex_chunk (lst , item_regex ):
72
+ msg = re .sub (item_regex , '' , "\n " .join (item ))
73
+ arr .append ((indent , place + ' ' + re .sub (
74
+ r'[\n\s]+' , ' ' , msg )))
75
+ else :
76
+ msg = re .sub (item_regex , '' , "\n " .join (lst ))
77
+ arr .append ((indent , place + ' ' + re .sub (
78
+ r'[\n\s]+' , ' ' , msg )))
79
79
return arr
80
80
81
81
@@ -94,7 +94,7 @@ def to_one_line_messages(message): # type: (str) -> str
94
94
95
95
def reformat_yaml_exception_message (message ): # type: (str) -> str
96
96
line_regex = re .compile (r'^\s+in "(.+)", line (\d+), column (\d+)$' )
97
- fname_regex = re .compile (r'^file://' + os .getcwd ()+ '/' )
97
+ fname_regex = re .compile (r'^file://' + re . escape ( os .getcwd () )+ '/' )
98
98
msgs = message .splitlines ()
99
99
ret = []
100
100
@@ -103,17 +103,21 @@ def reformat_yaml_exception_message(message): # type: (str) -> str
103
103
nblanks = 0
104
104
elif len (msgs ) == 4 :
105
105
c_msg = msgs [0 ]
106
- c_file , c_line , c_column = line_regex .match (msgs [1 ]).groups ()
107
- c_file = re .sub (fname_regex , '' , c_file )
108
- ret .append ("%s:%s:%s: %s" % (c_file , c_line , c_column , c_msg ))
106
+ match = line_regex .match (msgs [1 ])
107
+ if match :
108
+ c_file , c_line , c_column = match .groups ()
109
+ c_file = re .sub (fname_regex , '' , c_file )
110
+ ret .append ("%s:%s:%s: %s" % (c_file , c_line , c_column , c_msg ))
109
111
110
112
msgs = msgs [2 :]
111
113
nblanks = 2
112
114
113
115
p_msg = msgs [0 ]
114
- p_file , p_line , p_column = line_regex .match (msgs [1 ]).groups ()
115
- p_file = re .sub (fname_regex , '' , p_file )
116
- ret .append ("%s:%s:%s:%s %s" % (p_file , p_line , p_column , ' ' * nblanks , p_msg ))
116
+ match = line_regex .match (msgs [1 ])
117
+ if match :
118
+ p_file , p_line , p_column = match .groups ()
119
+ p_file = re .sub (fname_regex , '' , p_file )
120
+ ret .append ("%s:%s:%s:%s %s" % (p_file , p_line , p_column , ' ' * nblanks , p_msg ))
117
121
return "\n " .join (ret )
118
122
119
123
@@ -264,9 +268,10 @@ def main(argsl=None): # type: (List[str]) -> int
264
268
return 1
265
269
266
270
if isinstance (avsc_names , Exception ):
267
- _logger .error ("Schema `%s` error:\n %s" , args .schema ,
268
- avsc_names , exc_info = ((type (avsc_names ), avsc_names ,
269
- None ) if args .debug else None ))
271
+ _logger .error ("Schema `%s` error:\n %s" , args .schema , # type: ignore
272
+ avsc_names , exc_info = (
273
+ (type (avsc_names ), avsc_names , None ) if args .debug
274
+ else None ))
270
275
if args .print_avro :
271
276
print (json .dumps (avsc_obj , indent = 4 ))
272
277
return 1
@@ -284,7 +289,7 @@ def main(argsl=None): # type: (List[str]) -> int
284
289
285
290
# Optionally print the RDFS graph from the schema
286
291
if args .print_rdfs :
287
- print (rdfs .serialize (format = args .rdf_serializer ).decode ('utf-8' ))
292
+ print (rdfs .serialize (format = args .rdf_serializer ).decode ('utf-8' )) # type: ignore
288
293
return 0
289
294
290
295
if args .print_metadata and not args .document :
0 commit comments