Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
out = []
for i, item in enumerate(seq):
typ, val = item.type, item.value
if isinstance(val, cssutils.css.CSSComment):
# CSSComment
if self.prefs.keepComments:
out.append(val.cssText)
out.append(separator)
elif isinstance(val, cssutils.css.Property):
# PropertySimilarNameList
out.append(val.cssText)
if not (self.prefs.omitLastSemicolon and i==len(seq)-1):
out.append(u';')
out.append(separator)
elif isinstance(val, cssutils.css.CSSUnknownRule):
# @rule
out.append(val.cssText)
out.append(separator)
else:
# ?
out.append(val)
out.append(separator)
if out and out[-1] == separator:
del out[-1]
return u''.join(out)
else:
return u''
out = []
for i, item in enumerate(seq):
typ, val = item.type, item.value
if isinstance(val, cssutils.css.CSSComment):
# CSSComment
if self.prefs.keepComments:
out.append(val.cssText)
out.append(separator)
elif isinstance(val, cssutils.css.Property):
# PropertySimilarNameList
out.append(val.cssText)
if not (self.prefs.omitLastSemicolon and i==len(seq)-1):
out.append(u';')
out.append(separator)
elif isinstance(val, cssutils.css.CSSUnknownRule):
# @rule
out.append(val.cssText)
out.append(separator)
else:
# ?
out.append(val)
out.append(separator)
if out and out[-1] == separator:
del out[-1]
return u''.join(out)
else:
return u''
for i, item in enumerate(seq):
type_, val = item.type, item.value
if isinstance(val, cssutils.css.CSSComment):
# CSSComment
if self.prefs.keepComments:
out.append(val.cssText)
out.append(separator)
elif isinstance(val, cssutils.css.Property):
# PropertySimilarNameList
if val.cssText:
out.append(val.cssText)
if not (omitLastSemicolon and i==len(seq)-1):
out.append(u';')
out.append(separator)
elif isinstance(val, cssutils.css.CSSUnknownRule):
# @rule
out.append(val.cssText)
out.append(separator)
else:
# ?
out.append(val)
out.append(separator)
if out and out[-1] == separator:
del out[-1]
return u''.join(out)
else:
return u''
def atrule(expected, seq, token, tokenizer):
# TODO: get complete rule!
tokens = self._tokensupto2(tokenizer, token)
atval = self._tokenvalue(token)
if atval in ('@charset ', '@font-face', '@import', '@namespace',
'@page', '@media'):
self._log.error(
u'CSSMediaRule: This rule is not allowed in CSSMediaRule - ignored: %s.'
% self._valuestr(tokens),
token = token,
error=xml.dom.HierarchyRequestErr)
else:
rule = cssutils.css.CSSUnknownRule(parentRule=self,
parentStyleSheet=self.parentStyleSheet)
rule.cssText = tokens
if rule.wellformed:
seq.append(rule)
return expected
def unknownrule(expected, seq, token, tokenizer):
# parse and consume tokens in any case
if token[1] in cssutils.css.MarginRule.margins:
self._log.error(u'CSSStylesheet: MarginRule out CSSPageRule.',
token, neverraise=True)
rule = cssutils.css.MarginRule(parentStyleSheet=self)
rule.cssText = self._tokensupto2(tokenizer, token)
else:
self._log.warn(u'CSSStylesheet: Unknown @rule found.',
token, neverraise=True)
rule = cssutils.css.CSSUnknownRule(parentStyleSheet=self)
rule.cssText = self._tokensupto2(tokenizer, token)
if rule.wellformed:
self.insertRule(rule)
# or 0 for py3
return max(1, expected or 0)
def rule(tokens):
saved = []
for t in tokens:
saved.append(t)
if (t[1] == u'}' or t[1] == u';'):
return cssutils.css.CSSUnknownRule(saved)
for i, item in enumerate(seq):
type_, val = item.type, item.value
if isinstance(val, cssutils.css.CSSComment):
# CSSComment
if self.prefs.keepComments:
out.append(val.cssText)
out.append(separator)
elif isinstance(val, cssutils.css.Property):
# PropertySimilarNameList
if val.cssText:
out.append(val.cssText)
if not (omitLastSemicolon and i==len(seq)-1):
out.append(u';')
out.append(separator)
elif isinstance(val, cssutils.css.CSSUnknownRule):
# @rule
out.append(val.cssText)
out.append(separator)
else:
# ?
out.append(val)
out.append(separator)
if out and out[-1] == separator:
del out[-1]
return u''.join(out)
else:
return u''
def rule(tokens):
saved = []
for t in tokens:
saved.append(t)
if (t[1] == u'}' or t[1] == u';'):
return cssutils.css.CSSUnknownRule(saved)
def unknownrule(expected, seq, token, tokenizer):
self._log.warn(
u'CSSStylesheet: Unknown @rule found.',
token, neverraise=True)
rule = cssutils.css.CSSUnknownRule(parentStyleSheet=self)
rule.cssText = self._tokensupto2(tokenizer, token)
if rule.wellformed:
seq.append(rule)
return expected
def atrule(expected, seq, token, tokenizer):
# TODO: get complete rule!
tokens = self._tokensupto2(tokenizer, token)
atval = self._tokenvalue(token)
if atval in ('@charset ', '@font-face', '@import',
'@namespace', '@page', '@media', '@variables'):
self._log.error(u'CSSMediaRule: This rule is not '
u'allowed in CSSMediaRule - ignored: '
u'%s.' % self._valuestr(tokens),
token = token,
error=xml.dom.HierarchyRequestErr)
else:
rule = cssutils.css.CSSUnknownRule(tokens,
parentRule=self,
parentStyleSheet=self.parentStyleSheet)
if rule.wellformed:
self.insertRule(rule)
return expected