@@ -555,7 +555,8 @@ def __run_command(command, use_test_user, a_input, a_stdout, a_stderr, log_outpu
555
555
os .killpg (p .pid , timeout_signal )
556
556
os ._exit (0 )
557
557
558
- (stdout , stderr ) = p .communicate (a_input )
558
+ stdout , stderr = p .communicate (to_bytes (a_input ))
559
+ stdout , stderr = to_str (stdout ), to_str (stderr )
559
560
560
561
if timeout is not None :
561
562
if p .returncode >= 0 :
@@ -783,11 +784,23 @@ def run_fn_if_el_release_ok(*args, **kwargs):
783
784
return el_release_decorator
784
785
785
786
786
- try :
787
- unicode
788
- except NameError : # python 3
789
- unicode = str
787
+ def to_str (strlike , encoding = "latin-1" , errors = "backslashreplace" ):
788
+ """Turns a bytes into a str (Python 3) or a unicode to a str (Python 2)"""
789
+ if strlike is None :
790
+ return
791
+ if not isinstance (strlike , str ):
792
+ if str is bytes :
793
+ return strlike .encode (encoding , errors )
794
+ else :
795
+ return strlike .decode (encoding , errors )
796
+ else :
797
+ return strlike
790
798
791
799
792
- def is_string (var ):
793
- return isinstance (var , (str , unicode ))
800
+ def to_bytes (strlike , encoding = "latin-1" , errors = "backslashreplace" ):
801
+ """Turns a str into bytes (Python 3) or a unicode to a str (Python 2)"""
802
+ if strlike is None :
803
+ return
804
+ if not isinstance (strlike , bytes ):
805
+ return strlike .encode (encoding , errors )
806
+ return strlike
0 commit comments