diff options
-rw-r--r-- | mitmproxy/flow.py | 7 | ||||
-rw-r--r-- | mitmproxy/models/connections.py | 12 | ||||
-rw-r--r-- | mitmproxy/models/flow.py | 3 | ||||
-rw-r--r-- | mitmproxy/models/http.py | 36 | ||||
-rw-r--r-- | mitmproxy/protocol/http.py | 5 | ||||
-rw-r--r-- | mitmproxy/proxy/config.py | 7 |
6 files changed, 44 insertions, 26 deletions
diff --git a/mitmproxy/flow.py b/mitmproxy/flow.py index 8e239a44..d656bc4d 100644 --- a/mitmproxy/flow.py +++ b/mitmproxy/flow.py @@ -6,6 +6,8 @@ from __future__ import absolute_import import traceback from abc import abstractmethod, ABCMeta import hashlib + +import six from six.moves import http_cookies, http_cookiejar import os import re @@ -384,9 +386,12 @@ class FlowList(object): def __getitem__(self, item): return self._list[item] - def __nonzero__(self): + def __bool__(self): return bool(self._list) + if six.PY2: + __nonzero__ = __bool__ + def __len__(self): return len(self._list) diff --git a/mitmproxy/models/connections.py b/mitmproxy/models/connections.py index 2ffc667d..14545842 100644 --- a/mitmproxy/models/connections.py +++ b/mitmproxy/models/connections.py @@ -3,6 +3,8 @@ from __future__ import (absolute_import, print_function, division) import copy import os +import six + from netlib import tcp, certutils from .. import stateobject, utils @@ -27,9 +29,12 @@ class ClientConnection(tcp.BaseHandler, stateobject.StateObject): self.timestamp_ssl_setup = None self.protocol = None - def __nonzero__(self): + def __bool__(self): return bool(self.connection) and not self.finished + if six.PY2: + __nonzero__ = __bool__ + def __repr__(self): return "<ClientConnection: {ssl}{address}>".format( ssl="[ssl] " if self.ssl_established else "", @@ -95,9 +100,12 @@ class ServerConnection(tcp.TCPClient, stateobject.StateObject): self.timestamp_ssl_setup = None self.protocol = None - def __nonzero__(self): + def __bool__(self): return bool(self.connection) and not self.finished + if six.PY2: + __nonzero__ = __bool__ + def __repr__(self): if self.ssl_established and self.sni: ssl = "[ssl: {0}] ".format(self.sni) diff --git a/mitmproxy/models/flow.py b/mitmproxy/models/flow.py index 10255dad..95fb2b69 100644 --- a/mitmproxy/models/flow.py +++ b/mitmproxy/models/flow.py @@ -99,9 +99,6 @@ class Flow(stateobject.StateObject): self._backup = state.pop("backup") super(Flow, self).set_state(state) - def __eq__(self, other): - return self is other - def copy(self): f = copy.copy(self) diff --git a/mitmproxy/models/http.py b/mitmproxy/models/http.py index 21096a39..5b1c8daf 100644 --- a/mitmproxy/models/http.py +++ b/mitmproxy/models/http.py @@ -164,17 +164,17 @@ class HTTPRequest(MessageMixin, Request): @classmethod def wrap(self, request): req = HTTPRequest( - first_line_format=request.form_in, - method=request.method, - scheme=request.scheme, - host=request.host, - port=request.port, - path=request.path, - http_version=request.http_version, - headers=request.headers, - content=request.content, - timestamp_start=request.timestamp_start, - timestamp_end=request.timestamp_end, + first_line_format=request.data.first_line_format, + method=request.data.method, + scheme=request.data.scheme, + host=request.data.host, + port=request.data.port, + path=request.data.path, + http_version=request.data.http_version, + headers=request.data.headers, + content=request.data.content, + timestamp_start=request.data.timestamp_start, + timestamp_end=request.data.timestamp_end, form_out=(request.form_out if hasattr(request, 'form_out') else None), ) return req @@ -264,13 +264,13 @@ class HTTPResponse(MessageMixin, Response): @classmethod def wrap(self, response): resp = HTTPResponse( - http_version=response.http_version, - status_code=response.status_code, - reason=response.reason, - headers=response.headers, - content=response.content, - timestamp_start=response.timestamp_start, - timestamp_end=response.timestamp_end, + http_version=response.data.http_version, + status_code=response.data.status_code, + reason=response.data.reason, + headers=response.data.headers, + content=response.data.content, + timestamp_start=response.data.timestamp_start, + timestamp_end=response.data.timestamp_end, ) return resp diff --git a/mitmproxy/protocol/http.py b/mitmproxy/protocol/http.py index 81e59fbb..ae0dd53a 100644 --- a/mitmproxy/protocol/http.py +++ b/mitmproxy/protocol/http.py @@ -82,9 +82,12 @@ class ConnectServerConnection(object): def __getattr__(self, item): return getattr(self.via, item) - def __nonzero__(self): + def __bool__(self): return bool(self.via) + if six.PY2: + __nonzero__ = __bool__ + class UpstreamConnectLayer(Layer): diff --git a/mitmproxy/proxy/config.py b/mitmproxy/proxy/config.py index bd02c628..58b568ea 100644 --- a/mitmproxy/proxy/config.py +++ b/mitmproxy/proxy/config.py @@ -2,6 +2,8 @@ from __future__ import (absolute_import, print_function, division) import collections import os import re + +import six from OpenSSL import SSL from netlib import certutils, tcp @@ -34,9 +36,12 @@ class HostMatcher(object): else: return False - def __nonzero__(self): + def __bool__(self): return bool(self.patterns) + if six.PY2: + __nonzero__ = __bool__ + ServerSpec = collections.namedtuple("ServerSpec", "scheme address") |