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

[tor-commits] [ooni-probe/master] Make nettest take a filename instead of a file



commit ba54af4f7b6f02e074164aafa00f26454a16dfad
Author: Arturo Filastò <art@xxxxxxxxx>
Date:   Mon Nov 12 09:42:39 2012 +0100

    Make nettest take a filename instead of a file
    (cherry picked from commit 7ba9d50a5195aa8310c30445fd3e10ca02592e0b)
---
 ooni/nettest.py |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/ooni/nettest.py b/ooni/nettest.py
index 62b3657..8d911eb 100644
--- a/ooni/nettest.py
+++ b/ooni/nettest.py
@@ -109,7 +109,7 @@ class NetTestCase(object):
         """
         pass
 
-    def inputProcessor(self, fp):
+    def inputProcessor(self, filename):
         """
         You may replace this with your own custom input processor. It takes as
         input a file descriptor so remember to close it when you are done.
@@ -121,6 +121,7 @@ class NetTestCase(object):
         For example you may wish to have an input processor that will allow you
         to ignore comments in files. This can be easily achieved like so:
 
+            fp = open(filename)
             for x in fp.xreadlines():
                 if x.startswith("#"):
                     continue
@@ -130,6 +131,7 @@ class NetTestCase(object):
         Other fun stuff is also possible.
         """
         log.debug("Running default input processor")
+        fp = open(filename)
         for x in fp.xreadlines():
             yield x.strip()
         fp.close()
@@ -148,8 +150,7 @@ class NetTestCase(object):
                 log.err(ae)
             else:
                 if os.path.isfile(self.inputFile):
-                    fp = open(self.inputFile)
-                    self.inputs = self.inputProcessor(fp)
+                    self.inputs = self.inputProcessor(self.inputFile)
         elif not self.inputs[0]:
             pass
         elif self.inputFile:



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