aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorThomas Kriechbaumer <Kriechi@users.noreply.github.com>2016-05-29 11:03:54 +0200
committerThomas Kriechbaumer <Kriechi@users.noreply.github.com>2016-05-29 11:03:54 +0200
commitc707479bcd5a8ebb5d6bc8f54a5879176db46b3a (patch)
tree8fb49cb2bfa2f68b2841f2a4028c91eb781e4587 /examples
parent979c7fc319cbf551b9ea14062387f195b208b8fa (diff)
parent17382b963e22de8cb395a99e529b256e03d440ce (diff)
downloadmitmproxy-c707479bcd5a8ebb5d6bc8f54a5879176db46b3a.tar.gz
mitmproxy-c707479bcd5a8ebb5d6bc8f54a5879176db46b3a.tar.bz2
mitmproxy-c707479bcd5a8ebb5d6bc8f54a5879176db46b3a.zip
Merge pull request #1173 from mitmproxy/format-examples
Format examples
Diffstat (limited to 'examples')
-rw-r--r--examples/change_upstream_proxy.py2
-rw-r--r--examples/custom_contentviews.py3
-rw-r--r--examples/dns_spoofing.py3
-rw-r--r--examples/har_extractor.py7
-rw-r--r--examples/mitmproxywrapper.py7
-rw-r--r--examples/pathod/test_setup.py1
-rw-r--r--examples/pathod/test_setupall.py2
-rw-r--r--examples/redirect_requests.py1
-rw-r--r--examples/sslstrip.py22
-rw-r--r--examples/tcp_message.py1
-rw-r--r--examples/tls_passthrough.py2
11 files changed, 28 insertions, 23 deletions
diff --git a/examples/change_upstream_proxy.py b/examples/change_upstream_proxy.py
index 9c454897..34a6eece 100644
--- a/examples/change_upstream_proxy.py
+++ b/examples/change_upstream_proxy.py
@@ -21,4 +21,4 @@ def request(context, flow):
return
address = proxy_address(flow)
if flow.live:
- flow.live.change_upstream_proxy_server(address) \ No newline at end of file
+ flow.live.change_upstream_proxy_server(address)
diff --git a/examples/custom_contentviews.py b/examples/custom_contentviews.py
index f3b7317f..6cc9314c 100644
--- a/examples/custom_contentviews.py
+++ b/examples/custom_contentviews.py
@@ -23,7 +23,8 @@ class ViewPigLatin(contentviews.View):
ret = ''
for word in words:
idx = -1
- while word[idx] in string.punctuation and (idx * -1) != len(word): idx -= 1
+ while word[idx] in string.punctuation and (idx * -1) != len(word):
+ idx -= 1
if word[0].lower() in 'aeiou':
if idx == -1:
ret += word[0:] + "hay"
diff --git a/examples/dns_spoofing.py b/examples/dns_spoofing.py
index 7eb79695..8d715f33 100644
--- a/examples/dns_spoofing.py
+++ b/examples/dns_spoofing.py
@@ -22,7 +22,6 @@ Usage:
"""
import re
-
# This regex extracts splits the host header into host and port.
# Handles the edge case of IPv6 addresses containing colons.
# https://bugzilla.mozilla.org/show_bug.cgi?id=45891
@@ -47,4 +46,4 @@ def request(context, flow):
port = int(m.group("port"))
flow.request.host = sni or host_header
- flow.request.port = port \ No newline at end of file
+ flow.request.port = port
diff --git a/examples/har_extractor.py b/examples/har_extractor.py
index 371e2282..6806989d 100644
--- a/examples/har_extractor.py
+++ b/examples/har_extractor.py
@@ -162,8 +162,11 @@ def response(context, flow):
# If the current url is in the page list of context.HARLog or
# does not have a referrer, we add it as a new pages object.
- if (flow.request.url in context.HARLog.get_page_list() or
- flow.request.headers.get('Referer') is None):
+ is_new_page = (
+ flow.request.url in context.HARLog.get_page_list() or
+ flow.request.headers.get('Referer') is None
+ )
+ if is_new_page:
page_id = context.HARLog.create_page_id()
context.HARLog.add(
HAR.pages({
diff --git a/examples/mitmproxywrapper.py b/examples/mitmproxywrapper.py
index 7ea10715..f6afbf97 100644
--- a/examples/mitmproxywrapper.py
+++ b/examples/mitmproxywrapper.py
@@ -16,7 +16,6 @@ import sys
class Wrapper(object):
-
def __init__(self, port, extra_arguments=None):
self.port = port
self.extra_arguments = extra_arguments
@@ -142,7 +141,7 @@ class Wrapper(object):
'--toggle',
action='store_true',
help='just toggle the proxy configuration')
-# parser.add_argument('--honeyproxy', action='store_true', help='run honeyproxy instead of mitmproxy')
+ # parser.add_argument('--honeyproxy', action='store_true', help='run honeyproxy instead of mitmproxy')
parser.add_argument(
'-p',
'--port',
@@ -155,8 +154,8 @@ class Wrapper(object):
if args.toggle:
wrapper.toggle_proxy()
-# elif args.honeyproxy:
-# wrapper.wrap_honeyproxy()
+ # elif args.honeyproxy:
+ # wrapper.wrap_honeyproxy()
else:
wrapper.wrap_mitmproxy()
diff --git a/examples/pathod/test_setup.py b/examples/pathod/test_setup.py
index 5dbc456d..32fcb214 100644
--- a/examples/pathod/test_setup.py
+++ b/examples/pathod/test_setup.py
@@ -3,7 +3,6 @@ from pathod import test
class Test:
-
"""
Testing the requests module with
a pathod instance started for
diff --git a/examples/pathod/test_setupall.py b/examples/pathod/test_setupall.py
index cb84b7b2..cc0ec2e4 100644
--- a/examples/pathod/test_setupall.py
+++ b/examples/pathod/test_setupall.py
@@ -3,12 +3,12 @@ from pathod import test
class Test:
-
"""
Testing the requests module with
a single pathod instance started
for the test suite.
"""
+
@classmethod
def setup_class(cls):
cls.d = test.Daemon()
diff --git a/examples/redirect_requests.py b/examples/redirect_requests.py
index c0a0ccba..3ff8f9e4 100644
--- a/examples/redirect_requests.py
+++ b/examples/redirect_requests.py
@@ -4,6 +4,7 @@ This example shows two ways to redirect flows to other destinations.
from mitmproxy.models import HTTPResponse
from netlib.http import Headers
+
def request(context, flow):
# pretty_host takes the "Host" header of the request into account,
# which is useful in transparent mode where we usually only have the IP
diff --git a/examples/sslstrip.py b/examples/sslstrip.py
index 369427a2..1bc89946 100644
--- a/examples/sslstrip.py
+++ b/examples/sslstrip.py
@@ -2,39 +2,39 @@ from netlib.http import decoded
import re
from six.moves import urllib
-def start(context, argv) :
- #set of SSL/TLS capable hosts
+def start(context, argv):
+ # set of SSL/TLS capable hosts
context.secure_hosts = set()
-def request(context, flow) :
+def request(context, flow):
flow.request.headers.pop('If-Modified-Since', None)
flow.request.headers.pop('Cache-Control', None)
- #proxy connections to SSL-enabled hosts
- if flow.request.pretty_host in context.secure_hosts :
+ # proxy connections to SSL-enabled hosts
+ if flow.request.pretty_host in context.secure_hosts:
flow.request.scheme = 'https'
flow.request.port = 443
-def response(context, flow) :
- with decoded(flow.response) :
+def response(context, flow):
+ with decoded(flow.response):
flow.request.headers.pop('Strict-Transport-Security', None)
flow.request.headers.pop('Public-Key-Pins', None)
- #strip links in response body
+ # strip links in response body
flow.response.content = flow.response.content.replace('https://', 'http://')
- #strip links in 'Location' header
- if flow.response.headers.get('Location','').startswith('https://'):
+ # strip links in 'Location' header
+ if flow.response.headers.get('Location', '').startswith('https://'):
location = flow.response.headers['Location']
hostname = urllib.parse.urlparse(location).hostname
if hostname:
context.secure_hosts.add(hostname)
flow.response.headers['Location'] = location.replace('https://', 'http://', 1)
- #strip secure flag from 'Set-Cookie' headers
+ # strip secure flag from 'Set-Cookie' headers
cookies = flow.response.headers.get_all('Set-Cookie')
cookies = [re.sub(r';\s*secure\s*', '', s) for s in cookies]
flow.response.headers.set_all('Set-Cookie', cookies)
diff --git a/examples/tcp_message.py b/examples/tcp_message.py
index c63368e4..52471ae9 100644
--- a/examples/tcp_message.py
+++ b/examples/tcp_message.py
@@ -10,6 +10,7 @@ mitmdump -T --host --tcp ".*" -q -s examples/tcp_message.py
'''
from netlib.utils import clean_bin
+
def tcp_message(ctx, tcp_msg):
modified_msg = tcp_msg.message.replace("foo", "bar")
diff --git a/examples/tls_passthrough.py b/examples/tls_passthrough.py
index 8c8fa4eb..23afe3ff 100644
--- a/examples/tls_passthrough.py
+++ b/examples/tls_passthrough.py
@@ -40,6 +40,7 @@ class _TlsStrategy(object):
"""
Abstract base class for interception strategies.
"""
+
def __init__(self):
# A server_address -> interception results mapping
self.history = collections.defaultdict(lambda: collections.deque(maxlen=200))
@@ -78,6 +79,7 @@ class ProbabilisticStrategy(_TlsStrategy):
"""
Fixed probability that we intercept a given connection.
"""
+
def __init__(self, p):
self.p = p
super(ProbabilisticStrategy, self).__init__()