aboutsummaryrefslogtreecommitdiffstats
path: root/mitmproxy/contentviews.py
diff options
context:
space:
mode:
Diffstat (limited to 'mitmproxy/contentviews.py')
-rw-r--r--mitmproxy/contentviews.py53
1 files changed, 29 insertions, 24 deletions
diff --git a/mitmproxy/contentviews.py b/mitmproxy/contentviews.py
index 373c9514..6215fa4d 100644
--- a/mitmproxy/contentviews.py
+++ b/mitmproxy/contentviews.py
@@ -12,27 +12,32 @@ use. For HTTP, the message headers are passed as the ``headers`` keyword argumen
requests, the query parameters are passed as the ``query`` keyword argument.
"""
-from __future__ import (absolute_import, print_function, division)
-from six.moves import cStringIO as StringIO
+from __future__ import absolute_import, print_function, division
+
+import datetime
import json
import logging
import subprocess
import sys
-import lxml.html
-import lxml.etree
-import datetime
-from PIL import Image
-from PIL.ExifTags import TAGS
+
+import PIL
import html2text
+import lxml.etree
+import lxml.html
import six
-from netlib.odict import ODict
-from netlib import encoding, http
+from PIL import ExifTags
+from six.moves import cStringIO as StringIO
+
+from mitmproxy import exceptions
+from mitmproxy import utils
+from mitmproxy.contrib import jsbeautifier
+from mitmproxy.contrib.wbxml import ASCommandResponse
+from netlib import encoding
+from netlib import http
+from netlib import odict
from netlib.http import url
-from netlib.utils import clean_bin, hexdump
-from . import utils
-from .exceptions import ContentViewException
-from .contrib import jsbeautifier
-from .contrib.wbxml.ASCommandResponse import ASCommandResponse
+from netlib.utils import clean_bin
+from netlib.utils import hexdump
try:
import pyamf
@@ -259,7 +264,7 @@ class ViewURLEncoded(View):
def __call__(self, data, **metadata):
d = url.decode(data)
- return "URLEncoded form", format_dict(ODict(d))
+ return "URLEncoded form", format_dict(odict.ODict(d))
class ViewMultipart(View):
@@ -270,7 +275,7 @@ class ViewMultipart(View):
@staticmethod
def _format(v):
yield [("highlight", "Form data:\n")]
- for message in format_dict(ODict(v)):
+ for message in format_dict(odict.ODict(v)):
yield message
def __call__(self, data, **metadata):
@@ -398,7 +403,7 @@ class ViewImage(View):
def __call__(self, data, **metadata):
try:
- img = Image.open(StringIO(data))
+ img = PIL.Image.open(StringIO(data))
except IOError:
return None
parts = [
@@ -415,11 +420,11 @@ class ViewImage(View):
ex = img._getexif()
if ex:
for i in sorted(ex.keys()):
- tag = TAGS.get(i, i)
+ tag = ExifTags.TAGS.get(i, i)
parts.append(
(str(tag), str(ex[i]))
)
- fmt = format_dict(ODict(parts))
+ fmt = format_dict(odict.ODict(parts))
return "%s image" % img.format, fmt
@@ -490,7 +495,7 @@ class ViewWBXML(View):
def __call__(self, data, **metadata):
try:
- parser = ASCommandResponse(data)
+ parser = ASCommandResponse.ASCommandResponse(data)
parsedContent = parser.xmlString
if parsedContent:
return "WBXML", format_text(parsedContent)
@@ -519,12 +524,12 @@ def add(view):
# TODO: auto-select a different name (append an integer?)
for i in views:
if i.name == view.name:
- raise ContentViewException("Duplicate view: " + view.name)
+ raise exceptions.ContentViewException("Duplicate view: " + view.name)
# TODO: the UI should auto-prompt for a replacement shortcut
for prompt in view_prompts:
if prompt[1] == view.prompt[1]:
- raise ContentViewException("Duplicate view shortcut: " + view.prompt[1])
+ raise exceptions.ContentViewException("Duplicate view shortcut: " + view.prompt[1])
views.append(view)
@@ -611,8 +616,8 @@ def get_content_view(viewmode, data, **metadata):
# Third-party viewers can fail in unexpected ways...
except Exception as e:
six.reraise(
- ContentViewException,
- ContentViewException(str(e)),
+ exceptions.ContentViewException,
+ exceptions.ContentViewException(str(e)),
sys.exc_info()[2]
)
if not ret: