commit 12cac3d21b8a3c8182e59958bc47219b40d926c3 Author: Arturo Filastò art@fuffa.org Date: Thu Sep 18 11:01:19 2014 +0200
Polyfill the connectProtocol to fix compatibility with Twisted 12.2 --- ooni/settings.py | 4 ++-- ooni/utils/net.py | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/ooni/settings.py b/ooni/settings.py index 130ce2e..61a9ca1 100644 --- a/ooni/settings.py +++ b/ooni/settings.py @@ -4,11 +4,11 @@ import yaml import getpass
from twisted.internet import defer, reactor -from twisted.internet.endpoints import TCP4ClientEndpoint, connectProtocol +from twisted.internet.endpoints import TCP4ClientEndpoint
from os.path import abspath, expanduser
-from ooni.utils.net import ConnectAndCloseProtocol +from ooni.utils.net import ConnectAndCloseProtocol, connectProtocol from ooni import geoip from ooni.utils import Storage, log from ooni import errors diff --git a/ooni/utils/net.py b/ooni/utils/net.py index 58185ab..ad19b49 100644 --- a/ooni/utils/net.py +++ b/ooni/utils/net.py @@ -6,6 +6,16 @@ from zope.interface import implements from twisted.internet import protocol, defer from twisted.web.iweb import IBodyProducer
+ +try: + from twisted.internet.endpoints import connectProtocol +except ImportError: + def connectProtocol(endpoint, protocol): + class OneShotFactory(protocol.Factory): + def buildProtocol(self, addr): + return protocol + return endpoint.connect(OneShotFactory()) + from ooni.utils import log
# if sys.platform.system() == 'Windows':