"""classes and functions used by cssutils scripts
"""
__all__ = ['CSSCapture', 'csscombine']
import html.parser
import codecs
import cssutils
import errno
import logging
import os
import sys
import urllib.request
import urllib.error
import urllib.parse
import encutils
# types of sheets in HTML
LINK = (
0 #
)
STYLE = 1 #
class CSSCaptureHTMLParser(html.parser.HTMLParser):
"""CSSCapture helper: Parse given data for link and style elements"""
curtag = ''
sheets = [] # (type, [atts, cssText])
def _loweratts(self, atts):
return {a.lower(): v.lower() for a, v in atts}
def handle_starttag(self, tag, atts):
if tag == 'link':
atts = self._loweratts(atts)
if 'text/css' == atts.get('type', ''):
self.sheets.append((LINK, atts))
elif tag == 'style':
# also get content of style
atts = self._loweratts(atts)
if 'text/css' == atts.get('type', ''):
self.sheets.append((STYLE, [atts, '']))
self.curtag = tag
else:
# close as only intersting