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
ccc87b53
Commit
ccc87b53
authored
May 10, 2011
by
Antoine Pitrou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #12054: use support.find_unused_port() instead of reinventing the wheel
parent
1be815aa
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
2 additions
and
16 deletions
+2
-16
Lib/test/test_socket.py
Lib/test/test_socket.py
+2
-16
No files found.
Lib/test/test_socket.py
View file @
ccc87b53
...
@@ -564,23 +564,9 @@ class GeneralModuleTests(unittest.TestCase):
...
@@ -564,23 +564,9 @@ class GeneralModuleTests(unittest.TestCase):
# XXX The following don't test module-level functionality...
# XXX The following don't test module-level functionality...
def
_get_unused_port
(
self
,
bind_address
=
'0.0.0.0'
):
"""Use a temporary socket to elicit an unused ephemeral port.
Args:
bind_address: Hostname or IP address to search for a port on.
Returns: A most likely to be unused port.
"""
tempsock
=
socket
.
socket
()
tempsock
.
bind
((
bind_address
,
0
))
host
,
port
=
tempsock
.
getsockname
()
tempsock
.
close
()
return
port
def
testSockName
(
self
):
def
testSockName
(
self
):
# Testing getsockname()
# Testing getsockname()
port
=
s
elf
.
_get
_unused_port
()
port
=
s
upport
.
find
_unused_port
()
sock
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
sock
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
self
.
addCleanup
(
sock
.
close
)
self
.
addCleanup
(
sock
.
close
)
sock
.
bind
((
"0.0.0.0"
,
port
))
sock
.
bind
((
"0.0.0.0"
,
port
))
...
@@ -629,7 +615,7 @@ class GeneralModuleTests(unittest.TestCase):
...
@@ -629,7 +615,7 @@ class GeneralModuleTests(unittest.TestCase):
def
test_getsockaddrarg
(
self
):
def
test_getsockaddrarg
(
self
):
host
=
'0.0.0.0'
host
=
'0.0.0.0'
port
=
s
elf
.
_get_unused_port
(
bind_address
=
host
)
port
=
s
upport
.
find_unused_port
(
)
big_port
=
port
+
65536
big_port
=
port
+
65536
neg_port
=
port
-
65536
neg_port
=
port
-
65536
sock
=
socket
.
socket
()
sock
=
socket
.
socket
()
...
...
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