diff options
author | Facundo Batista <facundobatista@gmail.com> | 2007-03-23 18:54:07 (GMT) |
---|---|---|
committer | Facundo Batista <facundobatista@gmail.com> | 2007-03-23 18:54:07 (GMT) |
commit | 07c78be0b4723deb62acebab50888cc59b1e4eb2 (patch) | |
tree | 0d1da08d12eafe4ac485889e1aac891e035c0696 /Lib/httplib.py | |
parent | f102e24bd34442026f4200a298a8b08d1deb3616 (diff) | |
download | cpython-07c78be0b4723deb62acebab50888cc59b1e4eb2.zip cpython-07c78be0b4723deb62acebab50888cc59b1e4eb2.tar.gz cpython-07c78be0b4723deb62acebab50888cc59b1e4eb2.tar.bz2 |
Added a 'create_connect()' function to socket.py, which creates a
connection with an optional timeout, and modified httplib.py to
use this function in HTTPConnection. Applies patch 1676823.
Diffstat (limited to 'Lib/httplib.py')
-rw-r--r-- | Lib/httplib.py | 23 |
1 files changed, 3 insertions, 20 deletions
diff --git a/Lib/httplib.py b/Lib/httplib.py index 213d80c..008f0a4 100644 --- a/Lib/httplib.py +++ b/Lib/httplib.py @@ -625,7 +625,8 @@ class HTTPConnection: debuglevel = 0 strict = 0 - def __init__(self, host, port=None, strict=None): + def __init__(self, host, port=None, strict=None, timeout=None): + self.timeout = timeout self.sock = None self._buffer = [] self.__response = None @@ -658,25 +659,7 @@ class HTTPConnection: def connect(self): """Connect to the host and port specified in __init__.""" - msg = "getaddrinfo returns an empty list" - for res in socket.getaddrinfo(self.host, self.port, 0, - socket.SOCK_STREAM): - af, socktype, proto, canonname, sa = res - try: - self.sock = socket.socket(af, socktype, proto) - if self.debuglevel > 0: - print "connect: (%s, %s)" % (self.host, self.port) - self.sock.connect(sa) - except socket.error, msg: - if self.debuglevel > 0: - print 'connect fail:', (self.host, self.port) - if self.sock: - self.sock.close() - self.sock = None - continue - break - if not self.sock: - raise socket.error, msg + self.sock = socket.create_connection((self.host,self.port), self.timeout) def close(self): """Close the connection to the HTTP server.""" |