summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOmer Katz <omer.drow@gmail.com>2020-08-30 18:28:12 +0300
committerAsif Saif Uddin <auvipy@gmail.com>2020-08-31 14:05:09 +0600
commitd6b758ca49bad3f09f449f570c65758fc07c0ac2 (patch)
tree50d114d9b0ff6c788e20a606e5057d1a17b0552b
parent98267b667e86aa606daf3f2c514869a5d3a4165c (diff)
downloadpy-amqp-d6b758ca49bad3f09f449f570c65758fc07c0ac2.tar.gz
Remove get_errno() since it is no longer needed.
-rw-r--r--amqp/transport.py10
-rw-r--r--amqp/utils.py19
-rw-r--r--t/unit/test_utils.py22
3 files changed, 6 insertions, 45 deletions
diff --git a/amqp/transport.py b/amqp/transport.py
index 1c7d49e..c7d82fc 100644
--- a/amqp/transport.py
+++ b/amqp/transport.py
@@ -12,7 +12,7 @@ from struct import pack, unpack
from .exceptions import UnexpectedFrame
from .platform import KNOWN_TCP_OPTS, SOL_TCP
-from .utils import get_errno, set_cloexec
+from .utils import set_cloexec
_UNAVAIL = {errno.EAGAIN, errno.EINTR, errno.ENOENT, errno.EWOULDBLOCK}
@@ -108,7 +108,7 @@ class _AbstractTransport(object):
raise socket.timeout()
raise
except socket.error as exc:
- if get_errno(exc) == errno.EWOULDBLOCK:
+ if exc.errno == errno.EWOULDBLOCK:
raise socket.timeout()
raise
finally:
@@ -275,7 +275,7 @@ class _AbstractTransport(object):
except (OSError, IOError, SSLError, socket.error) as exc:
if (
isinstance(exc, socket.error) and os.name == 'nt'
- and get_errno(exc) == errno.EWOULDBLOCK # noqa
+ and exc.errno == errno.EWOULDBLOCK # noqa
):
# On windows we can get a read timeout with a winsock error
# code instead of a proper socket.timeout() error, see
@@ -289,7 +289,7 @@ class _AbstractTransport(object):
self._read_buffer = read_frame_buffer + self._read_buffer
raise socket.timeout()
- if get_errno(exc) not in _UNAVAIL:
+ if exc.errno not in _UNAVAIL:
self.connected = False
raise
if ch == 206: # '\xce'
@@ -304,7 +304,7 @@ class _AbstractTransport(object):
except socket.timeout:
raise
except (OSError, IOError, socket.error) as exc:
- if get_errno(exc) not in _UNAVAIL:
+ if exc.errno not in _UNAVAIL:
self.connected = False
raise
diff --git a/amqp/utils.py b/amqp/utils.py
index 9f58897..8ba5f67 100644
--- a/amqp/utils.py
+++ b/amqp/utils.py
@@ -30,25 +30,6 @@ def set_cloexec(fd, cloexec):
return fcntl.fcntl(fd, fcntl.F_SETFD, flags)
-def get_errno(exc):
- """Get exception errno (if set).
-
- Notes:
- :exc:`socket.error` and :exc:`IOError` first got
- the ``.errno`` attribute in Py2.7.
- """
- try:
- return exc.errno
- except AttributeError:
- try:
- # e.args = (errno, reason)
- if isinstance(exc.args, tuple) and len(exc.args) == 2:
- return exc.args[0]
- except AttributeError:
- pass
- return 0
-
-
def coro(gen):
"""Decorator to mark generator as a co-routine."""
@wraps(gen)
diff --git a/t/unit/test_utils.py b/t/unit/test_utils.py
index 8c54645..45eb283 100644
--- a/t/unit/test_utils.py
+++ b/t/unit/test_utils.py
@@ -1,26 +1,6 @@
from case import Mock, patch
-from amqp.utils import bytes_to_str, coro, get_errno, get_logger, str_to_bytes
-
-
-class test_get_errno:
-
- def test_has_attr(self):
- exc = KeyError('foo')
- exc.errno = 23
- assert get_errno(exc) == 23
-
- def test_in_args(self):
- exc = KeyError(34, 'foo')
- exc.args = (34, 'foo')
- assert get_errno(exc) == 34
-
- def test_args_short(self):
- exc = KeyError(34)
- assert not get_errno(exc)
-
- def test_no_args(self):
- assert not get_errno(object())
+from amqp.utils import bytes_to_str, coro, get_logger, str_to_bytes
class test_coro: