Bug 221981 - [LayoutTests] Convert http/tests/misc convert PHP to Python
Summary: [LayoutTests] Convert http/tests/misc convert PHP to Python
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Tools / Tests (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Chris Gambrell
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2021-02-16 11:28 PST by Chris Gambrell
Modified: 2021-04-06 15:20 PDT (History)
12 users (show)

See Also:


Attachments
Patch (74.17 KB, patch)
2021-02-17 12:33 PST, Chris Gambrell
no flags Details | Formatted Diff | Diff
Patch (90.47 KB, patch)
2021-02-17 14:22 PST, Chris Gambrell
no flags Details | Formatted Diff | Diff
Patch (84.63 KB, patch)
2021-02-17 14:53 PST, Chris Gambrell
no flags Details | Formatted Diff | Diff
Patch (88.17 KB, patch)
2021-02-17 15:06 PST, Chris Gambrell
no flags Details | Formatted Diff | Diff
Patch (84.58 KB, patch)
2021-02-17 16:08 PST, Chris Gambrell
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (84.59 KB, patch)
2021-02-17 20:39 PST, Chris Gambrell
no flags Details | Formatted Diff | Diff
Patch (110.71 KB, patch)
2021-02-18 14:23 PST, Chris Gambrell
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (132.78 KB, patch)
2021-02-18 16:56 PST, Chris Gambrell
no flags Details | Formatted Diff | Diff
Patch (138.77 KB, patch)
2021-02-18 21:20 PST, Chris Gambrell
no flags Details | Formatted Diff | Diff
Patch (14.11 KB, patch)
2021-02-19 11:41 PST, Chris Gambrell
no flags Details | Formatted Diff | Diff
Patch (23.73 KB, patch)
2021-02-19 12:31 PST, Chris Gambrell
no flags Details | Formatted Diff | Diff
Patch (26.00 KB, patch)
2021-02-19 12:56 PST, Chris Gambrell
no flags Details | Formatted Diff | Diff
Patch (25.27 KB, patch)
2021-02-19 13:09 PST, Chris Gambrell
no flags Details | Formatted Diff | Diff
Patch (22.93 KB, patch)
2021-02-19 13:13 PST, Chris Gambrell
no flags Details | Formatted Diff | Diff
Patch (40.08 KB, patch)
2021-02-19 15:36 PST, Chris Gambrell
no flags Details | Formatted Diff | Diff
Patch (59.37 KB, patch)
2021-02-19 16:07 PST, Chris Gambrell
no flags Details | Formatted Diff | Diff
Patch (104.23 KB, patch)
2021-02-19 17:07 PST, Chris Gambrell
no flags Details | Formatted Diff | Diff
Patch (102.51 KB, patch)
2021-02-22 07:21 PST, Chris Gambrell
no flags Details | Formatted Diff | Diff
Patch (105.89 KB, patch)
2021-02-22 08:11 PST, Chris Gambrell
no flags Details | Formatted Diff | Diff
Patch (121.03 KB, patch)
2021-02-22 09:38 PST, Chris Gambrell
no flags Details | Formatted Diff | Diff
Patch (114.36 KB, patch)
2021-02-22 10:22 PST, Chris Gambrell
no flags Details | Formatted Diff | Diff
Patch (126.18 KB, patch)
2021-02-22 11:05 PST, Chris Gambrell
no flags Details | Formatted Diff | Diff
Patch (189.85 KB, patch)
2021-02-22 13:58 PST, Chris Gambrell
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (188.95 KB, patch)
2021-02-22 21:07 PST, Chris Gambrell
no flags Details | Formatted Diff | Diff
Patch (195.98 KB, patch)
2021-02-23 06:19 PST, Chris Gambrell
no flags Details | Formatted Diff | Diff
Patch (189.78 KB, patch)
2021-02-23 14:30 PST, Chris Gambrell
no flags Details | Formatted Diff | Diff
Patch (191.63 KB, patch)
2021-03-01 13:15 PST, Chris Gambrell
no flags Details | Formatted Diff | Diff
Patch (189.48 KB, patch)
2021-03-01 13:33 PST, Chris Gambrell
no flags Details | Formatted Diff | Diff
Patch (185.90 KB, patch)
2021-03-01 17:22 PST, Chris Gambrell
no flags Details | Formatted Diff | Diff
Patch (186.97 KB, patch)
2021-03-02 08:17 PST, Chris Gambrell
no flags Details | Formatted Diff | Diff
Patch (24.38 KB, patch)
2021-04-01 21:34 PDT, Chris Gambrell
no flags Details | Formatted Diff | Diff
Patch (19.91 KB, patch)
2021-04-01 21:39 PDT, Chris Gambrell
no flags Details | Formatted Diff | Diff
Patch (14.01 KB, patch)
2021-04-01 21:47 PDT, Chris Gambrell
no flags Details | Formatted Diff | Diff
Patch (15.20 KB, patch)
2021-04-02 11:23 PDT, Chris Gambrell
no flags Details | Formatted Diff | Diff
Patch (14.04 KB, patch)
2021-04-02 12:04 PDT, Chris Gambrell
jbedard: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Gambrell 2021-02-16 11:28:55 PST
Replacing PHP with equivalent Python CGI scripts
Comment 1 Radar WebKit Bug Importer 2021-02-16 11:29:38 PST
<rdar://problem/74399686>
Comment 2 Chris Gambrell 2021-02-17 12:33:23 PST
Created attachment 420693 [details]
Patch
Comment 3 Chris Gambrell 2021-02-17 14:22:26 PST
Created attachment 420714 [details]
Patch
Comment 4 Chris Gambrell 2021-02-17 14:53:09 PST
Created attachment 420724 [details]
Patch
Comment 5 Chris Gambrell 2021-02-17 15:06:16 PST
Created attachment 420728 [details]
Patch
Comment 6 Chris Gambrell 2021-02-17 16:08:15 PST
Created attachment 420750 [details]
Patch
Comment 7 Chris Gambrell 2021-02-17 20:39:01 PST
Created attachment 420792 [details]
Patch
Comment 8 Jonathan Bedard 2021-02-18 11:06:45 PST
Comment on attachment 420792 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=420792&action=review

> LayoutTests/http/tests/misc/resources/charset-sniffer-end-sniffing.py:15
> +for i in range(0, 10000):

The usual idiom when you have a variable that you need to complete a statement but that you are not actually going to use is to use '_'

> LayoutTests/http/tests/misc/resources/check-test-file.py:28
> +        'PASS: File upload was successful\n'

Is there any "error" equivalent in Python? This code isn't exactly the same, although it's the same in the successful case, so that's probably sufficient.

> LayoutTests/http/tests/misc/resources/check-unnamed-file-included-in-formdata.py:23
> +if data != None:

Style is to use "data is not None" in this case.

> LayoutTests/http/tests/misc/resources/redirect-to-http-url.py:1
> +#!/usr/bin/env python3

Is there a php file being removed here?

> LayoutTests/http/tests/misc/resources/referrer-main-resource.py:6
> +referer = os.environ.get('HTTP_REFERER', '')

Don't need the default empty string (since you aren't printing it) and you probably don't need the variable either and could just put the os.environ.get in the if statement

