def test_get_urls_from_css_resource_fonts(): content = b"""@font-face { font-family: "A"; src: url(1); src: url("2") format("f1"), url("3") format("f2");}""" urls = parsers.get_urls_from_css_resource(content) assert urls == ["1", "2", "3"]
def handle_resources(content_type, content): urls_from_css, urls_from_svg = [], [] if content_type.startswith("text/css"): urls_from_css = parsers.get_urls_from_css_resource(content) if content_type.startswith("image/svg"): urls_from_svg = parsers.get_urls_from_svg_resource(content) for discovered_url in urls_from_css + urls_from_svg: target_url = _apply_base_url(discovered_url, base_url) with self.discovered_resources_lock: discovered_resources_urls.append(target_url)
def handle_resources(content_type, content, resource_url): logger.debug("handle_resources({0}, {1}) call".format( content_type, resource_url)) urls_from_css, urls_from_svg = [], [] if content_type.startswith("text/css"): urls_from_css = parsers.get_urls_from_css_resource(content) if content_type.startswith("image/svg"): urls_from_svg = parsers.get_urls_from_svg_resource(content) for discovered_url in urls_from_css + urls_from_svg: if discovered_url.startswith( "data:") or discovered_url.startswith("#"): # resource already in blob or not relevant continue target_url = apply_base_url(discovered_url, base_url, resource_url) with discovered_resources_lock: discovered_resources_urls.add(target_url)
def test_get_urls_charset_rule_does_not_crash(): content = b'@charset "UTF-8";' urls = parsers.get_urls_from_css_resource(content) assert urls == []
def test_get_urls_from_css_resource_background_img(): content = b'p {background-image: url("1");} a {background-image: url(2);}' urls = parsers.get_urls_from_css_resource(content) assert urls == ["1", "2"]
def test_get_urls_from_css_resource_imports(): content = b'@import "1.css";@import url(2.css);@import url("3.css")' urls = parsers.get_urls_from_css_resource(content) assert urls == ["1.css", "2.css", "3.css"]