Skip to content

Commit 1b5d296

Browse files
committed
xcresult_logs.py: Another fix for when sys.stdout does not have a 'buffer' attribute
1 parent ae9bdf5 commit 1b5d296

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

scripts/xcresult_logs.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,15 @@ def main():
6666
log = export_log(xcresult_path, log_id)
6767

6868
# Avoid a potential UnicodeEncodeError raised by sys.stdout.write() by
69-
# doing a relaxed encoding ourselves and writing the resulting bytes.
70-
log_encoded = log.encode('utf8', errors='backslashreplace')
71-
sys.stdout.flush()
72-
sys.stdout.buffer.write(log_encoded)
69+
# doing a relaxed encoding ourselves.
70+
if hasattr(sys.stdout, 'buffer'):
71+
log_encoded = log.encode('utf8', errors='backslashreplace')
72+
sys.stdout.flush()
73+
sys.stdout.buffer.write(log_encoded)
74+
else:
75+
log_encoded = log.encode('ascii', errors='backslashreplace')
76+
log_decoded = log_encoded.decode('ascii', errors='strict')
77+
sys.stdout.write(log_decoded)
7378

7479

7580
# Most flags on the xcodebuild command-line are uninteresting, so only pull

0 commit comments

Comments
 (0)