diff options
author | Tomaz Muraus <tomaz@tomaz.me> | 2014-01-04 04:06:42 +0100 |
---|---|---|
committer | Tomaz Muraus <tomaz@tomaz.me> | 2014-01-04 04:49:50 +0100 |
commit | e9f6302ec7dacb55f83bf1c283963c7a35fa0f6b (patch) | |
tree | 9a024c47406b5e578cfaf27fd403723f7a6ad523 /libmproxy/console | |
parent | b9d4eb103e6b45cc331b0fc3cd5a0c693f1b669e (diff) | |
download | mitmproxy-e9f6302ec7dacb55f83bf1c283963c7a35fa0f6b.tar.gz mitmproxy-e9f6302ec7dacb55f83bf1c283963c7a35fa0f6b.tar.bz2 mitmproxy-e9f6302ec7dacb55f83bf1c283963c7a35fa0f6b.zip |
Add CSS view which beautifies CSS files if cssutils library is available,
otherwise it acts as a no-op.
Diffstat (limited to 'libmproxy/console')
-rw-r--r-- | libmproxy/console/contentview.py | 27 |
1 files changed, 26 insertions, 1 deletions
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(), |