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:
Gregory P. Smith 2010-01-03 03:28:29 +00:00
parent 91ae4a1404
commit b4066374db
7 changed files with 89 additions and 14 deletions

View file

@ -634,8 +634,9 @@ class HTTPConnection:
strict = 0
def __init__(self, host, port=None, strict=None,
timeout=socket._GLOBAL_DEFAULT_TIMEOUT):
timeout=socket._GLOBAL_DEFAULT_TIMEOUT, source_address=None):
self.timeout = timeout
self.source_address = source_address
self.sock = None
self._buffer = []
self.__response = None
@ -707,7 +708,7 @@ class HTTPConnection:
def connect(self):
"""Connect to the host and port specified in __init__."""
self.sock = socket.create_connection((self.host,self.port),
self.timeout)
self.timeout, self.source_address)
if self._tunnel_host:
self._tunnel()
@ -1042,8 +1043,10 @@ else:
default_port = HTTPS_PORT
def __init__(self, host, port=None, key_file=None, cert_file=None,
strict=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT):
HTTPConnection.__init__(self, host, port, strict, timeout)
strict=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT,
source_address=None):
super(HTTPSConnection, self).__init__(host, port, strict, timeout,
source_address)
self.key_file = key_file
self.cert_file = cert_file
@ -1051,7 +1054,7 @@ else:
"Connect to a host on a given (SSL) port."
sock = socket.create_connection((self.host, self.port),
self.timeout)
self.timeout, self.source_address)
if self._tunnel_host:
self.sock = sock