strip out buggy retry code

it assumed there'd be at least one retry, and was trying to return
response that was initialized
This commit is contained in:
Damien Elmes 2013-11-08 01:14:49 +09:00
parent be81d282ac
commit 3dbc6fa0dd

View file

@ -449,70 +449,53 @@ httplib.HTTPConnection.send = _incrementalSend
# receiving in httplib2 # receiving in httplib2
def _conn_request(self, conn, request_uri, method, body, headers): def _conn_request(self, conn, request_uri, method, body, headers):
for i in range(httplib2.RETRIES): try:
try: if conn.sock is None:
if conn.sock is None: conn.connect()
conn.connect() conn.request(method, request_uri, body, headers)
conn.request(method, request_uri, body, headers) except socket.timeout:
except socket.timeout: raise
raise except socket.gaierror:
except socket.gaierror: conn.close()
conn.close() raise httplib2.ServerNotFoundError(
raise httplib2.ServerNotFoundError( "Unable to find the server at %s" % conn.host)
"Unable to find the server at %s" % conn.host) except httplib2.ssl_SSLError:
except httplib2.ssl_SSLError: conn.close()
conn.close() raise
raise except socket.error, e:
except socket.error, e: err = 0
err = 0 if hasattr(e, 'args'):
if hasattr(e, 'args'): err = getattr(e, 'args')[0]
err = getattr(e, 'args')[0]
else:
err = e.errno
if err == errno.ECONNREFUSED: # Connection refused
raise
except httplib.HTTPException:
# Just because the server closed the connection doesn't apparently mean
# that the server didn't send a response.
if conn.sock is None:
if i == 0:
conn.close()
conn.connect()
continue
else:
conn.close()
raise
if i == 0:
conn.close()
conn.connect()
continue
pass
try:
response = conn.getresponse()
except (socket.error, httplib.HTTPException):
if i == 0:
conn.close()
conn.connect()
continue
else:
raise
else: else:
content = "" err = e.errno
if method == "HEAD": if err == errno.ECONNREFUSED: # Connection refused
response.close() raise
else: except httplib.HTTPException:
buf = StringIO() # Just because the server closed the connection doesn't apparently mean
while 1: # that the server didn't send a response.
data = response.read(CHUNK_SIZE) if conn.sock is None:
if not data: conn.close()
break raise
buf.write(data) try:
runHook("httpRecv", len(data)) response = conn.getresponse()
content = buf.getvalue() except (socket.error, httplib.HTTPException):
response = httplib2.Response(response) raise
if method != "HEAD": else:
content = httplib2._decompressContent(response, content) content = ""
break if method == "HEAD":
response.close()
else:
buf = StringIO()
while 1:
data = response.read(CHUNK_SIZE)
if not data:
break
buf.write(data)
runHook("httpRecv", len(data))
content = buf.getvalue()
response = httplib2.Response(response)
if method != "HEAD":
content = httplib2._decompressContent(response, content)
return (response, content) return (response, content)
httplib2.Http._conn_request = _conn_request httplib2.Http._conn_request = _conn_request