Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
119c7a62
Commit
119c7a62
authored
Sep 10, 2007
by
Bill Janssen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
A better way of finding an open port to test with.
parent
b5591137
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
3 deletions
+26
-3
Lib/test/test_ssl.py
Lib/test/test_ssl.py
+26
-3
No files found.
Lib/test/test_ssl.py
View file @
119c7a62
...
@@ -381,9 +381,11 @@ else:
...
@@ -381,9 +381,11 @@ else:
# to let the main thread know the socket is gone.
# to let the main thread know the socket is gone.
def
listener
():
def
listener
():
s
=
socket
.
socket
()
s
=
socket
.
socket
()
if
hasattr
(
socket
,
'SO_REUSEADDR'
):
s
.
setsockopt
(
socket
.
SOL_SOCKET
,
socket
.
SO_REUSEADDR
,
1
)
if
hasattr
(
socket
,
'SO_REUSEPORT'
):
if
hasattr
(
socket
,
'SO_REUSEPORT'
):
s
.
setsockopt
(
socket
.
SOL_SOCKET
,
socket
.
SO_REUSEPORT
,
1
)
s
.
setsockopt
(
socket
.
SOL_SOCKET
,
socket
.
SO_REUSEPORT
,
1
)
port
=
test_support
.
bind_port
(
s
,
'
localhost
'
,
TESTPORT
)
port
=
test_support
.
bind_port
(
s
,
'
127.0.0.1
'
,
TESTPORT
)
s
.
listen
(
5
)
s
.
listen
(
5
)
listener_ready
.
set
()
listener_ready
.
set
()
s
.
accept
()
s
.
accept
()
...
@@ -393,7 +395,7 @@ else:
...
@@ -393,7 +395,7 @@ else:
def
connector
():
def
connector
():
listener_ready
.
wait
()
listener_ready
.
wait
()
s
=
socket
.
socket
()
s
=
socket
.
socket
()
s
.
connect
((
'
localhost
'
,
TESTPORT
))
s
.
connect
((
'
127.0.0.1
'
,
TESTPORT
))
listener_gone
.
wait
()
listener_gone
.
wait
()
try
:
try
:
ssl_sock
=
ssl
.
wrap_socket
(
s
)
ssl_sock
=
ssl
.
wrap_socket
(
s
)
...
@@ -668,15 +670,36 @@ def create_cert_files(hostname=None):
...
@@ -668,15 +670,36 @@ def create_cert_files(hostname=None):
return
d
,
crtfile
return
d
,
crtfile
def
findtestsocket
(
start
,
end
):
def
testbind
(
i
):
s
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
try
:
s
.
bind
((
"127.0.0.1"
,
i
))
except
:
return
0
else
:
return
1
finally
:
s
.
close
()
for
i
in
range
(
start
,
end
):
if
testbind
(
i
)
and
testbind
(
i
+
1
):
return
i
return
0
def
test_main
(
verbose
=
False
):
def
test_main
(
verbose
=
False
):
if
skip_expected
:
if
skip_expected
:
raise
test_support
.
TestSkipped
(
"No SSL support"
)
raise
test_support
.
TestSkipped
(
"No SSL support"
)
global
CERTFILE
global
CERTFILE
,
TESTPORT
CERTFILE
=
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
)
or
os
.
curdir
,
CERTFILE
=
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
)
or
os
.
curdir
,
"keycert.pem"
)
"keycert.pem"
)
if
(
not
os
.
path
.
exists
(
CERTFILE
)):
if
(
not
os
.
path
.
exists
(
CERTFILE
)):
raise
test_support
.
TestFailed
(
"Can't read certificate files!"
)
raise
test_support
.
TestFailed
(
"Can't read certificate files!"
)
TESTPORT
=
findtestsocket
(
10025
,
12000
)
if
not
TESTPORT
:
raise
test_support
.
TestFailed
(
"Can't find open port to test servers on!"
)
tests
=
[
BasicTests
]
tests
=
[
BasicTests
]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment