From: Bob Halley Date: Sat, 28 May 2016 19:45:46 +0000 (-0700) Subject: Add socket_factory to allow socket creation to be overridden when needed. X-Git-Tag: v1.15.0~52 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4a7c1d8b3171d7cb68cce3e2c4510332726ee939;p=thirdparty%2Fdnspython.git Add socket_factory to allow socket creation to be overridden when needed. --- diff --git a/dns/query.py b/dns/query.py index 35670983..6b76b42e 100644 --- a/dns/query.py +++ b/dns/query.py @@ -37,6 +37,9 @@ if sys.version_info > (3,): else: select_error = select.error +# Function used to create a socket. Can be overridden if needed in special +# situations. +socket_factory = socket.socket class UnexpectedSource(dns.exception.DNSException): @@ -223,7 +226,7 @@ def udp(q, where, timeout=None, port=53, af=None, source=None, source_port=0, wire = q.to_wire() (af, destination, source) = _destination_and_source(af, where, port, source, source_port) - s = socket.socket(af, socket.SOCK_DGRAM, 0) + s = socket_factory(af, socket.SOCK_DGRAM, 0) begin_time = None try: expiration = _compute_expiration(timeout) @@ -331,7 +334,7 @@ def tcp(q, where, timeout=None, port=53, af=None, source=None, source_port=0, wire = q.to_wire() (af, destination, source) = _destination_and_source(af, where, port, source, source_port) - s = socket.socket(af, socket.SOCK_STREAM, 0) + s = socket_factory(af, socket.SOCK_STREAM, 0) begin_time = None try: expiration = _compute_expiration(timeout) @@ -435,9 +438,9 @@ def xfr(where, zone, rdtype=dns.rdatatype.AXFR, rdclass=dns.rdataclass.IN, if use_udp: if rdtype != dns.rdatatype.IXFR: raise ValueError('cannot do a UDP AXFR') - s = socket.socket(af, socket.SOCK_DGRAM, 0) + s = socket_factory(af, socket.SOCK_DGRAM, 0) else: - s = socket.socket(af, socket.SOCK_STREAM, 0) + s = socket_factory(af, socket.SOCK_STREAM, 0) s.setblocking(0) if source is not None: s.bind(source)