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

Commit9192281

Browse files
authored
Update test_httpservers.py
1 parente818bb6 commit9192281

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

‎Lib/test/test_httpservers.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,6 +1472,14 @@ def setUp(self):
14721472
f.write(self.tls_password.encode())
14731473
self.addCleanup(os_helper.unlink,self.tls_password_file)
14741474

1475+
@unittest.skipIf(sslisNone,"requires ssl")
1476+
defget_ssl_context(self):
1477+
context=ssl.create_default_context()
1478+
# allow self-signed certificates
1479+
context.check_hostname=False
1480+
context.verify_mode=ssl.CERT_NONE
1481+
returncontext
1482+
14751483
deffetch_file(self,path,context=None):
14761484
req=urllib.request.Request(path,method='GET')
14771485
withurllib.request.urlopen(req,context=context)asres:
@@ -1506,8 +1514,7 @@ def wait_for_server(self, proc, protocol, port, bind, timeout=50):
15061514
returnFalse
15071515

15081516
deftest_http_client(self):
1509-
port=find_unused_port()
1510-
bind='127.0.0.1'
1517+
_, (bind,port)=server._get_best_family(None,find_unused_port())
15111518
proc=spawn_python('-u','-m','http.server',str(port),'-b',bind,
15121519
bufsize=1,text=True)
15131520
self.addCleanup(kill_python,proc)
@@ -1516,15 +1523,8 @@ def test_http_client(self):
15161523
res=self.fetch_file(f'http://{bind}:{port}/{self.served_file_name}')
15171524
self.assertEqual(res,self.served_data)
15181525

1519-
@unittest.skipIf(sslisNone,"requires ssl")
15201526
deftest_https_client(self):
1521-
context=ssl.create_default_context()
1522-
# allow self-signed certificates
1523-
context.check_hostname=False
1524-
context.verify_mode=ssl.CERT_NONE
1525-
1526-
port=find_unused_port()
1527-
bind='127.0.0.1'
1527+
_, (bind,port)=server._get_best_family(None,find_unused_port())
15281528
proc=spawn_python('-u','-m','http.server',str(port),'-b',bind,
15291529
'--tls-cert',self.tls_cert,
15301530
'--tls-key',self.tls_key,
@@ -1533,8 +1533,8 @@ def test_https_client(self):
15331533
self.addCleanup(kill_python,proc)
15341534
self.addCleanup(proc.terminate)
15351535
self.assertTrue(self.wait_for_server(proc,'https',port,bind))
1536-
res=self.fetch_file(f'https://{bind}:{port}/{self.served_file_name}',
1537-
context=context)
1536+
url=f'https://{bind}:{port}/{self.served_file_name}'
1537+
res=self.fetch_file(url,context=self.get_ssl_context())
15381538
self.assertEqual(res,self.served_data)
15391539

15401540

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp