summaryrefslogtreecommitdiff
path: root/dns/query.py
diff options
context:
space:
mode:
authorBrian Wellington <bwelling@xbill.org>2020-05-20 16:48:04 -0700
committerBrian Wellington <bwelling@xbill.org>2020-05-20 16:48:04 -0700
commit94dbee316f63702c5097e376a8b4fe7f9e5dd3bf (patch)
treee4c4791b09051f919b701a40d78728de9fd9312a /dns/query.py
parent7e7f8d76cd2dc4a23d12cb26551968a7ac67271a (diff)
downloaddnspython-94dbee316f63702c5097e376a8b4fe7f9e5dd3bf.tar.gz
Simplify dns.query._connect().
Diffstat (limited to 'dns/query.py')
-rw-r--r--dns/query.py19
1 files changed, 6 insertions, 13 deletions
diff --git a/dns/query.py b/dns/query.py
index de5c300..080a66d 100644
--- a/dns/query.py
+++ b/dns/query.py
@@ -590,21 +590,14 @@ def receive_tcp(sock, expiration=None, one_rr_per_rrset=False,
return (r, received_time)
def _connect(s, address, expiration):
- try:
- s.connect(address)
- except socket.error:
- (ty, v) = sys.exc_info()[:2]
-
- if hasattr(v, 'errno'):
- v_err = v.errno
- else:
- v_err = v[0]
- if v_err not in [errno.EINPROGRESS, errno.EWOULDBLOCK, errno.EALREADY]:
- raise v
+ err = s.connect_ex(address)
+ if err == 0:
+ return
+ if err in (errno.EINPROGRESS, errno.EWOULDBLOCK, errno.EALREADY):
_wait_for_writable(s, expiration)
err = s.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR)
- if err != 0:
- raise OSError(err, os.strerror(err)) from None
+ if err != 0:
+ raise OSError(err, os.strerror(err))
def tcp(q, where, timeout=None, port=53, af=None, source=None, source_port=0,