aboutsummaryrefslogtreecommitdiffstats
path: root/mitmproxy/contentviews/css.py
blob: 353a3257fe304cfa2f41507e142a652aca338d66 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import logging

import cssutils

from . import base


class ViewCSS(base.View):
    name = "CSS"
    prompt = ("css", "c")
    content_types = [
        "text/css"
    ]

    def __call__(self, data, **metadata):
        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

        sheet = cssutils.parseString(data)
        beautified = sheet.cssText

        return "CSS", base.format_text(beautified)