From 728d5caa22945d935bee24f39770b10763244cf6 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Sun, 12 Jun 2016 10:29:12 +1200 Subject: [PATCH] Fold mitmproxy.version and pathod.version into netlib.version --- docs/conf.py | 6 +++--- mitmproxy/cmdline.py | 2 +- mitmproxy/console/help.py | 3 ++- mitmproxy/flow/io_compat.py | 4 ++-- mitmproxy/flow/modules.py | 4 ++-- mitmproxy/models/flow.py | 3 ++- mitmproxy/models/http.py | 4 ++-- mitmproxy/version.py | 13 ------------- mitmproxy/web/app.py | 4 ++-- netlib/version.py | 4 ++-- pathod/pathoc_cmdline.py | 3 ++- pathod/pathod.py | 9 ++++++--- pathod/pathod_cmdline.py | 6 ++++-- pathod/protocols/http.py | 5 +++-- pathod/version.py | 13 ------------- setup.py | 2 +- 16 files changed, 34 insertions(+), 51 deletions(-) delete mode 100644 mitmproxy/version.py delete mode 100644 pathod/version.py diff --git a/docs/conf.py b/docs/conf.py index 3ef0c63d3..ae6574353 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -21,7 +21,7 @@ import shlex # documentation root, use os.path.abspath to make it absolute, like shown here. sys.path.insert(0, os.path.abspath('..')) -import mitmproxy.version +import netlib.version # -- General configuration ------------------------------------------------ @@ -69,9 +69,9 @@ author = u'The mitmproxy project' # built documents. # # The short X.Y version. -version = mitmproxy.version.VERSION +version = netlib.version.VERSION # The full version, including alpha/beta/rc tags. -release = mitmproxy.version.VERSION +release = netlib.version.VERSION # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/mitmproxy/cmdline.py b/mitmproxy/cmdline.py index 4727e263c..77cdb8caa 100644 --- a/mitmproxy/cmdline.py +++ b/mitmproxy/cmdline.py @@ -7,10 +7,10 @@ import re import configargparse from mitmproxy import filt -from mitmproxy import version from mitmproxy.proxy import config from netlib import human from netlib import tcp +from netlib import version from netlib.http import url APP_HOST = "mitm.it" diff --git a/mitmproxy/console/help.py b/mitmproxy/console/help.py index 26cb4ed39..064d3cb57 100644 --- a/mitmproxy/console/help.py +++ b/mitmproxy/console/help.py @@ -3,10 +3,11 @@ from __future__ import absolute_import, print_function, division import urwid from mitmproxy import filt -from mitmproxy import version from mitmproxy.console import common from mitmproxy.console import signals +from netlib import version + footer = [ ("heading", 'mitmproxy v%s ' % version.VERSION), ('heading_key', "q"), ":back ", diff --git a/mitmproxy/flow/io_compat.py b/mitmproxy/flow/io_compat.py index 7522163fa..1023e87f1 100644 --- a/mitmproxy/flow/io_compat.py +++ b/mitmproxy/flow/io_compat.py @@ -3,7 +3,7 @@ This module handles the import of mitmproxy flows generated by old versions. """ from __future__ import absolute_import, print_function, division -from mitmproxy import version +from netlib import version def convert_013_014(data): @@ -66,6 +66,6 @@ def migrate_flow(flow_data): else: v = ".".join(str(i) for i in flow_data["version"]) raise ValueError( - "{} cannot read files serialized with version {}.".format(version.NAMEVERSION, v) + "{} cannot read files serialized with version {}.".format(version.MITMPROXY, v) ) return flow_data diff --git a/mitmproxy/flow/modules.py b/mitmproxy/flow/modules.py index 601ebfceb..2998d259f 100644 --- a/mitmproxy/flow/modules.py +++ b/mitmproxy/flow/modules.py @@ -9,8 +9,8 @@ from six.moves import urllib from mitmproxy import controller from mitmproxy import filt -from mitmproxy import version from netlib import wsgi +from netlib import version from netlib.http import cookies from netlib.http import http1 @@ -28,7 +28,7 @@ class AppRegistry: app, domain, port, - version.NAMEVERSION + version.MITMPROXY ) def get(self, request): diff --git a/mitmproxy/models/flow.py b/mitmproxy/models/flow.py index de86e4519..0e4f80cb4 100644 --- a/mitmproxy/models/flow.py +++ b/mitmproxy/models/flow.py @@ -5,10 +5,11 @@ import copy import uuid from mitmproxy import stateobject -from mitmproxy import version from mitmproxy.models.connections import ClientConnection from mitmproxy.models.connections import ServerConnection +from netlib import version + class Error(stateobject.StateObject): diff --git a/mitmproxy/models/http.py b/mitmproxy/models/http.py index a32124acc..01f5f1ee1 100644 --- a/mitmproxy/models/http.py +++ b/mitmproxy/models/http.py @@ -2,9 +2,9 @@ from __future__ import absolute_import, print_function, division import cgi -from mitmproxy import version from mitmproxy.models.flow import Flow from netlib import encoding +from netlib import version from netlib.http import Headers from netlib.http import Request from netlib.http import Response @@ -258,7 +258,7 @@ def make_error_response(status_code, message, headers=None): if not headers: headers = Headers( - Server=version.NAMEVERSION, + Server=version.MITMPROXY, Connection="close", Content_Length=str(len(body)), Content_Type="text/html" diff --git a/mitmproxy/version.py b/mitmproxy/version.py deleted file mode 100644 index 0ebb08291..000000000 --- a/mitmproxy/version.py +++ /dev/null @@ -1,13 +0,0 @@ -from __future__ import absolute_import, print_function, division - -from netlib.version import VERSION, IVERSION - -NAME = "mitmproxy" -NAMEVERSION = NAME + " " + VERSION - -__all__ = [ - "NAME", - "NAMEVERSION", - "VERSION", - "IVERSION", -] diff --git a/mitmproxy/web/app.py b/mitmproxy/web/app.py index 2ba97b8d8..27415619d 100644 --- a/mitmproxy/web/app.py +++ b/mitmproxy/web/app.py @@ -12,7 +12,7 @@ from io import BytesIO from mitmproxy.flow import FlowWriter, FlowReader from mitmproxy import filt -from mitmproxy import version +from netlib import version def _strip_content(flow_state): @@ -72,7 +72,7 @@ class RequestHandler(BasicAuth, tornado.web.RequestHandler): def set_default_headers(self): super(RequestHandler, self).set_default_headers() - self.set_header("Server", version.NAMEVERSION) + self.set_header("Server", version.MITMPROXY) self.set_header("X-Frame-Options", "DENY") self.add_header("X-XSS-Protection", "1; mode=block") self.add_header("X-Content-Type-Options", "nosniff") diff --git a/netlib/version.py b/netlib/version.py index 94ea43ba8..a048c17f4 100644 --- a/netlib/version.py +++ b/netlib/version.py @@ -2,5 +2,5 @@ from __future__ import (absolute_import, print_function, division) IVERSION = (0, 18) VERSION = ".".join(str(i) for i in IVERSION) -NAME = "netlib" -NAMEVERSION = NAME + " " + VERSION +PATHOD = "pathod " + VERSION +MITMPROXY = "mitmproxy " + VERSION diff --git a/pathod/pathoc_cmdline.py b/pathod/pathoc_cmdline.py index 1f438cd77..21d0efc62 100644 --- a/pathod/pathoc_cmdline.py +++ b/pathod/pathoc_cmdline.py @@ -5,8 +5,9 @@ import os import os.path from netlib import tcp +from netlib import version from netlib.http import user_agents -from . import pathoc, version, language +from . import pathoc, language def args_pathoc(argv, stdout=sys.stdout, stderr=sys.stderr): diff --git a/pathod/pathod.py b/pathod/pathod.py index d1cc9980a..315a04e0c 100644 --- a/pathod/pathod.py +++ b/pathod/pathod.py @@ -6,11 +6,14 @@ import sys import threading import urllib -from netlib import tcp, certutils, websockets +from netlib import tcp +from netlib import certutils +from netlib import websockets +from netlib import version from netlib.exceptions import HttpException, HttpReadDisconnect, TcpTimeout, TcpDisconnect, \ TlsException -from . import version, language, utils, log, protocols +from . import language, utils, log, protocols DEFAULT_CERT_DOMAIN = "pathod.net" @@ -486,7 +489,7 @@ def main(args): # pragma: no cover try: print("%s listening on %s" % ( - version.NAMEVERSION, + version.PATHOD, repr(pd.address) )) pd.serve_forever() diff --git a/pathod/pathod_cmdline.py b/pathod/pathod_cmdline.py index 5bb0cdd37..3531b8f3e 100644 --- a/pathod/pathod_cmdline.py +++ b/pathod/pathod_cmdline.py @@ -4,8 +4,10 @@ import os import os.path import re -from netlib import tcp, human -from . import pathod, version +from netlib import tcp +from netlib import human +from netlib import version +from . import pathod def parse_anchor_spec(s): diff --git a/pathod/protocols/http.py b/pathod/protocols/http.py index 6eefb34fe..7736df4b5 100644 --- a/pathod/protocols/http.py +++ b/pathod/protocols/http.py @@ -1,6 +1,7 @@ +from netlib import version from netlib.exceptions import TlsException from netlib.http import http1 -from .. import version, language +from .. import language class HTTPProtocol(object): @@ -17,7 +18,7 @@ class HTTPProtocol(object): self.pathod_handler.wfile.write( 'HTTP/1.1 200 Connection established\r\n' + - ('Proxy-agent: %s\r\n' % version.NAMEVERSION) + + ('Proxy-agent: %s\r\n' % version.PATHOD) + '\r\n' ) self.pathod_handler.wfile.flush() diff --git a/pathod/version.py b/pathod/version.py deleted file mode 100644 index 3441be929..000000000 --- a/pathod/version.py +++ /dev/null @@ -1,13 +0,0 @@ -from __future__ import (absolute_import, print_function, division) - -from netlib.version import VERSION, IVERSION - -NAME = "pathod" -NAMEVERSION = NAME + " " + VERSION - -__all__ = [ - "NAME", - "NAMEVERSION", - "VERSION", - "IVERSION", -] diff --git a/setup.py b/setup.py index cd1230448..a430d31a6 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ import os here = os.path.abspath(os.path.dirname(__file__)) -from mitmproxy import version +from netlib import version with open(os.path.join(here, 'README.rst'), encoding='utf-8') as f: long_description = f.read()