@@ -315,8 +315,7 @@ def file_extension(file_format: str) -> str:
315
315
}
316
316
if file_format in types_with_standard_extension :
317
317
return types_with_standard_extension [file_format ]
318
- else :
319
- raise ValueError ('Provided file format is not a valid one.' )
318
+ raise ValueError ('Provided file format is not a valid one.' )
320
319
321
320
# Formats: 'n3', 'nt', 'turtle', 'xml'
322
321
def read (self , location : Union [Path , str ], file_format : str = None ) -> None :
@@ -394,8 +393,7 @@ def add(self,
394
393
# Now dispatch to the appropriate method
395
394
if isinstance (objects , TopLevel ):
396
395
return self ._add (objects )
397
- else :
398
- return self ._add_all (objects )
396
+ return self ._add_all (objects )
399
397
400
398
def _find_in_objects (self , search_string : str ) -> Optional [Identified ]:
401
399
# TODO: implement recursive search
@@ -428,13 +426,19 @@ def join_lines(self, lines: List[Union[bytes, str]]) -> Union[bytes, str]:
428
426
"""
429
427
if not lines :
430
428
return ''
431
- lines_type = type (lines [0 ])
429
+
430
+ first_line = lines [0 ]
431
+ lines_type = type (first_line )
432
+
432
433
if lines_type is bytes :
433
- # rdflib 5
434
- return b'\n ' .join (lines ) + b'\n '
434
+ newline = b'\n '
435
435
elif lines_type is str :
436
- # rdflib 6
437
- return '\n ' .join (lines ) + '\n '
436
+ newline = '\n '
437
+ else :
438
+ raise ValueError ("Lines must be either bytes or str" )
439
+
440
+ joined = newline .join (lines )
441
+ return joined + newline
438
442
439
443
def write_string (self , file_format : str ) -> str :
440
444
graph = self .graph ()
0 commit comments