Skip to content

Commit

Permalink
!fixup doc
Browse files Browse the repository at this point in the history
  • Loading branch information
temoto committed Oct 3, 2021
1 parent 832d456 commit a8429bd
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions python3/httplib2/__init__.py
Expand Up @@ -183,6 +183,20 @@ def _get_end2end_headers(response):
return [header for header in list(response.keys()) if header not in hopbyhop]


def _errno_from_exception(e):
# socket.error and common wrap in .args
if len(e.args) > 0:
return e.args[0].errno if isinstance(e.args[0], socket.error) else e.errno

# pysocks.ProxyError wraps in .socket_err
# https://github.com/httplib2/httplib2/pull/202
if hasattr(e, "socket_err"):
e_int = e.socket_err
return e_int.args[0].errno if isinstance(e_int.args[0], socket.error) else e_int.errno

return None


URI = re.compile(r"^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?")


Expand Down Expand Up @@ -1355,7 +1369,7 @@ def _conn_request(self, conn, request_uri, method, body, headers):
conn.close()
raise ServerNotFoundError("Unable to find the server at %s" % conn.host)
except socket.error as e:
errno_ = self._errno_from_exception(e)
errno_ = _errno_from_exception(e)
if errno_ in (errno.ENETUNREACH, errno.EADDRNOTAVAIL) and i < RETRIES:
continue # retry on potentially transient errors
raise
Expand Down Expand Up @@ -1413,17 +1427,6 @@ def _conn_request(self, conn, request_uri, method, body, headers):
break
return (response, content)

@staticmethod
def _errno_from_exception(e):
if len(e.args) > 0:
return e.args[0].errno if isinstance(e.args[0], socket.error) else e.errno

if hasattr(e, 'socket_err'):
e_int = e.socket_err
return e_int.args[0].errno if isinstance(e_int.args[0], socket.error) else e_int.errno

return None

def _request(
self, conn, host, absolute_uri, request_uri, method, body, headers, redirections, cachekey,
):
Expand Down

0 comments on commit a8429bd

Please sign in to comment.