diff options
Diffstat (limited to 'libmproxy/console/contentview.py')
-rw-r--r-- | libmproxy/console/contentview.py | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/libmproxy/console/contentview.py b/libmproxy/console/contentview.py index 8dd8ad1d..b03d06c5 100644 --- a/libmproxy/console/contentview.py +++ b/libmproxy/console/contentview.py @@ -1,3 +1,4 @@ +import logging import re, cStringIO, traceback, json import urwid @@ -19,6 +20,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 +331,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 +438,7 @@ views = [ ViewHTML(), ViewHTMLOutline(), ViewJavaScript(), + ViewCSS(), ViewURLEncoded(), ViewMultipart(), ViewImage(), |