@@ -484,18 +484,37 @@ def _read__binary(self, filename):
484
484
return content
485
485
486
486
def readlines (self , filename , num_lines = 0 , binary = False , encoding = None ):
487
+ assert type (num_lines ) == int # noqa: E721
488
+ assert type (filename ) == str # noqa: E721
489
+ assert type (binary ) == bool # noqa: E721
490
+ assert encoding is None or type (encoding ) == str # noqa: E721
491
+
487
492
if num_lines > 0 :
488
- cmd = "tail -n {} {}" .format (num_lines , filename )
493
+ cmd = ["tail" , "-n" , str (num_lines ), filename ]
494
+ else :
495
+ cmd = ["cat" , filename ]
496
+
497
+ if binary :
498
+ assert encoding is None
499
+ pass
500
+ elif encoding is None :
501
+ encoding = get_default_encoding ()
502
+ assert type (encoding ) == str # noqa: E721
489
503
else :
490
- cmd = "cat {}" .format (filename )
504
+ assert type (encoding ) == str # noqa: E721
505
+ pass
491
506
492
507
result = self .exec_command (cmd , encoding = encoding )
508
+ assert result is not None
493
509
494
- if not binary and result :
495
- lines = result .decode (encoding or get_default_encoding ()).splitlines ()
510
+ if binary :
511
+ assert type (result ) == bytes # noqa: E721
512
+ lines = result .splitlines ()
496
513
else :
514
+ assert type (result ) == str # noqa: E721
497
515
lines = result .splitlines ()
498
516
517
+ assert type (lines ) == list # noqa: E721
499
518
return lines
500
519
501
520
def read_binary (self , filename , offset ):
0 commit comments