Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
% (variableName, value))
else:
# check value
if isinstance(value, PropertyValue):
v = value
else:
v = PropertyValue(cssText=value, parent=self)
if not v.wellformed:
self._log.error(u'Invalid variable value: %r: %r'
% (variableName, value))
else:
# update seq
self.seq._readonly = False
variableName = normalize(variableName)
if variableName in self._vars:
for i, x in enumerate(self.seq):
if x.value[0] == variableName:
self.seq.replace(i,
[variableName, v],
x.type,
x.line,
x.col)
break
else:
self.seq.append([variableName, v], 'var')
self.seq._readonly = True
self._vars[variableName] = v
def _getNumDim(self, value=None):
"Split self._value in numerical and dimension part."
if value is None:
value = cssutils.helper.normalize(self._value[0])
try:
val, dim = CSSPrimitiveValue._reNumDim.findall(value)[0]
except IndexError:
val, dim = value, u''
try:
val = float(val)
if val == int(val):
val = int(val)
except ValueError:
raise xml.dom.InvalidAccessErr(
u'CSSPrimitiveValue: No float value %r' % self._value[0])
return val, dim
toSeq=lambda t, tokens: (t[0], cssutils.helper.normalize(t[1]))),
Choice(Sequence(PreDef.unary(),
def _getNumDim(self, value=None):
"Split self._value in numerical and dimension part."
if value is None:
value = cssutils.helper.normalize(self._value[0])
try:
val, dim = CSSPrimitiveValue._reNumDim.findall(value)[0]
except IndexError:
val, dim = value, u''
try:
val = float(val)
if val == int(val):
val = int(val)
except ValueError:
raise xml.dom.InvalidAccessErr(
u'CSSPrimitiveValue: No float value %r' % self._value[0])
return val, dim
def _unitFUNCTION(value):
"""Check val for function name."""
units = {'attr(': 'CSS_ATTR',
'counter(': 'CSS_COUNTER',
'rect(': 'CSS_RECT',
'rgb(': 'CSS_RGBCOLOR',
'rgba(': 'CSS_RGBACOLOR',
}
return units.get(re.findall(ur'^(.*?\()',
cssutils.helper.normalize(value.cssText),
re.U)[0],
'CSS_UNKNOWN')
def _unitDIMENSION(value):
"""Check val for dimension name."""
units = {'em': 'CSS_EMS', 'ex': 'CSS_EXS',
'px': 'CSS_PX',
'cm': 'CSS_CM', 'mm': 'CSS_MM',
'in': 'CSS_IN',
'pt': 'CSS_PT', 'pc': 'CSS_PC',
'deg': 'CSS_DEG', 'rad': 'CSS_RAD', 'grad': 'CSS_GRAD',
'ms': 'CSS_MS', 's': 'CSS_S',
'hz': 'CSS_HZ', 'khz': 'CSS_KHZ'
}
val, dim = CSSPrimitiveValue._reNumDim.findall(cssutils.helper.normalize(value))[0]
return units.get(dim, 'CSS_DIMENSION')
def _unitFUNCTION(value):
"""Check val for function name."""
units = {'attr(': 'CSS_ATTR',
'counter(': 'CSS_COUNTER',
'rect(': 'CSS_RECT',
'rgb(': 'CSS_RGBCOLOR',
'rgba(': 'CSS_RGBACOLOR',
}
return units.get(re.findall(ur'^(.*?\()',
cssutils.helper.normalize(value.cssText),
re.U)[0],
'CSS_UNKNOWN')
:param value:
The new value of the variable, may also be a PropertyValue object.
:exceptions:
- :exc:`~xml.dom.SyntaxErr`:
Raised if the specified value has a syntax error and is
unparsable.
- :exc:`~xml.dom.NoModificationAllowedErr`:
Raised if this declaration is readonly or the property is
readonly.
"""
self._checkReadonly()
# check name
wellformed, seq, store, unused = \
ProdParser().parse(normalize(variableName),
u'variableName',
Sequence(PreDef.ident()))
if not wellformed:
self._log.error(u'Invalid variableName: %r: %r'
% (variableName, value))
else:
# check value
if isinstance(value, PropertyValue):
v = value
else:
v = PropertyValue(cssText=value, parent=self)
if not v.wellformed:
self._log.error(u'Invalid variable value: %r: %r'
% (variableName, value))
else:
def __contains__(self, variableName):
"""Check if a variable is in variable declaration block.
:param variableName:
a string
"""
return normalize(variableName) in self.keys()