From e73c7fe77e9aa269e32283112e21c0e264c494ab Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Wed, 19 Oct 2016 23:11:56 +1300 Subject: [PATCH] mitmproxy.protocol -> mitmproxy.proxy.protocol The protocols here are compltely proxy-specific, are only used from within the proxy module, and are not exposed to users. --- docs/scripting/events.rst | 2 +- examples/tls_passthrough.py | 2 +- mitmproxy/master.py | 2 +- mitmproxy/proxy/modes/http_proxy.py | 2 +- mitmproxy/proxy/modes/reverse_proxy.py | 2 +- mitmproxy/proxy/modes/socks_proxy.py | 2 +- mitmproxy/proxy/modes/transparent_proxy.py | 2 +- mitmproxy/{ => proxy}/protocol/__init__.py | 0 mitmproxy/{ => proxy}/protocol/base.py | 2 +- mitmproxy/{ => proxy}/protocol/http.py | 4 ++-- mitmproxy/{ => proxy}/protocol/http1.py | 2 +- mitmproxy/{ => proxy}/protocol/http2.py | 4 ++-- mitmproxy/{ => proxy}/protocol/http_replay.py | 2 +- mitmproxy/{ => proxy}/protocol/rawtcp.py | 2 +- mitmproxy/{ => proxy}/protocol/tls.py | 4 ++-- mitmproxy/{ => proxy}/protocol/websockets.py | 2 +- mitmproxy/proxy/root_context.py | 2 +- test/mitmproxy/addons/test_clientplayback.py | 2 +- test/mitmproxy/tutils.py | 10 +++++----- 19 files changed, 25 insertions(+), 25 deletions(-) rename mitmproxy/{ => proxy}/protocol/__init__.py (100%) rename mitmproxy/{ => proxy}/protocol/base.py (99%) rename mitmproxy/{ => proxy}/protocol/http.py (99%) rename mitmproxy/{ => proxy}/protocol/http1.py (97%) rename mitmproxy/{ => proxy}/protocol/http2.py (99%) rename mitmproxy/{ => proxy}/protocol/http_replay.py (98%) rename mitmproxy/{ => proxy}/protocol/rawtcp.py (98%) rename mitmproxy/{ => proxy}/protocol/tls.py (99%) rename mitmproxy/{ => proxy}/protocol/websockets.py (99%) diff --git a/docs/scripting/events.rst b/docs/scripting/events.rst index c16c01f62..622664853 100644 --- a/docs/scripting/events.rst +++ b/docs/scripting/events.rst @@ -56,7 +56,7 @@ Connection connection can correspond to multiple HTTP requests. *root_layer* - The root layer (see `mitmproxy.protocol` for an explanation what + The root layer (see `mitmproxy.proxy.protocol` for an explanation what the root layer is), provides transparent access to all attributes of the :py:class:`~mitmproxy.proxy.RootContext`. For example, ``root_layer.client_conn.address`` gives the remote address of the diff --git a/examples/tls_passthrough.py b/examples/tls_passthrough.py index 445ea5c31..40c1051d8 100644 --- a/examples/tls_passthrough.py +++ b/examples/tls_passthrough.py @@ -28,7 +28,7 @@ from enum import Enum import mitmproxy from mitmproxy.exceptions import TlsProtocolException -from mitmproxy.protocol import TlsLayer, RawTCPLayer +from mitmproxy.proxy.protocol import TlsLayer, RawTCPLayer class InterceptionResult(Enum): diff --git a/mitmproxy/master.py b/mitmproxy/master.py index 672ff1e8c..1fc001121 100644 --- a/mitmproxy/master.py +++ b/mitmproxy/master.py @@ -13,7 +13,7 @@ from mitmproxy import connections from mitmproxy import http from mitmproxy import log from mitmproxy import io -from mitmproxy.protocol import http_replay +from mitmproxy.proxy.protocol import http_replay from netlib import basethread import netlib.http diff --git a/mitmproxy/proxy/modes/http_proxy.py b/mitmproxy/proxy/modes/http_proxy.py index 37e7f04f8..d4fb9d687 100644 --- a/mitmproxy/proxy/modes/http_proxy.py +++ b/mitmproxy/proxy/modes/http_proxy.py @@ -1,4 +1,4 @@ -from mitmproxy import protocol +from mitmproxy.proxy import protocol class HttpProxy(protocol.Layer, protocol.ServerConnectionMixin): diff --git a/mitmproxy/proxy/modes/reverse_proxy.py b/mitmproxy/proxy/modes/reverse_proxy.py index 453b7d051..87d5d8c8e 100644 --- a/mitmproxy/proxy/modes/reverse_proxy.py +++ b/mitmproxy/proxy/modes/reverse_proxy.py @@ -1,4 +1,4 @@ -from mitmproxy import protocol +from mitmproxy.proxy import protocol class ReverseProxy(protocol.Layer, protocol.ServerConnectionMixin): diff --git a/mitmproxy/proxy/modes/socks_proxy.py b/mitmproxy/proxy/modes/socks_proxy.py index f6537b9e6..4f8473bde 100644 --- a/mitmproxy/proxy/modes/socks_proxy.py +++ b/mitmproxy/proxy/modes/socks_proxy.py @@ -1,6 +1,6 @@ import netlib.exceptions from mitmproxy import exceptions -from mitmproxy import protocol +from mitmproxy.proxy import protocol from netlib import socks diff --git a/mitmproxy/proxy/modes/transparent_proxy.py b/mitmproxy/proxy/modes/transparent_proxy.py index 2fb19b44a..ae532235a 100644 --- a/mitmproxy/proxy/modes/transparent_proxy.py +++ b/mitmproxy/proxy/modes/transparent_proxy.py @@ -1,6 +1,6 @@ from mitmproxy import exceptions from mitmproxy import platform -from mitmproxy import protocol +from mitmproxy.proxy import protocol class TransparentProxy(protocol.Layer, protocol.ServerConnectionMixin): diff --git a/mitmproxy/protocol/__init__.py b/mitmproxy/proxy/protocol/__init__.py similarity index 100% rename from mitmproxy/protocol/__init__.py rename to mitmproxy/proxy/protocol/__init__.py diff --git a/mitmproxy/protocol/base.py b/mitmproxy/proxy/protocol/base.py similarity index 99% rename from mitmproxy/protocol/base.py rename to mitmproxy/proxy/protocol/base.py index 53cfd1377..00d507219 100644 --- a/mitmproxy/protocol/base.py +++ b/mitmproxy/proxy/protocol/base.py @@ -22,7 +22,7 @@ class _LayerCodeCompletion: self.channel = None """@type: mitmproxy.controller.Channel""" self.ctx = None - """@type: mitmproxy.protocol.Layer""" + """@type: mitmproxy.proxy.protocol.Layer""" class Layer(_LayerCodeCompletion): diff --git a/mitmproxy/protocol/http.py b/mitmproxy/proxy/protocol/http.py similarity index 99% rename from mitmproxy/protocol/http.py rename to mitmproxy/proxy/protocol/http.py index 325bf815f..ec018f899 100644 --- a/mitmproxy/protocol/http.py +++ b/mitmproxy/proxy/protocol/http.py @@ -5,8 +5,8 @@ import traceback from mitmproxy import exceptions from mitmproxy import http from mitmproxy import flow -from mitmproxy.protocol import base -from mitmproxy.protocol import websockets as pwebsockets +from mitmproxy.proxy.protocol import base +from mitmproxy.proxy.protocol import websockets as pwebsockets import netlib.http from netlib import tcp from netlib import websockets diff --git a/mitmproxy/protocol/http1.py b/mitmproxy/proxy/protocol/http1.py similarity index 97% rename from mitmproxy/protocol/http1.py rename to mitmproxy/proxy/protocol/http1.py index c00848042..968d32498 100644 --- a/mitmproxy/protocol/http1.py +++ b/mitmproxy/proxy/protocol/http1.py @@ -1,5 +1,5 @@ from mitmproxy import http -from mitmproxy.protocol import http as httpbase +from mitmproxy.proxy.protocol import http as httpbase from netlib.http import http1 diff --git a/mitmproxy/protocol/http2.py b/mitmproxy/proxy/protocol/http2.py similarity index 99% rename from mitmproxy/protocol/http2.py rename to mitmproxy/proxy/protocol/http2.py index a3ec03f4e..cbd8b34ca 100644 --- a/mitmproxy/protocol/http2.py +++ b/mitmproxy/proxy/protocol/http2.py @@ -11,8 +11,8 @@ import queue import netlib.exceptions from mitmproxy import exceptions from mitmproxy import http -from mitmproxy.protocol import base -from mitmproxy.protocol import http as httpbase +from mitmproxy.proxy.protocol import base +from mitmproxy.proxy.protocol import http as httpbase import netlib.http from netlib import tcp from netlib import basethread diff --git a/mitmproxy/protocol/http_replay.py b/mitmproxy/proxy/protocol/http_replay.py similarity index 98% rename from mitmproxy/protocol/http_replay.py rename to mitmproxy/proxy/protocol/http_replay.py index 952c18176..bf0697be9 100644 --- a/mitmproxy/protocol/http_replay.py +++ b/mitmproxy/proxy/protocol/http_replay.py @@ -11,7 +11,7 @@ from netlib.http import http1 from netlib import basethread -# TODO: Doesn't really belong into mitmproxy.protocol... +# TODO: Doesn't really belong into mitmproxy.proxy.protocol... class RequestReplayThread(basethread.BaseThread): diff --git a/mitmproxy/protocol/rawtcp.py b/mitmproxy/proxy/protocol/rawtcp.py similarity index 98% rename from mitmproxy/protocol/rawtcp.py rename to mitmproxy/proxy/protocol/rawtcp.py index 3bd7b162e..513b90b36 100644 --- a/mitmproxy/protocol/rawtcp.py +++ b/mitmproxy/proxy/protocol/rawtcp.py @@ -6,7 +6,7 @@ import netlib.exceptions import netlib.tcp from mitmproxy import tcp from mitmproxy import flow -from mitmproxy.protocol import base +from mitmproxy.proxy.protocol import base class RawTCPLayer(base.Layer): diff --git a/mitmproxy/protocol/tls.py b/mitmproxy/proxy/protocol/tls.py similarity index 99% rename from mitmproxy/protocol/tls.py rename to mitmproxy/proxy/protocol/tls.py index b287bb51d..940ab9ea8 100644 --- a/mitmproxy/protocol/tls.py +++ b/mitmproxy/proxy/protocol/tls.py @@ -6,7 +6,7 @@ import construct import netlib.exceptions from mitmproxy import exceptions from mitmproxy.contrib.tls import _constructs -from mitmproxy.protocol import base +from mitmproxy.proxy.protocol import base from netlib import utils @@ -283,7 +283,7 @@ class TlsClientHello: client_conn: The :py:class:`client connection `. Returns: - :py:class:`client hello `. + :py:class:`client hello `. """ try: raw_client_hello = get_client_hello(client_conn)[4:] # exclude handshake header. diff --git a/mitmproxy/protocol/websockets.py b/mitmproxy/proxy/protocol/websockets.py similarity index 99% rename from mitmproxy/protocol/websockets.py rename to mitmproxy/proxy/protocol/websockets.py index 23b21d22a..816ec92d9 100644 --- a/mitmproxy/protocol/websockets.py +++ b/mitmproxy/proxy/protocol/websockets.py @@ -3,7 +3,7 @@ import socket import struct from OpenSSL import SSL from mitmproxy import exceptions -from mitmproxy.protocol import base +from mitmproxy.proxy.protocol import base from netlib import strutils from netlib import tcp from netlib import websockets diff --git a/mitmproxy/proxy/root_context.py b/mitmproxy/proxy/root_context.py index fa4fae478..6a99d9cf4 100644 --- a/mitmproxy/proxy/root_context.py +++ b/mitmproxy/proxy/root_context.py @@ -1,7 +1,7 @@ import netlib.exceptions from mitmproxy import log from mitmproxy import exceptions -from mitmproxy import protocol +from mitmproxy.proxy import protocol from mitmproxy.proxy import modes diff --git a/test/mitmproxy/addons/test_clientplayback.py b/test/mitmproxy/addons/test_clientplayback.py index c5407d187..f15b62904 100644 --- a/test/mitmproxy/addons/test_clientplayback.py +++ b/test/mitmproxy/addons/test_clientplayback.py @@ -14,7 +14,7 @@ class TestClientPlayback: f = tutils.tflow(resp=True) cp.load([f]) assert cp.count() == 1 - RP = "mitmproxy.protocol.http_replay.RequestReplayThread" + RP = "mitmproxy.proxy.protocol.http_replay.RequestReplayThread" with mock.patch(RP) as rp: assert not cp.current with mastertest.mockctx(): diff --git a/test/mitmproxy/tutils.py b/test/mitmproxy/tutils.py index 9724516b2..eb0c90e95 100644 --- a/test/mitmproxy/tutils.py +++ b/test/mitmproxy/tutils.py @@ -92,10 +92,10 @@ def tflow(client_conn=True, server_conn=True, req=True, resp=None, err=None): """ @type client_conn: bool | None | mitmproxy.proxy.connection.ClientConnection @type server_conn: bool | None | mitmproxy.proxy.connection.ServerConnection - @type req: bool | None | mitmproxy.protocol.http.HTTPRequest - @type resp: bool | None | mitmproxy.protocol.http.HTTPResponse - @type err: bool | None | mitmproxy.protocol.primitives.Error - @return: mitmproxy.protocol.http.HTTPFlow + @type req: bool | None | mitmproxy.proxy.protocol.http.HTTPRequest + @type resp: bool | None | mitmproxy.proxy.protocol.http.HTTPResponse + @type err: bool | None | mitmproxy.proxy.protocol.primitives.Error + @return: mitmproxy.proxy.protocol.http.HTTPFlow """ if client_conn is True: client_conn = tclient_conn() @@ -160,7 +160,7 @@ def tserver_conn(): def terr(content="error"): """ - @return: mitmproxy.protocol.primitives.Error + @return: mitmproxy.proxy.protocol.primitives.Error """ err = flow.Error(content) return err