<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>264237</bug_id>
          
          <creation_ts>2023-11-05 22:42:33 -0800</creation_ts>
          <short_desc>[meta] Python CGI should use binary mode for stdout for Windows Python</short_desc>
          <delta_ts>2025-02-19 04:35:07 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>Tools / Tests</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          <dependson>263425</dependson>
    
    <dependson>263701</dependson>
    
    <dependson>264238</dependson>
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Fujii Hironori">fujii</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>kohei.asano</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1990087</commentid>
    <comment_count>0</comment_count>
    <who name="Fujii Hironori">fujii</who>
    <bug_when>2023-11-05 22:42:33 -0800</bug_when>
    <thetext>[meta] Python CGI should use binary mode for stdout for Windows Python

Windows Python automatically converts &apos;\n&apos; to &apos;\r\n&apos; for text mode.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1992029</commentid>
    <comment_count>1</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2023-11-12 22:43:14 -0800</bug_when>
    <thetext>&lt;rdar://problem/118316460&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2091721</commentid>
    <comment_count>2</comment_count>
    <who name="Kohei Asano">kohei.asano</who>
    <bug_when>2025-02-03 21:52:04 -0800</bug_when>
    <thetext>Although this is just cleaning for pre-existing file only, but we can fix this by inserting sys.stdout.reconfigure(newline=&apos;&apos;);


```bash
C:\Users\0300093582\tmp&gt;python -c &quot;import sys;sys.stdout.reconfigure(newline=&apos;&apos;);sys.stdout.write(&apos;Hello\nWorld\n&apos;)&quot; | xxd 
00000000: 4865 6c6c 6f0a 576f 726c 640a            Hello.World.
```



also on Linux(Ubuntu) I confirmed no effect appears

```bash
[12:22] JPC00234727:tmp | python3 -c &quot;import sys;sys.stdout.reconfigure(newline=&apos;&apos;);sys.stdout.write(&apos;Hello\nWorld\n&apos;)&quot; | xxd
00000000: 4865 6c6c 6f0a 576f 726c 640a            Hello.World.
[12:24] JPC00234727:tmp | cat /etc/os-release 
PRETTY_NAME=&quot;Ubuntu 22.04.4 LTS&quot;
```</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2091733</commentid>
    <comment_count>3</comment_count>
    <who name="Kohei Asano">kohei.asano</who>
    <bug_when>2025-02-03 22:19:06 -0800</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/39971</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2091735</commentid>
    <comment_count>4</comment_count>
    <who name="Kohei Asano">kohei.asano</who>
    <bug_when>2025-02-03 22:23:16 -0800</bug_when>
    <thetext>I tried to fix by the following shell script, but its lines are much more than I expected, I&apos;m not so sure it&apos;s worth to apply all, but I leave this for notes

```
I inserted by the following shell scripts, and it was 

#!/bin/bash

TARGET_DIR=&quot;LayoutTests&quot;

grep -rl &apos;sys.stdout.write&apos; &quot;$TARGET_DIR&quot; --include=&quot;*.py&quot; | while read -r file; do
    tmpfile=$(mktemp)
    inserted=0

    while IFS= read -r line || [[ -n &quot;$line&quot; ]]; do
        echo &quot;$line&quot; &gt;&gt; &quot;$tmpfile&quot;

        if [[ $line =~ ^[[:space:]]*import\ sys$ ]]; then
            indent=$(echo &quot;$line&quot; | grep -o &apos;^[[:space:]]*&apos;)
            echo &quot;${indent}sys.stdout.reconfigure(newline=\&quot;\&quot;)  # prevent windows \n -&gt; \n\r conversion&quot; &gt;&gt; &quot;$tmpfile&quot;
        fi
    done &lt; &quot;$file&quot;

    mv &quot;$tmpfile&quot; &quot;$file&quot;
done

```</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2095825</commentid>
    <comment_count>5</comment_count>
    <who name="Kohei Asano">kohei.asano</who>
    <bug_when>2025-02-19 04:35:07 -0800</bug_when>
    <thetext>&gt; Pull request: https://github.com/WebKit/WebKit/pull/39971
I&apos;m sorry, I think PR itself is a little bothering because of too much noises. Also I learned meta issue meaning. Thanks!</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>