Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# combine +- and following number or other
i += 1
try:
next = seq[i]
except IndexError:
firstvalue = () # raised later
break
newval = item.value + next.value
newseq.append(newval, next.type,
item.line, item.col)
if not firstvalue:
firstvalue = (newval, next.type)
count += 1
elif item.type != cssutils.css.CSSComment:
newseq.appendItem(item)
if not firstvalue:
firstvalue = (item.value, item.type)
count += 1
else:
newseq.appendItem(item)
i += 1
if not firstvalue:
self._log.error(
u'CSSValue: Unknown syntax or no value: %r.' %
self._valuestr(cssText))
else:
# ok and set
def rule(input_rule):
# Non-style elements are presently stripped. We may want to maintain
# comments at some point, but for now we'll only pass the barest
# structural elements that we're sure are safe through.
if input_rule.type == input_rule.STYLE_RULE:
output_rule = css.CSSStyleRule(selectorText=input_rule.selectorText, parentStyleSheet=output)
for prop in input_rule.style:
if prop.name.lower() in ruleset:
output_rule.style.setProperty(prop.name, value(prop.cssValue))
output.add(output_rule)
def insertRule(self, rule, index=None):
"""Implements base ``insertRule``."""
rule, index = self._prepareInsertRule(rule, index)
if rule is False or rule is True:
# done or error
return
# check hierarchy
if isinstance(rule, cssutils.css.CSSCharsetRule) or \
isinstance(rule, cssutils.css.CSSFontFaceRule) or \
isinstance(rule, cssutils.css.CSSImportRule) or \
isinstance(rule, cssutils.css.CSSNamespaceRule) or \
isinstance(rule, cssutils.css.CSSPageRule) or \
isinstance(rule, cssutils.css.MarginRule) or \
isinstance(rule, CSSMediaRule):
self._log.error(u'%s: This type of rule is not allowed here: %s'
% (self.__class__.__name__, rule.cssText),
error=xml.dom.HierarchyRequestErr)
return
return self._finishInsertRule(rule, index)
# We don't care about invalid CSS data, this will only litter the log
# output with CSS errors
parser = cssutils.CSSParser(loglevel=100,
fetcher=lambda url: (None, ""), validate=False)
if not inline:
sheet = parser.parseString(data)
return list(cssutils.getUrls(sheet))
else:
urls = []
declaration = parser.parseStyle(data)
# prop = background, color, margin, ...
for prop in declaration:
# value = red, 10px, url(foobar), ...
for value in prop.propertyValue:
if isinstance(value, cssutils.css.URIValue):
if value.uri:
urls.append(value.uri)
return urls
def importrule(expected, seq, token, tokenizer):
if new['encoding']:
# set temporarily as used by _resolveImport
# save newEncoding which have been set by resolveImport
self.__newEncoding = new['encoding']
rule = cssutils.css.CSSImportRule(parentStyleSheet=self)
rule.cssText = self._tokensupto2(tokenizer, token)
if expected > 1:
self._log.error(
u'CSSStylesheet: CSSImportRule not allowed here.',
token, xml.dom.HierarchyRequestErr)
else:
if rule.wellformed:
#del rule._parentEncoding # remove as later it is read from this sheet!
seq.append(rule)
try:
# remove as only used temporarily but may not be set at all
del self.__newEncoding
except AttributeError, e:
pass
def _css_rules_to_string(self, rules):
"""given a list of css rules returns a css string
"""
lines = []
for item in rules:
if isinstance(item, tuple):
k, v = item
lines.append('%s {%s}' % (k, make_important(v)))
# media rule
else:
for rule in item.cssRules:
if isinstance(rule, cssutils.css.csscomment.CSSComment):
continue
for key in rule.style.keys():
rule.style[key] = (
rule.style.getPropertyValue(key, False),
'!important'
)
lines.append(item.cssText)
return '\n'.join(lines)