@@ -484,18 +484,37 @@ def _read__binary(self, filename):
484484 return content
485485
486486 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+
487492 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
489503 else :
490- cmd = "cat {}" .format (filename )
504+ assert type (encoding ) == str # noqa: E721
505+ pass
491506
492507 result = self .exec_command (cmd , encoding = encoding )
508+ assert result is not None
493509
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 ()
496513 else :
514+ assert type (result ) == str # noqa: E721
497515 lines = result .splitlines ()
498516
517+ assert type (lines ) == list # noqa: E721
499518 return lines
500519
501520 def read_binary (self , filename , offset ):
0 commit comments