Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf735ee5

Browse files
committed
reuse 127.0.0.1 everywhere???
1 parent4ad442a commitf735ee5

File tree

1 file changed

+11
-18
lines changed

1 file changed

+11
-18
lines changed

‎Lib/test/test_httpservers.py

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1478,31 +1478,26 @@ def fetch_file(self, path, context=None):
14781478
returnres.read()
14791479

14801480
defparse_cli_output(self,output):
1481-
matches=re.search(r'Serving (HTTP|HTTPS) on (.+) port (\d+)',output)
1482-
ifmatchesisNone:
1481+
match=re.search(r'Serving (HTTP|HTTPS) on (.+) port (\d+)',output)
1482+
ifmatchisNone:
14831483
returnNone,None,None
1484-
returnmatches.group(1).lower(),matches.group(2),int(matches.group(3))
1484+
returnmatch.group(1).lower(),match.group(2),int(match.group(3))
14851485

1486-
defwait_for_server(self,proc,protocol,port):
1487-
"""Extractthe serverbind address once ithas been started."""
1486+
defwait_for_server(self,proc,protocol,bind,port):
1487+
"""Check thatthe server has been successfully started."""
14881488
line=proc.stdout.readline().strip()
14891489
ifsupport.verbose:
14901490
print()
14911491
print('python -m http.server: ',line)
1492-
parsed_protocol,host,parsed_port=self.parse_cli_output(line)
1493-
ifprotocol==parsed_protocolandparsed_port==port:
1494-
returnhost
1495-
returnNone
1492+
returnself.parse_cli_output(line)== (protocol,bind,port)
14961493

14971494
deftest_http_client(self):
1498-
port=find_unused_port()
1499-
proc=spawn_python('-u','-m','http.server',str(port),
1495+
bind,port='127.0.0.1',find_unused_port()
1496+
proc=spawn_python('-u','-m','http.server',str(port),'-b',bind,
15001497
bufsize=1,text=True)
15011498
self.addCleanup(kill_python,proc)
15021499
self.addCleanup(proc.terminate)
1503-
bind=self.wait_for_server(proc,'http',port)
1504-
self.assertIsNotNone(bind)
1505-
# localhost may be redirected to something else for whatever reason
1500+
self.assertTrue(self.wait_for_server(proc,'http',bind,port))
15061501
res=self.fetch_file(f'http://{bind}:{port}/{self.served_filename}')
15071502
self.assertEqual(res,self.served_data)
15081503

@@ -1514,16 +1509,14 @@ def test_https_client(self):
15141509
context.verify_mode=ssl.CERT_NONE
15151510

15161511
bind,port='127.0.0.1',find_unused_port()
1517-
proc=spawn_python('-u','-m','http.server',str(port),
1518-
'-b',bind,
1512+
proc=spawn_python('-u','-m','http.server',str(port),'-b',bind,
15191513
'--tls-cert',self.tls_cert,
15201514
'--tls-key',self.tls_key,
15211515
'--tls-password-file',self.tls_password_file,
15221516
bufsize=1,text=True)
15231517
self.addCleanup(kill_python,proc)
15241518
self.addCleanup(proc.terminate)
1525-
bind=self.wait_for_server(proc,'https',port)
1526-
self.assertIsNotNone(bind)
1519+
self.assertTrue(self.wait_for_server(proc,'https',bind,port))
15271520
url=f'https://{bind}:{port}/{self.served_filename}'
15281521
res=self.fetch_file(url,context=context)
15291522
self.assertEqual(res,self.served_data)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp