[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [ooni-probe/master] Make HTTPConnectionPool be a softer dependency
commit d613f21c78a75d0a4dea3639cd0eb0d8a57f49f8
Author: Arturo Filastò <art@xxxxxxxxx>
Date: Sat Nov 24 11:34:23 2012 +0100
Make HTTPConnectionPool be a softer dependency
* Print out messages warning the user that the current version of twisted is
outdated.
* Update requirements.txt to require Twisted > 12.1.0
Thanks to mct for reporting the bug
---
ooni/reporter.py | 2 +-
ooni/utils/txagentwithsocks.py | 21 ++++++++++++++++++---
requirements.txt | 2 +-
3 files changed, 20 insertions(+), 5 deletions(-)
diff --git a/ooni/reporter.py b/ooni/reporter.py
index 8c76dc4..7fc49e2 100644
--- a/ooni/reporter.py
+++ b/ooni/reporter.py
@@ -20,7 +20,7 @@ from twisted.trial import reporter
from twisted.internet import defer, reactor
from twisted.internet.error import ConnectionRefusedError
-from ooni.templates.httpt import BodyReceiver, StringProducer
+from ooni.utils.net import BodyReceiver, StringProducer, userAgents
from ooni.utils import otime, log, geodata
from ooni.utils.hacks import OSafeRepresenter, OSafeDumper
diff --git a/ooni/utils/txagentwithsocks.py b/ooni/utils/txagentwithsocks.py
index 05da54f..57c27e4 100644
--- a/ooni/utils/txagentwithsocks.py
+++ b/ooni/utils/txagentwithsocks.py
@@ -14,6 +14,8 @@ from twisted.internet.endpoints import TCP4ClientEndpoint, SSL4ClientEndpoint, _
from twisted.internet import interfaces, defer
from twisted.internet.defer import Deferred, succeed, fail, maybeDeferred
+from ooni.utils import log
+
class SOCKSError(Exception):
def __init__(self, value):
Exception.__init__(self)
@@ -198,15 +200,22 @@ class _HTTP11ClientFactory(client._HTTP11ClientFactory):
def buildProtocol(self, addr):
return HTTP11ClientProtocol(self._quiescentCallback)
-class HTTPConnectionPool(client.HTTPConnectionPool):
- _factory = _HTTP11ClientFactory
+try:
+ class HTTPConnectionPool(client.HTTPConnectionPool):
+ _factory = _HTTP11ClientFactory
+except AttributeError:
+ log.err("Your version of Twisted is outdated and we will not support HTTPConnectionPool")
+ HTTPConnectionPool = None
+
+class UnsupportedTwistedVersion(Exception):
+ pass
class Agent(client.Agent):
def __init__(self, reactor,
contextFactory=client.WebClientContextFactory(),
connectTimeout=None, bindAddress=None,
pool=None, sockshost=None, socksport=None):
- if pool is None:
+ if pool is None and HTTPConnectionPool:
pool = HTTPConnectionPool(reactor, False)
self._reactor = reactor
self._pool = pool
@@ -216,6 +225,12 @@ class Agent(client.Agent):
self._sockshost = sockshost
self._socksport = socksport
+ def request(self, method, uri, headers=None, bodyProducer=None):
+ if uri.startswith('shttp') or uri.startswith('httpo'):
+ log.err("Requests over SOCKS are supported only with versions of Twisted >= 12.1.0")
+ raise UnsupportedTwistedVersion
+ return client.Agent.request(self, method, uri, headers, bodyProducer)
+
def _getEndpoint(self, scheme, host, port):
kwargs = {}
if self._connectTimeout is not None:
diff --git a/requirements.txt b/requirements.txt
index 0848cca..4ddb915 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -2,7 +2,7 @@ Jinja2>=2.6
PyYAML>=3.10
Pygments>=1.5
Sphinx>=1.1.3
-Twisted>=12.0.0
+Twisted>=12.1.0
argparse>=1.2.1
distribute>=0.6.24
dnspython>=1.10.0
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits