From c2bb29f669cd80509f4efe205551a9cf5fc29770 Mon Sep 17 00:00:00 2001 From: Thomas Kriechbaumer Date: Wed, 27 Jan 2016 10:10:14 +0100 Subject: [PATCH] cleanup imports --- libmproxy/console/flowdetailview.py | 1 - libmproxy/console/flowlist.py | 1 - libmproxy/console/tabs.py | 1 - libmproxy/contrib/jsbeautifier/unpackers/__init__.py | 1 - libmproxy/contrib/jsbeautifier/unpackers/packer.py | 1 - libmproxy/dump.py | 3 --- libmproxy/flow.py | 1 - libmproxy/platform/osx.py | 2 +- libmproxy/protocol/__init__.py | 8 +++++--- libmproxy/protocol/base.py | 1 - libmproxy/protocol/rawtcp.py | 1 - libmproxy/protocol/tls.py | 3 ++- libmproxy/web/__init__.py | 1 - setup.cfg | 10 +++++----- test/test_app.py | 7 ------- test/test_console.py | 7 +------ test/test_custom_contentview.py | 1 - test/test_filt.py | 2 +- test/test_flow.py | 6 +++++- test/test_protocol_http.py | 1 - test/test_proxy.py | 1 - test/tools/passive_close.py | 1 - test/tservers.py | 2 -- 23 files changed, 20 insertions(+), 43 deletions(-) diff --git a/libmproxy/console/flowdetailview.py b/libmproxy/console/flowdetailview.py index 394ad217d..f4b4262e6 100644 --- a/libmproxy/console/flowdetailview.py +++ b/libmproxy/console/flowdetailview.py @@ -9,7 +9,6 @@ def maybe_timestamp(base, attr): return utils.format_timestamp_with_milli(getattr(base, attr)) else: return "active" - pass def flowdetails(state, flow): diff --git a/libmproxy/console/flowlist.py b/libmproxy/console/flowlist.py index 2c18d1973..a8df423fc 100644 --- a/libmproxy/console/flowlist.py +++ b/libmproxy/console/flowlist.py @@ -1,7 +1,6 @@ from __future__ import absolute_import import urwid -from netlib import http import netlib.utils from . import common, signals diff --git a/libmproxy/console/tabs.py b/libmproxy/console/tabs.py index fea9bbdee..6893494c2 100644 --- a/libmproxy/console/tabs.py +++ b/libmproxy/console/tabs.py @@ -1,5 +1,4 @@ import urwid -import signals class Tab(urwid.WidgetWrap): diff --git a/libmproxy/contrib/jsbeautifier/unpackers/__init__.py b/libmproxy/contrib/jsbeautifier/unpackers/__init__.py index 96318a5a8..fcb5b07a2 100644 --- a/libmproxy/contrib/jsbeautifier/unpackers/__init__.py +++ b/libmproxy/contrib/jsbeautifier/unpackers/__init__.py @@ -15,7 +15,6 @@ BLACKLIST = ['jsbeautifier.unpackers.evalbased'] class UnpackingError(Exception): """Badly packed source or general error. Argument is a meaningful description.""" - pass def getunpackers(): """Scans the unpackers dir, finds unpackers and add them to UNPACKERS list. diff --git a/libmproxy/contrib/jsbeautifier/unpackers/packer.py b/libmproxy/contrib/jsbeautifier/unpackers/packer.py index 37aa7123b..4ada669e1 100644 --- a/libmproxy/contrib/jsbeautifier/unpackers/packer.py +++ b/libmproxy/contrib/jsbeautifier/unpackers/packer.py @@ -13,7 +13,6 @@ """Unpacker for Dean Edward's p.a.c.k.e.r""" import re -import string from . import UnpackingError PRIORITY = 1 diff --git a/libmproxy/dump.py b/libmproxy/dump.py index c2a3268ae..435037c89 100644 --- a/libmproxy/dump.py +++ b/libmproxy/dump.py @@ -1,6 +1,4 @@ from __future__ import absolute_import, print_function -import sys -import os import traceback import click @@ -10,7 +8,6 @@ from netlib.http import CONTENT_MISSING import netlib.utils from . import flow, filt, contentviews from .exceptions import ContentViewException -from .models import HTTPRequest class DumpError(Exception): pass diff --git a/libmproxy/flow.py b/libmproxy/flow.py index 1f28166f5..4fe5d83e4 100644 --- a/libmproxy/flow.py +++ b/libmproxy/flow.py @@ -652,7 +652,6 @@ class FlowMaster(controller.Master): """ level: debug, info, error """ - pass def unload_scripts(self): for s in self.scripts[:]: diff --git a/libmproxy/platform/osx.py b/libmproxy/platform/osx.py index 2824718e0..afbc919b3 100644 --- a/libmproxy/platform/osx.py +++ b/libmproxy/platform/osx.py @@ -21,7 +21,7 @@ class Resolver(object): peer = csock.getpeername() try: stxt = subprocess.check_output(self.STATECMD, stderr=subprocess.STDOUT) - except subprocess.CalledProcessError, e: + except subprocess.CalledProcessError as e: if "sudo: a password is required" in e.output: insufficient_priv = True else: diff --git a/libmproxy/protocol/__init__.py b/libmproxy/protocol/__init__.py index d8ebd4f08..d46f16f5a 100644 --- a/libmproxy/protocol/__init__.py +++ b/libmproxy/protocol/__init__.py @@ -28,12 +28,14 @@ as late as possible; this makes server replay without any outgoing connections p from __future__ import (absolute_import, print_function, division) from .base import Layer, ServerConnectionMixin, Kill from .http import Http1Layer, UpstreamConnectLayer, Http2Layer -from .tls import TlsLayer, is_tls_record_magic, TlsClientHello +from .tls import TlsLayer +from .tls import is_tls_record_magic +from .tls import TlsClientHello from .rawtcp import RawTCPLayer __all__ = [ "Layer", "ServerConnectionMixin", "Kill", "Http1Layer", "UpstreamConnectLayer", "Http2Layer", - "TlsLayer", "is_tls_record_magic", "TlsClientHello" - "RawTCPLayer" + "TlsLayer", "is_tls_record_magic", "TlsClientHello", + "RawTCPLayer", ] diff --git a/libmproxy/protocol/base.py b/libmproxy/protocol/base.py index d984cadbc..c8433e079 100644 --- a/libmproxy/protocol/base.py +++ b/libmproxy/protocol/base.py @@ -3,7 +3,6 @@ import sys import six -from netlib import tcp from ..models import ServerConnection from ..exceptions import ProtocolException from netlib.exceptions import TcpException diff --git a/libmproxy/protocol/rawtcp.py b/libmproxy/protocol/rawtcp.py index ccd3c7eca..2902e03db 100644 --- a/libmproxy/protocol/rawtcp.py +++ b/libmproxy/protocol/rawtcp.py @@ -1,6 +1,5 @@ from __future__ import (absolute_import, print_function, division) import socket -import select import six import sys diff --git a/libmproxy/protocol/tls.py b/libmproxy/protocol/tls.py index 6d4cac850..847ba263f 100644 --- a/libmproxy/protocol/tls.py +++ b/libmproxy/protocol/tls.py @@ -5,7 +5,8 @@ import sys from construct import ConstructError import six -from netlib.exceptions import InvalidCertificateException, TcpException, TlsException +from netlib.exceptions import InvalidCertificateException +from netlib.exceptions import TlsException from ..contrib.tls._constructs import ClientHello from ..exceptions import ProtocolException, TlsProtocolException, ClientHandshakeException diff --git a/libmproxy/web/__init__.py b/libmproxy/web/__init__.py index 90da6ffed..c30a2a7eb 100644 --- a/libmproxy/web/__init__.py +++ b/libmproxy/web/__init__.py @@ -2,7 +2,6 @@ from __future__ import absolute_import, print_function import collections import tornado.ioloop import tornado.httpserver -import os from .. import controller, flow from . import app diff --git a/setup.cfg b/setup.cfg index 4cafebb78..1151288f1 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,11 +1,11 @@ [flake8] -max-line-length = 80 -max-complexity = 15 +max-line-length = 120 +max-complexity = 20 [pep8] -max-line-length = 80 +max-line-length = 120 exclude = */contrib/* -ignore = E251,E309 +ignore = E251 [pytest] -testpaths = test \ No newline at end of file +testpaths = test diff --git a/test/test_app.py b/test/test_app.py index 5fb495633..f412072a4 100644 --- a/test/test_app.py +++ b/test/test_app.py @@ -1,10 +1,3 @@ -import mock -import socket -import os -import time -from libmproxy import dump -from netlib import certutils, tcp -from libpathod.pathoc import Pathoc import tutils import tservers diff --git a/test/test_console.py b/test/test_console.py index 3304fdbb0..9d1f81135 100644 --- a/test/test_console.py +++ b/test/test_console.py @@ -1,9 +1,4 @@ -import os -import sys -import mock import gc -from os.path import normpath -import mock_urwid import netlib.tutils from libmproxy import console @@ -89,7 +84,7 @@ class TestConsoleState: f = self._add_request(c) c.add_flow_setting(f, "foo", "bar") assert c.get_flow_setting(f, "foo") == "bar" - assert c.get_flow_setting(f, "oink") == None + assert c.get_flow_setting(f, "oink") is None assert c.get_flow_setting(f, "oink", "foo") == "foo" assert len(c.flowsettings) == 1 c.delete_flow(f) diff --git a/test/test_custom_contentview.py b/test/test_custom_contentview.py index 4b5a3e53f..2538ab35a 100644 --- a/test/test_custom_contentview.py +++ b/test/test_custom_contentview.py @@ -1,4 +1,3 @@ -from libmproxy import script, flow import libmproxy.contentviews as cv from netlib.http import Headers diff --git a/test/test_filt.py b/test/test_filt.py index 104849bec..c9b8937e2 100644 --- a/test/test_filt.py +++ b/test/test_filt.py @@ -1,5 +1,5 @@ import cStringIO -from libmproxy import filt, flow +from libmproxy import filt from libmproxy.protocol import http from libmproxy.models import Error from netlib.http import Headers diff --git a/test/test_flow.py b/test/test_flow.py index d052a8e8b..388182f9f 100644 --- a/test/test_flow.py +++ b/test/test_flow.py @@ -10,7 +10,11 @@ import netlib.utils from netlib import odict from netlib.http import CONTENT_MISSING, Headers from libmproxy import filt, controller, tnetstring, flow -from libmproxy.models import Error, Flow, HTTPRequest, HTTPResponse, HTTPFlow, decoded +from libmproxy.models import Error +from libmproxy.models import Flow +from libmproxy.models import HTTPFlow +from libmproxy.models import HTTPRequest +from libmproxy.models import HTTPResponse from libmproxy.proxy.config import HostMatcher from libmproxy.proxy import ProxyConfig from libmproxy.proxy.server import DummyServer diff --git a/test/test_protocol_http.py b/test/test_protocol_http.py index 1f0386b4e..c7c5c1b6a 100644 --- a/test/test_protocol_http.py +++ b/test/test_protocol_http.py @@ -1,4 +1,3 @@ -import socket from io import BytesIO from netlib.exceptions import HttpSyntaxException from netlib.http import http1 diff --git a/test/test_proxy.py b/test/test_proxy.py index b498c800b..1759f07a0 100644 --- a/test/test_proxy.py +++ b/test/test_proxy.py @@ -10,7 +10,6 @@ from libmproxy.proxy.server import DummyServer, ProxyServer, ConnectionHandler from netlib.exceptions import TcpDisconnect import tutils from libpathod import test -from netlib import http, tcp from netlib.http import http1 diff --git a/test/tools/passive_close.py b/test/tools/passive_close.py index 7199ea70d..87d8846c5 100644 --- a/test/tools/passive_close.py +++ b/test/tools/passive_close.py @@ -1,5 +1,4 @@ import SocketServer -from threading import Thread from time import sleep diff --git a/test/tservers.py b/test/tservers.py index 5963667b5..c5b238549 100644 --- a/test/tservers.py +++ b/test/tservers.py @@ -1,6 +1,5 @@ import os.path import threading -import shutil import tempfile import flask import mock @@ -11,7 +10,6 @@ import libpathod.test import libpathod.pathoc from libmproxy import flow, controller from libmproxy.cmdline import APP_HOST, APP_PORT -import tutils testapp = flask.Flask(__name__)