commit 59adcce1b1b9f3698b58baaa7e42a61c0b334c80 Author: Arturo Filastò art@fuffa.org Date: Mon Aug 18 14:09:21 2014 +0200
Fix some errors detected with pyflakes --- ooni/geoip.py | 2 +- ooni/nettest.py | 1 - ooni/nettests/manipulation/captiveportal.py | 5 +---- ooni/oonibclient.py | 3 --- ooni/oonicli.py | 2 +- ooni/otime.py | 1 - ooni/settings.py | 2 +- ooni/templates/httpt.py | 2 +- ooni/templates/tcpt.py | 1 - ooni/tests/mocks.py | 1 - ooni/utils/net.py | 3 +-- ooni/utils/trueheaders.py | 13 ++++--------- ooni/utils/txscapy.py | 7 ++----- 13 files changed, 12 insertions(+), 31 deletions(-)
diff --git a/ooni/geoip.py b/ooni/geoip.py index d135595..14dde4b 100644 --- a/ooni/geoip.py +++ b/ooni/geoip.py @@ -232,7 +232,7 @@ class ProbeIP(object): self.address = yield s.lookup() self.strategy = 'geo_ip_service-' + service_name break - except Exception, e: + except Exception: log.msg("Failed to lookup your IP via %s" % service_name)
if not self.address: diff --git a/ooni/nettest.py b/ooni/nettest.py index 0d5c0f2..3852b40 100644 --- a/ooni/nettest.py +++ b/ooni/nettest.py @@ -11,7 +11,6 @@ from twisted.python import usage, reflect from ooni.tasks import Measurement from ooni.utils import log, checkForRoot, sanitize_options from ooni.settings import config -from ooni import geoip
from ooni import errors as e
diff --git a/ooni/nettests/manipulation/captiveportal.py b/ooni/nettests/manipulation/captiveportal.py index eb28104..344ae1c 100644 --- a/ooni/nettests/manipulation/captiveportal.py +++ b/ooni/nettests/manipulation/captiveportal.py @@ -28,8 +28,6 @@ # :authors: Jacob Appelbaum, Arturo Filastò, Isis Lovecruft # :license: see LICENSE for more details
-import base64 -import os import random import re import string @@ -37,9 +35,8 @@ from urlparse import urlparse
from twisted.names import error from twisted.python import usage -from twisted.internet import defer, threads +from twisted.internet import defer
-from ooni import nettest from ooni.templates import httpt, dnst from ooni.utils import net from ooni.utils import log diff --git a/ooni/oonibclient.py b/ooni/oonibclient.py index 7dcc0af..9e08c74 100644 --- a/ooni/oonibclient.py +++ b/ooni/oonibclient.py @@ -1,8 +1,5 @@ -import os import json
-from hashlib import sha256 - from twisted.web.client import Agent from twisted.internet import defer, reactor from twisted.internet.endpoints import TCP4ClientEndpoint diff --git a/ooni/oonicli.py b/ooni/oonicli.py index eef3112..4df542f 100644 --- a/ooni/oonicli.py +++ b/ooni/oonicli.py @@ -4,7 +4,7 @@ import yaml
from twisted.python import usage from twisted.python.util import spewer -from twisted.internet import defer, reactor +from twisted.internet import defer
from ooni import errors, __version__
diff --git a/ooni/otime.py b/ooni/otime.py index 21dab42..51124db 100644 --- a/ooni/otime.py +++ b/ooni/otime.py @@ -1,4 +1,3 @@ -import time from datetime import datetime
def prettyDateNow(): diff --git a/ooni/settings.py b/ooni/settings.py index a5b6468..674b4d3 100644 --- a/ooni/settings.py +++ b/ooni/settings.py @@ -10,7 +10,7 @@ from os.path import abspath, expanduser from scapy.all import get_if_list
from ooni.utils.net import ConnectAndCloseProtocol -from ooni import otime, geoip +from ooni import geoip from ooni.utils import Storage, log from ooni import errors
diff --git a/ooni/templates/httpt.py b/ooni/templates/httpt.py index 18b0d81..e77913d 100644 --- a/ooni/templates/httpt.py +++ b/ooni/templates/httpt.py @@ -154,7 +154,7 @@ class HTTPTest(NetTestCase): response.body = response_body return response
- def _processResponseBodyFail(self, failure, request): + def _processResponseBodyFail(self, failure, request, response): failure_string = handleAllFailures(failure) HTTPTest.addToReport(self, request, response, failure_string=failure_string) diff --git a/ooni/templates/tcpt.py b/ooni/templates/tcpt.py index 17307fb..bdedebc 100644 --- a/ooni/templates/tcpt.py +++ b/ooni/templates/tcpt.py @@ -1,5 +1,4 @@ from twisted.internet import protocol, defer, reactor -from twisted.internet.error import ConnectionDone from twisted.internet.endpoints import TCP4ClientEndpoint
from ooni.nettest import NetTestCase diff --git a/ooni/tests/mocks.py b/ooni/tests/mocks.py index 72865b1..42f548e 100644 --- a/ooni/tests/mocks.py +++ b/ooni/tests/mocks.py @@ -2,7 +2,6 @@ from twisted.python import failure from twisted.internet import defer
from ooni.tasks import BaseTask, TaskWithTimeout -from ooni.nettest import NetTest from ooni.managers import TaskManager
diff --git a/ooni/utils/net.py b/ooni/utils/net.py index 51d55e5..58185ab 100644 --- a/ooni/utils/net.py +++ b/ooni/utils/net.py @@ -209,7 +209,7 @@ def checkInterfaces(ifaces=None, timeout=1): + " local address {}".format(ifname, ifaddr)) try: pkt = IP(dst=ifaddr) / ICMP() - ans, unans = sr(pkt, iface=ifname, timeout=5, retry=3) + ans, unans = sr1(pkt, iface=ifname, timeout=5, retry=3) except Exception, e: raise PermissionsError if e.find("Errno 1") else log.err(e) else: @@ -252,4 +252,3 @@ def getNonLoopbackIfaces(platform_name=None): def getLocalAddress(): default_iface = getDefaultIface() return default_iface.ipaddr - diff --git a/ooni/utils/trueheaders.py b/ooni/utils/trueheaders.py index a879687..e5dcd0a 100644 --- a/ooni/utils/trueheaders.py +++ b/ooni/utils/trueheaders.py @@ -4,18 +4,13 @@ # Here we make sure that the HTTP Headers sent and received are True. By this # we mean that they are not normalized and that the ordering is maintained.
-import struct import itertools from copy import copy
-from zope.interface import implements from twisted.web import client, _newclient, http_headers -from twisted.web._newclient import Request, RequestNotSent, RequestGenerationFailed, TransportProxyProducer, STATUS -from twisted.internet import protocol, reactor -from twisted.internet.protocol import ClientFactory, Protocol -from twisted.internet.endpoints import TCP4ClientEndpoint, SSL4ClientEndpoint -from twisted.internet import interfaces, defer -from twisted.internet.defer import Deferred, succeed, fail, maybeDeferred +from twisted.web._newclient import RequestNotSent, RequestGenerationFailed, TransportProxyProducer, STATUS +from twisted.internet import reactor +from twisted.internet.defer import Deferred, fail, maybeDeferred, failure
from txsocksx.http import SOCKS5Agent from txsocksx.client import SOCKS5ClientFactory @@ -137,7 +132,7 @@ class HTTP11ClientProtocol(_newclient.HTTP11ClientProtocol): self._state = 'GENERATION_FAILED' self.transport.loseConnection() self._finishedRequest.errback( - Failure(RequestGenerationFailed([err]))) + failure.Failure(RequestGenerationFailed([err]))) else: log.err(err, 'Error writing request, but not in valid state ' 'to finalize request: %s' % self._state) diff --git a/ooni/utils/txscapy.py b/ooni/utils/txscapy.py index 1701c93..ba90223 100644 --- a/ooni/utils/txscapy.py +++ b/ooni/utils/txscapy.py @@ -1,11 +1,10 @@ import socket -import os import sys import time import random
-from twisted.internet import protocol, base, fdesc -from twisted.internet import reactor, threads, error +from twisted.internet import fdesc +from twisted.internet import reactor from twisted.internet import defer, abstract
from scapy.config import conf @@ -256,7 +255,6 @@ class ScapySender(ScapyProtocol): self.stopSending()
def packetReceived(self, packet): - timeout = time.time() - self._start_time if self.timeout and time.time() - self._start_time > self.timeout: self.stopSending() if packet: @@ -491,7 +489,6 @@ class MPTraceroute(ScapyProtocol): for p in self._recvbuf: l = p.getlayer(2) if isinstance(l, IPerror): - pid = l.id l = p.getlayer(3) if isinstance(l, ICMPerror): addToReceivedPackets(('icmp', l.id), p)