Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
started = False
stopall = False
prod = None
# flag if default S handling should be done
defaultS = True
while True:
try:
token = tokens.next()
except StopIteration:
break
type_, val, line, col = token
# default productions
if type_ == self.types.COMMENT:
# always append COMMENT
seq.append(cssutils.css.CSSComment(val),
cssutils.css.CSSComment, line, col)
elif defaultS and type_ == self.types.S:
# append S (but ignore starting ones)
if not keepS or not started:
continue
else:
seq.append(val, type_, line, col)
# elif type_ == self.types.ATKEYWORD:
# # @rule
# r = cssutils.css.CSSUnknownRule(cssText=val)
# seq.append(r, type(r), line, col)
elif type_ == self.types.INVALID:
# invalidate parse
wellformed = False
self._log.error(u'Invalid token: %r' % (token,))
break
if self.prefs.keepAllProperties:
# all
seq = style.seq
else:
# only effective ones
_effective = style.getProperties()
seq = [item for item in style.seq
if (isinstance(item.value, cssutils.css.Property)
and item.value in _effective)
or not isinstance(item.value, cssutils.css.Property)]
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
if val.cssText:
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:
# 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 do_css_CSSFunction(self, cssvalue, valuesOnly=False):
"""Serialize a CSS function value"""
if not cssvalue:
return u''
else:
out = Out(self)
for item in cssvalue.seq:
type_, val = item.type, item.value
if valuesOnly and type_ == cssutils.css.CSSComment:
continue
out.append(val, type_)
return out.value()
def COMMENT(expected, seq, token, tokenizer=None):
"special: sets parent*"
self.insertRule(cssutils.css.CSSComment([token],
parentStyleSheet=self))
# or 0 for py3
return max(1, expected or 0)
def COMMENT(expected, seq, token, tokenizer=None):
"default impl, adds CSSCommentRule if not token == EOF"
if expected == 'EOF':
new['wellformed'] = False
self._log.error(u'Expected EOF but found comment.', token=token)
seq.append(cssutils.css.CSSComment([token]), 'COMMENT')
return expected
def COMMENT(expected, seq, token, tokenizer=None):
"special: sets parent*"
comment = cssutils.css.CSSComment([token],
parentStyleSheet=self.parentStyleSheet)
seq.append(comment)
return expected
# while no real token is found any S are ignored
started = False
prod = None
# flag if default S handling should be done
defaultS = True
while True:
try:
token = tokens.next()
except StopIteration:
break
type_, val, line, col = token
# default productions
if type_ == self.types.COMMENT:
# always append COMMENT
seq.append(cssutils.css.CSSComment(val),
cssutils.css.CSSComment, line, col)
elif defaultS and type_ == self.types.S:
# append S (but ignore starting ones)
if not keepS or not started:
continue
else:
seq.append(val, type_, line, col)
# elif type_ == self.types.ATKEYWORD:
# # @rule
# r = cssutils.css.CSSUnknownRule(cssText=val)
# seq.append(r, type(r), line, col)
elif type_ == self.types.INVALID:
# invalidate parse
wellformed = False
self._log.error(u'Invalid token: %r' % (token,))
break
def COMMENT(expected, seq, token, tokenizer=None):
seq.append(cssutils.css.CSSComment([token]))
return expected