[PATCH] python indent bugfix in dns_hub.py

Tim Beale timbeale at catalyst.net.nz
Thu Jan 17 04:50:49 UTC 2019


Hi,

I rebased and pulled in this change, but I noticed dns_hub.py throwing
another exception during a CI run:
https://gitlab.com/catalyst-samba/samba/-/jobs/146917223

I think you also want the attached patch, which should stop it throwing
an exception in the exception handler. Kudos goes to Douglas for
actually figuring out the problem.

Cheers,
Tim

|---------------------------------------- Exception happened during
processing of request from ('127.0.0.39', 38556) Traceback (most recent
call last): File
"./bin/python/samba/tests/dns_forwarder_helpers/dns_hub.py", line 122,
in handle socket.sendto(send_packet, self.client_address) OSError:
[Errno 113] No route to host During handling of the above exception,
another exception occurred: Traceback (most recent call last): File
"/usr/lib/python3.4/socketserver.py", line 305, in
_handle_request_noblock self.process_request(request, client_address)
File "/usr/lib/python3.4/socketserver.py", line 331, in process_request
self.finish_request(request, client_address) File
"/usr/lib/python3.4/socketserver.py", line 344, in finish_request
self.RequestHandlerClass(request, client_address, self) File
"/usr/lib/python3.4/socketserver.py", line 673, in __init__
self.handle() 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' ----------------------------------------|

-------------- next part --------------
From 3357fb2e1be4f4485b8f8944d2ab7c238eae9c54 Mon Sep 17 00:00:00 2001
From: Tim Beale <timbeale at catalyst.net.nz>
Date: Thu, 17 Jan 2019 17:36:50 +1300
Subject: [PATCH] dns_hub: Rename variable to avoid naming collision in
 exception handler

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 at catalyst.net.nz>
---
 python/samba/tests/dns_forwarder_helpers/dns_hub.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/python/samba/tests/dns_forwarder_helpers/dns_hub.py b/python/samba/tests/dns_forwarder_helpers/dns_hub.py
index 12571f9..9cbd9023 100755
--- a/python/samba/tests/dns_forwarder_helpers/dns_hub.py
+++ b/python/samba/tests/dns_forwarder_helpers/dns_hub.py
@@ -91,7 +91,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)
@@ -121,7 +121,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))
-- 
2.7.4



More information about the samba-technical mailing list