
All usage of e[0] replaced with either get_errno(e) or e.args[0] if intnetion was not to extract errno, but first argument
20 lines
572 B
Python
20 lines
572 B
Python
def get_errno(exc):
|
|
""" Get the error code out of socket.error objects.
|
|
socket.error in <2.5 does not have errno attribute
|
|
socket.error in 3.x does not allow indexing access
|
|
e.args[0] works for all.
|
|
There are cases when args[0] is not errno.
|
|
i.e. http://bugs.python.org/issue6471
|
|
Maybe there are cases when errno is set, but it is not the first argument?
|
|
"""
|
|
|
|
try:
|
|
if exc.errno is not None: return exc.errno
|
|
except AttributeError:
|
|
pass
|
|
try:
|
|
return exc.args[0]
|
|
except IndexError:
|
|
return None
|
|
|