dns_hub: Rename variable to avoid naming collision in exception handler
authorTim Beale <timbeale@catalyst.net.nz>
Thu, 17 Jan 2019 04:36:50 +0000 (17:36 +1300)
committerAndreas Schneider <asn@cryptomilk.org>
Thu, 17 Jan 2019 14:23:23 +0000 (15:23 +0100)
In dns_hup.py, we are both importing the socket module and declaring a
variable called socket. When we try to catch a socket.error exception
(defined by the module), Python thinks we're referring to the variable.
As the variable has no attribute called 'error', Python throws an
exception, e.g.:

  File "./bin/python/samba/tests/dns_forwarder_helpers/dns_hub.py", line
123, in handle
    except socket.error as err:
AttributeError: 'socket' object has no attribute 'error'

We can avoid this problem by calling the variable 'sock' instead.

Signed-off-by: Tim Beale <timbeale@catalyst.net.nz>
Reviewed-by: Andreas Schneider <asn@samba.org>
Autobuild-User(master): Andreas Schneider <asn@cryptomilk.org>
Autobuild-Date(master): Thu Jan 17 15:23:23 CET 2019 on sn-devel-144

python/samba/tests/dns_forwarder_helpers/dns_hub.py

index cf9beb7fa7a2426290de09e960d1911a243d3db6..067f32d0bf6733bc1171cad524a77abcfc044d37 100755 (executable)
@@ -89,7 +89,7 @@ class DnsHandler(sserver.BaseRequestHandler):
         return None
 
     def handle(self):
-        data, socket = self.request
+        data, sock = self.request
         query = ndr.ndr_unpack(dns.name_packet, data);
         name = query.questions[0].name
         forwarder = self.forwarder(name)
@@ -119,7 +119,7 @@ class DnsHandler(sserver.BaseRequestHandler):
             (forwarder, self.client_address, name))
 
         try:
-            socket.sendto(send_packet, self.client_address)
+            sock.sendto(send_packet, self.client_address)
         except socket.error as err:
             print("Error sending %s to address %s for name %s: %s\n" %
                 (forwarder, self.client_address, name, err.errno))