Skip to content

Commit 0b4e64d

Browse files
committed
Fix printStandardStream possible decode bug
Signed-off-by: Loren Eteval <loren.eteval@proton.me>
1 parent 3866549 commit 0b4e64d

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

Deploy.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import subprocess
3030
import urllib.request
3131

32+
from typing import AnyStr
33+
3234
logging.basicConfig(
3335
format='[%(asctime)s] [%(name)s] [%(levelname)s] %(message)s',
3436
level=logging.INFO,
@@ -362,18 +364,20 @@ def download():
362364
)
363365

364366

365-
def printStandardStream(stdout, stderr):
366-
if isinstance(stdout, bytes):
367-
decoded_stdout = stdout.decode('utf-8', 'replace')
367+
def printStandardStream(stdout: AnyStr, stderr: AnyStr):
368+
if isinstance(stdout, str):
369+
encoded_stdout = stdout.encode()
368370
else:
369-
decoded_stdout = stdout
371+
encoded_stdout = stdout
370372

371-
if isinstance(stderr, bytes):
372-
decoded_stderr = stderr.decode('utf-8', 'replace')
373+
if isinstance(stderr, str):
374+
encoded_stderr = stderr.encode()
373375
else:
374-
decoded_stderr = stderr
376+
encoded_stderr = stderr
377+
378+
encoded_output = b'stdout:\n%sstderr:\n%s' % (encoded_stdout, encoded_stderr)
375379

376-
print(f'stdout:\n{decoded_stdout}stderr:\n{decoded_stderr}', flush=True)
380+
print(encoded_output.decode('utf-8', 'ignore'), flush=True)
377381

378382

379383
def main():

0 commit comments

Comments
 (0)