mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
Merged revisions 77263-77264 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r77263 | gregory.p.smith | 2010-01-02 17:29:44 -0800 (Sat, 02 Jan 2010) | 4 lines Adds an optional source_address parameter to socket.create_connection(). For use by issue3972. ........ r77264 | gregory.p.smith | 2010-01-02 18:06:07 -0800 (Sat, 02 Jan 2010) | 5 lines issue3972: HTTPConnection and HTTPSConnection now support a source_address parameter. Also cleans up an annotation in the socket documentation. ........
This commit is contained in:
parent
91ae4a1404
commit
b4066374db
7 changed files with 89 additions and 14 deletions
|
@ -4,7 +4,8 @@ import io
|
|||
import array
|
||||
import socket
|
||||
|
||||
from unittest import TestCase
|
||||
import unittest
|
||||
TestCase = unittest.TestCase
|
||||
|
||||
from test import support
|
||||
|
||||
|
@ -263,6 +264,38 @@ class OfflineTest(TestCase):
|
|||
def test_responses(self):
|
||||
self.assertEquals(client.responses[client.NOT_FOUND], "Not Found")
|
||||
|
||||
|
||||
class SourceAddressTest(TestCase):
|
||||
def setUp(self):
|
||||
self.serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
self.port = support.bind_port(self.serv)
|
||||
self.source_port = support.find_unused_port()
|
||||
self.serv.listen(5)
|
||||
self.conn = None
|
||||
|
||||
def tearDown(self):
|
||||
if self.conn:
|
||||
self.conn.close()
|
||||
self.conn = None
|
||||
self.serv.close()
|
||||
self.serv = None
|
||||
|
||||
def testHTTPConnectionSourceAddress(self):
|
||||
self.conn = client.HTTPConnection(HOST, self.port,
|
||||
source_address=('', self.source_port))
|
||||
self.conn.connect()
|
||||
self.assertEqual(self.conn.sock.getsockname()[1], self.source_port)
|
||||
|
||||
@unittest.skipIf(not hasattr(client, 'HTTPSConnection'),
|
||||
'http.client.HTTPSConnection not defined')
|
||||
def testHTTPSConnectionSourceAddress(self):
|
||||
self.conn = client.HTTPSConnection(HOST, self.port,
|
||||
source_address=('', self.source_port))
|
||||
# We don't test anything here other the constructor not barfing as
|
||||
# this code doesn't deal with setting up an active running SSL server
|
||||
# for an ssl_wrapped connect() to actually return from.
|
||||
|
||||
|
||||
class TimeoutTest(TestCase):
|
||||
PORT = None
|
||||
|
||||
|
@ -390,7 +423,7 @@ class RequestBodyTest(TestCase):
|
|||
|
||||
def test_main(verbose=None):
|
||||
support.run_unittest(HeaderTests, OfflineTest, BasicTest, TimeoutTest,
|
||||
HTTPSTimeoutTest, RequestBodyTest)
|
||||
HTTPSTimeoutTest, RequestBodyTest, SourceAddressTest)
|
||||
|
||||
if __name__ == '__main__':
|
||||
test_main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue