Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
ok_(url.startswith('https://'))
if 'style1.css' in url:
return MockResponse(
"h1 { color: brown }"
)
if 'style2.css' in url:
return MockResponse(
"h2 { color: pink }"
)
if 'style3.css' in url:
return MockResponse(
"h3 { color: red }", gzip=True
)
urlopen = mocked_urlopen
p = Premailer(
html,
base_url='https://www.peterbe.com'
)
result_html = p.transform()
compare_html(expect_html, result_html)
expect_html = """
<title>Title</title>
<style type="text/css">a:hover {color:purple !important}</style>
<h1 style="color:orange">Hello</h1>
<h2 style="color:green">World</h2>
<h3 style="color:yellow">Test</h3>
<a style="color:pink" href="#">Link</a>
"""
p = Premailer(
html,
strip_important=False
)
result_html = p.transform()
compare_html(expect_html, result_html)
<a href="#">Hi!</a>
"""
expect_html = """
<title>Title</title>
<style type="text/css">a:hover {color:green !important}
a:focus {color:blue !important}</style>
<a style="color:red" href="#">Hi!</a>
"""
p = Premailer(html,
keep_style_tags=True,
strip_important=False)
result_html = p.transform()
compare_html(expect_html, result_html)
def test_broken_xml(self):
"""Test the simplest case with xml"""
html = """
<title>Title
<style type="text/css">
img { border: none; }
</style>
</head>
<body>
<img src="test.png" alt="test"/>
</body>
"""
p = Premailer(html, method="xml")
assert_raises(
XMLSyntaxError,
p.transform,
)</title>
<div class="example"></div>
"""
expect_html = """
<div style="color:green"></div>
"""
p = Premailer(html)
result_html = p.transform()
compare_html(expect_html, result_html)
<div class="example"></div>
"""
expect_html = """
<div style="color:green"></div>
"""
p = Premailer(html)
result_html = p.transform()
compare_html(expect_html, result_html)
<div id="identified" class="example"></div>
"""
expect_html = """
<div style="color:green" id="identified"></div>
"""
p = Premailer(html)
result_html = p.transform()
compare_html(expect_html, result_html)
expect_html = """
<p style="text-align:center">Text</p>
<table style="height:300px; width:200px">
<tbody><tr>
<td bgcolor="red" style="background-color:red">Cell 1</td>
<td bgcolor="red" style="background-color:red">Cell 2</td>
</tr>
</tbody></table>
"""
p = Premailer(
html,
exclude_pseudoclasses=True,
disable_basic_attributes=['align', 'width', 'height']
)
result_html = p.transform()
expect_html = re.sub('}\s+', '}', expect_html)
result_html = result_html.replace('}\n', '}')
compare_html(expect_html, result_html)
<div>First div</div>
"""
expect_html = """
<div align="right" style="text-align:right">First div</div>
"""
p = Premailer(html)
result_html = p.transform()
compare_html(expect_html, result_html)
"--allow-insecure-ssl",
default=False,
action="store_true",
help="Skip SSL certificate verification for external URLs.",
)
options = parser.parse_args(args)
if options.disable_basic_attributes:
options.disable_basic_attributes = options.disable_basic_attributes.split()
html = options.infile.read()
if hasattr(html, "decode"): # Forgive me: Python 2 compatability
html = html.decode("utf-8")
p = Premailer(
html=html,
base_url=options.base_url,
preserve_internal_links=options.preserve_internal_links,
exclude_pseudoclasses=options.exclude_pseudoclasses,
keep_style_tags=options.keep_style_tags,
include_star_selectors=options.include_star_selectors,
remove_classes=options.remove_classes,
strip_important=options.strip_important,
external_styles=options.external_styles,
css_text=options.css_text,
method=options.method,
base_path=options.base_path,
disable_basic_attributes=options.disable_basic_attributes,
disable_validation=options.disable_validation,
allow_insecure_ssl=options.allow_insecure_ssl,
)