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

[tor-commits] [ooni-probe/master] Minor refactor to move hacks into separate module



commit fbd9ecdbbe0c8463716c3f0d7a70648e068c3bc7
Author: Arturo Filastò <arturo@xxxxxxxxxxx>
Date:   Fri Sep 28 22:03:42 2012 +0000

    Minor refactor to move hacks into separate module
---
 bin/ooniprobe              |    3 +-
 nettests/example_scapyt.py |    2 +-
 ooni/utils/__init__.py     |   53 --------------------------------------------
 3 files changed, 3 insertions(+), 55 deletions(-)

diff --git a/bin/ooniprobe b/bin/ooniprobe
index f25be7a..62d60bb 100755
--- a/bin/ooniprobe
+++ b/bin/ooniprobe
@@ -9,9 +9,10 @@
 
 
 import os, sys
+import copy_reg
 
 # This is a hack to overcome a bug in python
-from ooni.utils import patched_reduce_ex
+from ooni.utils.hacks import patched_reduce_ex
 copy_reg._reduce_ex = patched_reduce_ex
 
 sys.path[:] = map(os.path.abspath, sys.path)
diff --git a/nettests/example_scapyt.py b/nettests/example_scapyt.py
index ef61f3d..4c31567 100644
--- a/nettests/example_scapyt.py
+++ b/nettests/example_scapyt.py
@@ -6,4 +6,4 @@
 from ooni.templates import scapyt
 from scapy.all import *
 class ExampleScapy(scapyt.ScapyTest):
-    inputs = [IP()/TCP()]
+    inputs = [IP(dst='8.8.8.8')/UDP(), IP()/TCP()]
diff --git a/ooni/utils/__init__.py b/ooni/utils/__init__.py
index 5593027..38239ba 100644
--- a/ooni/utils/__init__.py
+++ b/ooni/utils/__init__.py
@@ -143,56 +143,3 @@ class Log():
         except:
             raise StopIteration
 
-import copy_reg
-
-def patched_reduce_ex(self, proto):
-    """
-    This is a hack to overcome a bug in one of pythons core functions. It is
-    located inside of copy_reg and is called _reduce_ex.
-
-    Some background on the issue can be found here:
-    http://stackoverflow.com/questions/569754/how-to-tell-for-which-object-attribute-pickle-fails
-    http://stackoverflow.com/questions/2049849/why-cant-i-pickle-this-object
-
-    There was also an open bug on the pyyaml trac repo, but it got closed because
-    they could not reproduce.
-    http://pyyaml.org/ticket/190
-
-    It turned out to be easier to patch the python core library than to monkey
-    patch yaml.
-
-    XXX see if there is a better way. sigh...
-    """
-    _HEAPTYPE = 1<<9
-    assert proto < 2
-    for base in self.__class__.__mro__:
-        if hasattr(base, '__flags__') and not base.__flags__ & _HEAPTYPE:
-            break
-    else:
-        base = object # not really reachable
-    if base is object:
-        state = None
-    elif base is int:
-        state = None
-    else:
-        if base is self.__class__:
-            raise TypeError, "can't pickle %s objects" % base.__name__
-        state = base(self)
-    args = (self.__class__, base, state)
-    try:
-        getstate = self.__getstate__
-    except AttributeError:
-        if getattr(self, "__slots__", None):
-            raise TypeError("a class that defines __slots__ without "
-                            "defining __getstate__ cannot be pickled")
-        try:
-            dict = self.__dict__
-        except AttributeError:
-            dict = None
-    else:
-        dict = getstate()
-    if dict:
-        return copy_reg._reconstructor, args, dict
-    else:
-        return copy_reg._reconstructor, args
-



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