[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [ooni-probe/master] Trap errors in importing dnspython



commit f63fc45985dae2f23ddf0453945b0f3d228bfbf3
Author: Arturo Filastò <hellais@xxxxxxxxx>
Date:   Tue Feb 7 20:46:39 2012 +0100

    Trap errors in importing dnspython
---
 refactor/tests/dnstamper.py  |   29 ++++++++++++++++-------------
 refactor/tests/traceroute.py |   31 +++++++++++++++++--------------
 2 files changed, 33 insertions(+), 27 deletions(-)

diff --git a/refactor/tests/dnstamper.py b/refactor/tests/dnstamper.py
index e68414d..987a948 100644
--- a/refactor/tests/dnstamper.py
+++ b/refactor/tests/dnstamper.py
@@ -1,4 +1,7 @@
-from dns import resolver
+try:
+    from dns import resolver
+except:
+    print "Error dnspython is not installed! (http://www.dnspython.org/)"
 import gevent
 import os
 import plugoo
@@ -13,27 +16,27 @@ class DNST(Plugoo):
         res = resolver.Resolver(configure=False)
         res.nameservers = [ns]
         answer = res.query(hostname)
-        
-        ret = []  
-        
+
+        ret = []
+
         for data in answer:
             ret.append(data.address)
-            
+
         return ret
-    
-    def experiment(self, *a, **kw):        
+
+    def experiment(self, *a, **kw):
         # this is just a dirty hack
         address = kw['data'][0]
         ns = kw['data'][1]
-        
+
         config = self.config
-        
+
         print "ADDRESS: %s" % address
         print "NAMESERVER: %s" % ns
-        
+
         exp = self.lookup(address, ns)
         control = self.lookup(address, config.tests.dns_control_server)
-        
+
         if len(set(exp) & set(control)) > 0:
             print "%s : no tampering on %s" % (address, ns)
             return (address, ns, False)
@@ -46,7 +49,7 @@ def run(ooni):
     """
     config = ooni.config
     urls = []
-    
+
     dns_experiment = DNSTAsset(os.path.join(config.main.assetdir, \
                                             config.tests.dns_experiment))
     dns_experiment_dns = DNSTAsset(os.path.join(config.main.assetdir, \
@@ -58,5 +61,5 @@ def run(ooni):
     ooni.logger.info("starting test")
     dnstest.run(assets)
     ooni.logger.info("finished")
-    
+
 
diff --git a/refactor/tests/traceroute.py b/refactor/tests/traceroute.py
index 13eb578..69f87e5 100644
--- a/refactor/tests/traceroute.py
+++ b/refactor/tests/traceroute.py
@@ -1,4 +1,7 @@
-from dns import resolver
+try:
+    from dns import resolver
+except:
+    print "Error dnspython is not installed (http://www.dnspython.org/)"
 import gevent
 import os
 import plugoo
@@ -40,52 +43,52 @@ class Traceroute(Plugoo):
                     send_sock.connect((dst, dst_port))
                 except socket.timeout:
                     pass
-                
+
                 except Exception, e:
                     print "Error doing connect %s" % e
             else:
                 send_sock.sendto("", (dst, dst_port))
-            
+
             curr_addr = None
             try:
                 print "receiving data..."
                 _, curr_addr = recv_sock.recvfrom(512)
                 curr_addr = curr_addr[0]
-            
+
             except socket.error, e:
                 print "SOCKET ERROR: %s" % e
-                
+
             except Exception, e:
                 print "ERROR: %s" % e
-                
+
             finally:
                 send_sock.close()
                 recv_sock.close()
-            
+
             if curr_addr is not None:
                 curr_host = "%s" % curr_addr
             else:
                 curr_host = "*"
-            
+
             print "%d\t%s" % (ttl, curr_host)
 
             if curr_addr == dest_addr or ttl > max_hops:
                 break
 
             ttl += 1
-    
-    
-    def experiment(self, *a, **kw):        
+
+
+    def experiment(self, *a, **kw):
         # this is just a dirty hack
         address = kw['data'][0]
-        
+
         self.traceroute(address)
 
 def run(ooni):
     """Run the test"""
     config = ooni.config
     urls = []
-    
+
     traceroute_experiment = TracerouteAsset(os.path.join(config.main.assetdir, \
                                             config.tests.traceroute))
 
@@ -95,5 +98,5 @@ def run(ooni):
     ooni.logger.info("starting traceroute test")
     traceroute.run(assets)
     ooni.logger.info("finished")
-    
+
 

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits