Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@function_cache()
def csstext_to_pairs(csstext, validate=True):
"""
csstext_to_pairs takes css text and make it to list of
tuple of key,value.
"""
# The lock is required to avoid ``cssutils`` concurrency
# issues documented in issue #65
with csstext_to_pairs._lock:
return sorted(
[
(prop.name.strip(), format_value(prop))
for prop in cssutils.parseStyle(csstext, validate=validate)
],
key=itemgetter(0),
)
@function_cache()
def _create_cssselector(selector):
return CSSSelector(selector)
@function_cache()
def _cache_parse_css_string(css_body, validate=True):
"""
This function will cache the result from cssutils
It is a big gain when number of rules is big
Maximum cache entries are 1000. This is mainly for
protecting memory leak in case something gone wild.
Be aware that you can turn the cache off in Premailer
Args:
css_body(str): css rules in string format
validate(bool): if cssutils should validate
Returns:
cssutils.css.cssstylesheet.CSSStyleSheet
"""
@function_cache()
def _cache_parse_css_string(css_body, validate=True):
"""
This function will cache the result from cssutils
It is a big gain when number of rules is big
Maximum cache entries are 1000. This is mainly for
protecting memory leak in case something gone wild.
Be aware that you can turn the cache off in Premailer
Args:
css_body(str): css rules in string format
validate(bool): if cssutils should validate
Returns:
cssutils.css.cssstylesheet.CSSStyleSheet
"""