> LayoutTests/http/tests/misc/resources/referrer-result.py:14
> +# formatting string

Remove this comment. I suspect the issue is about the brackets in the string, and can be mitigated with double brackets, but it's not a huge issue if these stay as "prints"

> LayoutTests/http/tests/misc/resources/stylesheet-bad-mime-type.py:18
> +    sys.stdout.write('\r\n')

I think we want the 406 status code here
Comment 9 Chris Gambrell 2021-02-18 14:23:26 PST
Created attachment 420871 [details]
Patch
Comment 10 Chris Gambrell 2021-02-18 16:56:25 PST
Created attachment 420886 [details]
Patch
Comment 11 Chris Gambrell 2021-02-18 21:20:54 PST
Created attachment 420917 [details]
Patch
Comment 12 Chris Gambrell 2021-02-19 11:41:27 PST
Created attachment 421001 [details]
Patch
Comment 13 Chris Gambrell 2021-02-19 12:31:05 PST
Created attachment 421010 [details]
Patch
Comment 14 Chris Gambrell 2021-02-19 12:56:18 PST
Created attachment 421018 [details]
Patch
Comment 15 Chris Gambrell 2021-02-19 13:09:42 PST
Created attachment 421019 [details]
Patch
Comment 16 Chris Gambrell 2021-02-19 13:13:45 PST
Created attachment 421021 [details]
Patch
Comment 17 Chris Gambrell 2021-02-19 15:36:50 PST
Created attachment 421048 [details]
Patch
Comment 18 Chris Gambrell 2021-02-19 15:41:46 PST
(In reply to Jonathan Bedard from comment #8)
> Comment on attachment 420792 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=420792&action=review
> 
> > LayoutTests/http/tests/misc/resources/charset-sniffer-end-sniffing.py:15
> > +for i in range(0, 10000):
> 
> The usual idiom when you have a variable that you need to complete a
> statement but that you are not actually going to use is to use '_'
> 
> > LayoutTests/http/tests/misc/resources/check-test-file.py:28
> > +        'PASS: File upload was successful\n'
> 
> Is there any "error" equivalent in Python? This code isn't exactly the same,
> although it's the same in the successful case, so that's probably sufficient.
> 
> > LayoutTests/http/tests/misc/resources/check-unnamed-file-included-in-formdata.py:23
> > +if data != None:
> 
> Style is to use "data is not None" in this case.
> 
> > LayoutTests/http/tests/misc/resources/redirect-to-http-url.py:1
> > +#!/usr/bin/env python3
> 
> Is there a php file being removed here?
> 
> > LayoutTests/http/tests/misc/resources/referrer-main-resource.py:6
> > +referer = os.environ.get('HTTP_REFERER', '')
> 
> Don't need the default empty string (since you aren't printing it) and you
> probably don't need the variable either and could just put the
> os.environ.get in the if statement
> 
> > LayoutTests/http/tests/misc/resources/referrer-result.py:14
> > +# formatting string
> 
> Remove this comment. I suspect the issue is about the brackets in the
> string, and can be mitigated with double brackets, but it's not a huge issue
> if these stay as "prints"
> 
> > LayoutTests/http/tests/misc/resources/stylesheet-bad-mime-type.py:18
> > +    sys.stdout.write('\r\n')
> 
> I think we want the 406 status code here

