From e9f6302ec7dacb55f83bf1c283963c7a35fa0f6b Mon Sep 17 00:00:00 2001 From: Tomaz Muraus Date: Sat, 4 Jan 2014 04:06:42 +0100 Subject: Add CSS view which beautifies CSS files if cssutils library is available, otherwise it acts as a no-op. --- libmproxy/console/contentview.py | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'libmproxy/console') diff --git a/libmproxy/console/contentview.py b/libmproxy/console/contentview.py index 8dd8ad1d..d6601045 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,13 @@ try: except ImportError: # pragma nocover pyamf = None +try: + import cssutils +except ImportError: # pragma nocover + cssutils = None +else: + cssutils.log.setLevel(logging.CRITICAL) + VIEW_CUTOFF = 1024*50 @@ -318,7 +326,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 +433,7 @@ views = [ ViewHTML(), ViewHTMLOutline(), ViewJavaScript(), + ViewCSS(), ViewURLEncoded(), ViewMultipart(), ViewImage(), -- cgit v1.2.3 From ff2d7a7501e3f510882266fd456349576d5859fc Mon Sep 17 00:00:00 2001 From: Tomaz Muraus Date: Sat, 4 Jan 2014 15:50:40 +0100 Subject: Provide more sensible serializer options. --- libmproxy/console/contentview.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'libmproxy/console') diff --git a/libmproxy/console/contentview.py b/libmproxy/console/contentview.py index d6601045..05607eb1 100644 --- a/libmproxy/console/contentview.py +++ b/libmproxy/console/contentview.py @@ -27,6 +27,11 @@ except ImportError: # pragma nocover 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 -- cgit v1.2.3 From c5f4614ba5bc8e3497951ef49c66fde07fb02ddb Mon Sep 17 00:00:00 2001 From: Tomaz Muraus Date: Sat, 4 Jan 2014 17:13:46 +0100 Subject: Fix CSS view prompt, update display mode options. --- libmproxy/console/contentview.py | 2 +- libmproxy/console/help.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'libmproxy/console') diff --git a/libmproxy/console/contentview.py b/libmproxy/console/contentview.py index 05607eb1..b03d06c5 100644 --- a/libmproxy/console/contentview.py +++ b/libmproxy/console/contentview.py @@ -335,7 +335,7 @@ class ViewJavaScript: class ViewCSS: name = "CSS" - prompt = ("CSS", "c") + prompt = ("css", "c") content_types = [ "text/css" ] diff --git a/libmproxy/console/help.py b/libmproxy/console/help.py index f8be6605..0d01ac6f 100644 --- a/libmproxy/console/help.py +++ b/libmproxy/console/help.py @@ -61,6 +61,10 @@ class HelpView(urwid.ListBox): common.highlight_key("json", "s") + [("text", ": JSON")] ), + (None, + common.highlight_key("css", "c") + + [("text", ": CSS")] + ), (None, common.highlight_key("urlencoded", "u") + [("text", ": URL-encoded data")] -- cgit v1.2.3