[tor-commits] [ooni-probe/master] Fix torify decorator

art at torproject.org art at torproject.org
Fri Feb 10 21:13:30 UTC 2012


commit 167756b4f3bc8453b61b761135c1a9aa9309b5a9
Author: Arturo Filastò <hellais at gmail.com>
Date:   Fri Feb 10 22:13:45 2012 +0100

    Fix torify decorator
---
 refactor/plugoo.py |   13 ++++++++-----
 1 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/refactor/plugoo.py b/refactor/plugoo.py
index 079a58f..20b418d 100644
--- a/refactor/plugoo.py
+++ b/refactor/plugoo.py
@@ -107,7 +107,7 @@ class Report:
         data to the reporting system
         """
         #print "Writing report(s)"
-        dump = '---\n'
+        dump = '--- \n'
         dump += yaml.dump(data)
         reports = []
 
@@ -315,16 +315,19 @@ class Plugoo():
                     job.kill()
                 jobs = []
 
-def torify(socksaddr):
+def torify(socksaddr, modules=None):
     """This is the torify decorator. It should be used to
     decorate functions that should use to for connecting to
     the interwebz. The suggary syntax is the following:
-    @torify("127.0.0.1:9050")
+    @torify("127.0.0.1:9050", [urllib2])
+    def myfunction():
+        f = urllib2.urlopen('https://torproject.org/')
     """
     def decorator(target):
         host, port = socksaddr.split(":")
         socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, host, int(port))
-        # Wrap the module into socks
-        socks.wrapmodule(target)
+        # Wrap the modules into socks
+        for module in modules:
+            socks.wrapmodule(module)
         return target
     return decorator



More information about the tor-commits mailing list