mirror of
https://github.com/python/cpython.git
synced 2025-08-01 07:33:08 +00:00
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
79a3eb1058
commit
9d3252154f
5 changed files with 61 additions and 12 deletions
|
@ -3,7 +3,8 @@ import httplib
|
|||
import StringIO
|
||||
import socket
|
||||
|
||||
from unittest import TestCase
|
||||
import unittest
|
||||
TestCase = unittest.TestCase
|
||||
|
||||
from test import test_support
|
||||
|
||||
|
@ -237,6 +238,38 @@ class OfflineTest(TestCase):
|
|||
def test_responses(self):
|
||||
self.assertEquals(httplib.responses[httplib.NOT_FOUND], "Not Found")
|
||||
|
||||
|
||||
class SourceAddressTest(TestCase):
|
||||
def setUp(self):
|
||||
self.serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
self.port = test_support.bind_port(self.serv)
|
||||
self.source_port = test_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 = httplib.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(httplib, 'HTTPSConnection'),
|
||||
'httplib.HTTPSConnection not defined')
|
||||
def testHTTPSConnectionSourceAddress(self):
|
||||
self.conn = httplib.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
|
||||
|
||||
|
@ -294,7 +327,7 @@ class HTTPSTimeoutTest(TestCase):
|
|||
|
||||
def test_main(verbose=None):
|
||||
test_support.run_unittest(HeaderTests, OfflineTest, BasicTest, TimeoutTest,
|
||||
HTTPSTimeoutTest)
|
||||
HTTPSTimeoutTest, SourceAddressTest)
|
||||
|
||||
if __name__ == '__main__':
|
||||
test_main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue