aboutsummaryrefslogtreecommitdiffstats
path: root/libmproxy/console/contentview.py
diff options
context:
space:
mode:
Diffstat (limited to 'libmproxy/console/contentview.py')
-rw-r--r--libmproxy/console/contentview.py39
1 files changed, 33 insertions, 6 deletions
diff --git a/libmproxy/console/contentview.py b/libmproxy/console/contentview.py
index 8dd8ad1d..70f39d83 100644
--- a/libmproxy/console/contentview.py
+++ b/libmproxy/console/contentview.py
@@ -1,11 +1,9 @@
+import logging
import re, cStringIO, traceback, json
import urwid
-try: from PIL import Image
-except ImportError: import Image
-
-try: from PIL.ExifTags import TAGS
-except ImportError: from ExifTags import TAGS
+from PIL import Image
+from PIL.ExifTags import TAGS
import lxml.html, lxml.etree
import netlib.utils
@@ -19,6 +17,18 @@ try:
except ImportError: # pragma nocover
pyamf = None
+try:
+ import cssutils
+except ImportError: # pragma nocover
+ cssutils = None
+else:
+ cssutils.log.setLevel(logging.CRITICAL)
+
+ cssutils.ser.prefs.keepComments = True
+ cssutils.ser.prefs.omitLastSemicolon = False
+ cssutils.ser.prefs.indentClosingBrace = False
+ cssutils.ser.prefs.validOnly = False
+
VIEW_CUTOFF = 1024*50
@@ -318,7 +328,23 @@ class ViewJavaScript:
opts = jsbeautifier.default_options()
opts.indent_size = 2
res = jsbeautifier.beautify(content[:limit], opts)
- return "JavaScript", _view_text(res, len(content), limit)
+ return "JavaScript", _view_text(res, len(res), limit)
+
+class ViewCSS:
+ name = "CSS"
+ prompt = ("css", "c")
+ content_types = [
+ "text/css"
+ ]
+
+ def __call__(self, hdrs, content, limit):
+ if cssutils:
+ sheet = cssutils.parseString(content)
+ beautified = sheet.cssText
+ else:
+ beautified = content
+
+ return "CSS", _view_text(beautified, len(beautified), limit)
class ViewImage:
@@ -409,6 +435,7 @@ views = [
ViewHTML(),
ViewHTMLOutline(),
ViewJavaScript(),
+ ViewCSS(),
ViewURLEncoded(),
ViewMultipart(),
ViewImage(),