Fixed in comment 17
Comment 19 Chris Gambrell 2021-02-19 16:07:31 PST
Created attachment 421054 [details]
Patch
Comment 20 Chris Gambrell 2021-02-19 17:07:18 PST
Created attachment 421061 [details]
Patch
Comment 21 Chris Gambrell 2021-02-22 07:21:21 PST
Created attachment 421189 [details]
Patch
Comment 22 Chris Gambrell 2021-02-22 08:11:48 PST
Created attachment 421193 [details]
Patch
Comment 23 Chris Gambrell 2021-02-22 09:38:26 PST
Created attachment 421204 [details]
Patch
Comment 24 Chris Gambrell 2021-02-22 10:22:18 PST
Created attachment 421208 [details]
Patch
Comment 25 Chris Gambrell 2021-02-22 11:05:29 PST
Created attachment 421213 [details]
Patch
Comment 26 Chris Gambrell 2021-02-22 13:58:05 PST
Created attachment 421237 [details]
Patch
Comment 27 Chris Gambrell 2021-02-22 21:07:31 PST
Created attachment 421282 [details]
Patch
Comment 28 Chris Gambrell 2021-02-23 06:19:24 PST
Created attachment 421309 [details]
Patch
Comment 29 Chris Gambrell 2021-02-23 14:30:13 PST
Created attachment 421351 [details]
Patch
Comment 30 Chris Gambrell 2021-02-23 14:32:47 PST
(In reply to Chris Gambrell from comment #29)
> Created attachment 421351 [details]
> Patch

There are still 3 PHP files remaining. Talked to Jonathan and it is beneficial to proceed with committing the changes that are complete and move on to more directories to keep progressing through the files we need to convert.

This directory will be revisited later. After cq+ the bug should remain open and not resolved.

LayoutTests/http/tests/misc/resources/redirect-to-http-url.php
LayoutTests/http/tests/misc/resources/prefetch-purpose.php
LayoutTests/http/tests/misc/resources/check-query-param.php
Comment 31 Jonathan Bedard 2021-02-25 11:49:10 PST
Comment on attachment 421351 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=421351&action=review

> LayoutTests/http/tests/loading/resources/slowimage.py:1
> +#!/usr/bin/env python3

I don't see the file that this is replacing, and it looks like a duplicate?

> LayoutTests/http/tests/misc/refresh-headers.py:11
> +if cache_control.lower() == 'no-cache' or pragma.lower == 'no-cache':

Should be pragma.lower()

> LayoutTests/http/tests/misc/resources/char-encoding-in-hidden-charset-field.py:7
> +data = ''.join(sys.stdin.readlines())

It seems wrong to read data if our request method is not a POST request

> LayoutTests/http/tests/misc/resources/check-query-param.py:1
> +#!/usr/bin/env python3

I don't see the PHP file we are replacing removed.

> LayoutTests/http/tests/misc/resources/dns-prefetch-control.py:10
> +sys.stdout.write('Content-Type: text/html\r\n\r\n')

X-DNS-Prefetch-Control is part of the header. You are ending the header here.

> LayoutTests/http/tests/misc/resources/dns-prefetch-control.py:17
> +    sys.stdout.write('X-DNS-Prefetch-Control: foo\r\n\r\n')

Maybe just:
if value in ['on', 'off', 'foo']:
    sys.stdout.write('X-DNS-Prefetch-Control: off\r\n'.format(value))

> LayoutTests/http/tests/misc/resources/image-checks-for-accept.py:6
> +allimages = 'image/*'

This doesn't really need be a variable.

> LayoutTests/http/tests/misc/resources/webtiming-cross-origin-and-back-redirect2.php:-2
> -  // 127.0.0.1 is where the test originally started. We redirected to "localhost" before this.

I would keep this comment in the Python file

> LayoutTests/http/tests/misc/resources/protected/protected-image.py:15
> +if !username:

Use `not username`
Comment 32 Chris Gambrell 2021-03-01 13:15:36 PST
Created attachment 421859 [details]
Patch
Comment 33 Chris Gambrell 2021-03-01 13:33:58 PST
Created attachment 421861 [details]
Patch
Comment 34 Chris Gambrell 2021-03-01 17:22:52 PST
Created attachment 421892 [details]
Patch
Comment 35 Chris Gambrell 2021-03-02 08:17:45 PST
Created attachment 421937 [details]
Patch
Comment 36 EWS 2021-03-03 09:14:57 PST
Committed r273819: <https://commits.webkit.org/r273819>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 421937 [details].
Comment 37 Chris Gambrell 2021-04-01 20:34:49 PDT
Reopening for second pass
Comment 38 Chris Gambrell 2021-04-01 21:34:05 PDT
Created attachment 424985 [details]
Patch
Comment 39 Chris Gambrell 2021-04-01 21:39:42 PDT
Created attachment 424986 [details]
Patch
Comment 40 Chris Gambrell 2021-04-01 21:47:24 PDT
Created attachment 424987 [details]
Patch
Comment 41 Chris Gambrell 2021-04-01 21:53:11 PDT
Comment on attachment 424987 [details]
Patch

apply-patch is having issues processing http/tests/misc/will-send-request-returns-null-on-redirect.html's resources being converted from .php to .py. No other tests use http/tests/misc/resources/redirect-to-http-url.php so I have included the .py version without removing the .php file so that EWS can chew on the other converted files. 

The test file that references http/tests/misc/resources/redirect-to-http-url.py (the file that is having trouble going through apply-patch) passes locally on wk1 and wk2. 

platform/wk2/http/tests/misc/will-send-request-returns-null-on-redirect-expected.txt will need to be updated along with http/tests/misc/will-send-request-returns-null-on-redirect.html and http/tests/misc/will-send-request-returns-null-on-redirect-expected.txt. 

Once r+, I will remove the .php version and update the files in question to reflect the .py version instead of the .php and will land it manually to bypass the apply-patch issues
Comment 42 Jonathan Bedard 2021-04-02 10:02:20 PDT
Comment on attachment 424987 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=424987&action=review

> LayoutTests/http/tests/misc/resources/check-query-param.py:21
> +if 'HTTP_COOKIE' in os.environ:

Might consider using get_cookies and request.update()

> LayoutTests/http/tests/misc/resources/redirect-to-http-url.py:1
> +#!/usr/bin/env python3

Where is the php file we're replacing? Is it still used elsewhere?
Comment 43 Chris Gambrell 2021-04-02 11:23:14 PDT
Created attachment 425034 [details]
Patch
Comment 44 Chris Gambrell 2021-04-02 11:23:59 PDT
(In reply to Jonathan Bedard from comment #42)
> Comment on attachment 424987 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=424987&action=review
> 
> > LayoutTests/http/tests/misc/resources/check-query-param.py:21
> > +if 'HTTP_COOKIE' in os.environ:
> 
> Might consider using get_cookies and request.update()
> 
> > LayoutTests/http/tests/misc/resources/redirect-to-http-url.py:1
> > +#!/usr/bin/env python3
> 
> Where is the php file we're replacing? Is it still used elsewhere?

See comment 41
Comment 45 Jonathan Bedard 2021-04-02 11:44:51 PDT
Comment on attachment 425034 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=425034&action=review

> LayoutTests/http/tests/misc/resources/check-query-param.py:29
> +    request.update({ key: cookies[key] })

Don't need a loop here, request.update(get_cookies()) should work
Comment 46 Chris Gambrell 2021-04-02 12:04:16 PDT
Created attachment 425036 [details]
Patch
Comment 47 Chris Gambrell 2021-04-06 15:20:23 PDT
Committed r275561 (236216@main): <https://commits.webkit.org/236216@main>