commit 05dd861653a8db58f769cb6623ca369a834d3f13 Author: Isis Lovecruft isis@torproject.org Date: Wed Oct 3 11:24:24 2012 +0000
* Added Arturo's hacks.py back in, because it accidentally did not get added. * Fixed the environment setting in bin/ooniprobe wrapper. * WHY NO MORE ASCIIART?!?!?! WTF?!?! --- bin/ooniprobe | 2 +- ooni/utils/hacks.py | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletions(-)
diff --git a/bin/ooniprobe b/bin/ooniprobe index c653756..4e400ce 100755 --- a/bin/ooniprobe +++ b/bin/ooniprobe @@ -1,4 +1,4 @@ -#!/usr/bin/python2 +#!/usr/bin/env python # -*- encoding: utf-8 -*- # # startup script based on twisted trial diff --git a/ooni/utils/hacks.py b/ooni/utils/hacks.py new file mode 100644 index 0000000..5ef7c8b --- /dev/null +++ b/ooni/utils/hacks.py @@ -0,0 +1,53 @@ +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-attri... + 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@lists.torproject.org