:type data: str :returns: A hash of css selectors, each of which contains a hash of css attributes. :rtype: dict
(data: str)
| 29 | |
| 30 | |
| 31 | def dumb_css_parser(data: str) -> Dict[str, Dict[str, str]]: |
| 32 | """ |
| 33 | :type data: str |
| 34 | |
| 35 | :returns: A hash of css selectors, each of which contains a hash of |
| 36 | css attributes. |
| 37 | :rtype: dict |
| 38 | """ |
| 39 | # remove @import sentences |
| 40 | data += ";" |
| 41 | importIndex = data.find("@import") |
| 42 | while importIndex != -1: |
| 43 | data = data[0:importIndex] + data[data.find(";", importIndex) + 1 :] |
| 44 | importIndex = data.find("@import") |
| 45 | |
| 46 | # parse the css. reverted from dictionary comprehension in order to |
| 47 | # support older pythons |
| 48 | pairs = [x.split("{") for x in data.split("}") if "{" in x.strip()] |
| 49 | try: |
| 50 | elements = {a.strip(): dumb_property_dict(b) for a, b in pairs} |
| 51 | except ValueError: |
| 52 | elements = {} # not that important |
| 53 | |
| 54 | return elements |
| 55 | |
| 56 | |
| 57 | def element_style( |
no test coverage detected
searching dependent graphs…