Merge branch 'module-imports' of github.com:mitmproxy/mitmproxy into module-imports

This commit is contained in:
Aldo Cortesi 2016-06-01 14:43:24 +12:00
commit efbdd8d266
2 changed files with 15 additions and 18 deletions

View File

@ -20,12 +20,12 @@ import logging
import subprocess import subprocess
import sys import sys
import PIL
import html2text import html2text
import lxml.etree import lxml.etree
import lxml.html import lxml.html
import six import six
from PIL import ExifTags from PIL import ExifTags
from PIL import Image
from six.moves import cStringIO as StringIO from six.moves import cStringIO as StringIO
from mitmproxy import exceptions from mitmproxy import exceptions
@ -36,8 +36,7 @@ from netlib import encoding
from netlib import http from netlib import http
from netlib import odict from netlib import odict
from netlib.http import url from netlib.http import url
from netlib.utils import clean_bin from netlib import utils
from netlib.utils import hexdump
try: try:
import pyamf import pyamf
@ -157,7 +156,7 @@ class ViewHex(View):
@staticmethod @staticmethod
def _format(data): def _format(data):
for offset, hexa, s in hexdump(data): for offset, hexa, s in utils.hexdump(data):
yield [ yield [
("offset", offset + " "), ("offset", offset + " "),
("text", hexa + " "), ("text", hexa + " "),
@ -403,7 +402,7 @@ class ViewImage(View):
def __call__(self, data, **metadata): def __call__(self, data, **metadata):
try: try:
img = PIL.Image.open(StringIO(data)) img = Image.open(StringIO(data))
except IOError: except IOError:
return None return None
parts = [ parts = [
@ -582,9 +581,9 @@ def safe_to_print(lines, encoding="utf8"):
clean_line = [] clean_line = []
for (style, text) in line: for (style, text) in line:
try: try:
text = clean_bin(text.decode(encoding, "strict")) text = utils.clean_bin(text.decode(encoding, "strict"))
except UnicodeDecodeError: except UnicodeDecodeError:
text = clean_bin(text).decode(encoding, "strict") text = utils.clean_bin(text).decode(encoding, "strict")
clean_line.append((style, text)) clean_line.append((style, text))
yield clean_line yield clean_line

View File

@ -8,10 +8,8 @@ import threading
import time import time
import configargparse import configargparse
from pydivert.enum import Direction from pydivert import enum
from pydivert.enum import Flag from pydivert import windivert
from pydivert.enum import Layer
from pydivert.windivert import WinDivert
from six.moves import cPickle as pickle from six.moves import cPickle as pickle
from six.moves import socketserver from six.moves import socketserver
@ -199,7 +197,7 @@ class TransparentProxy(object):
self.api_thread = threading.Thread(target=self.api.serve_forever) self.api_thread = threading.Thread(target=self.api.serve_forever)
self.api_thread.daemon = True self.api_thread.daemon = True
self.driver = WinDivert() self.driver = windivert.WinDivert()
self.driver.register() self.driver.register()
self.request_filter = custom_filter or " or ".join( self.request_filter = custom_filter or " or ".join(
@ -245,23 +243,23 @@ class TransparentProxy(object):
# real gateway if they are on the same network. # real gateway if they are on the same network.
self.icmp_handle = self.driver.open_handle( self.icmp_handle = self.driver.open_handle(
filter="icmp", filter="icmp",
layer=Layer.NETWORK, layer=enum.Layer.NETWORK,
flags=Flag.DROP) flags=enum.Flag.DROP)
self.response_handle = self.driver.open_handle( self.response_handle = self.driver.open_handle(
filter=self.response_filter, filter=self.response_filter,
layer=Layer.NETWORK) layer=enum.Layer.NETWORK)
self.response_thread.start() self.response_thread.start()
if self.mode == "forward" or self.mode == "both": if self.mode == "forward" or self.mode == "both":
self.request_forward_handle = self.driver.open_handle( self.request_forward_handle = self.driver.open_handle(
filter=self.request_filter, filter=self.request_filter,
layer=Layer.NETWORK_FORWARD) layer=enum.Layer.NETWORK_FORWARD)
self.request_forward_thread.start() self.request_forward_thread.start()
if self.mode == "local" or self.mode == "both": if self.mode == "local" or self.mode == "both":
self.request_local_handle = self.driver.open_handle( self.request_local_handle = self.driver.open_handle(
filter=self.request_filter, filter=self.request_filter,
layer=Layer.NETWORK) layer=enum.Layer.NETWORK)
self.request_local_thread.start() self.request_local_thread.start()
def shutdown(self): def shutdown(self):
@ -353,7 +351,7 @@ class TransparentProxy(object):
self.client_server_map[client] = server self.client_server_map[client] = server
packet.dst_addr, packet.dst_port = self.proxy_addr, self.proxy_port packet.dst_addr, packet.dst_port = self.proxy_addr, self.proxy_port
metadata.direction = Direction.INBOUND metadata.direction = enum.Direction.INBOUND
packet = self.driver.update_packet_checksums(packet) packet = self.driver.update_packet_checksums(packet)
# Use any handle thats on the NETWORK layer - request_local may be # Use any handle thats on the NETWORK layer - request_local may be