Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_is_variable(self):
test = utility.is_variable
self.assertTrue(test('@var'))
self.assertTrue(test('-@var'))
self.assertFalse(test('var'))
self.assertFalse(test(''))
self.assertFalse(test(False))
self.assertFalse(test([]))
def replace_variables(tokens, scope):
return [
scope.swap(t)
if (utility.is_variable(t) and not t in reserved.tokens) else t
for t in tokens
]
def p_media_query_value(self, p):
""" media_query_value : number
| variable
| word
| color
| expression
"""
if utility.is_variable(p[1]):
var = self.scope.variables(''.join(p[1]))
if var:
value = var.value[0]
if hasattr(value, 'parse'):
p[1] = value.parse(self.scope)
else:
p[1] = value
if isinstance(p[1], Expression):
p[0] = p[1].parse(self.scope)
else:
p[0] = p[1]
Variable object or None
"""
if isinstance(var, Variable):
# kwarg
if arg:
if utility.is_variable(arg[0]):
tmp = scope.variables(arg[0])
if not tmp:
return None
val = tmp.value
else:
val = arg
var = Variable(var.tokens[:-1] + [val])
else:
# arg
if utility.is_variable(var):
if arg is None:
raise SyntaxError('Missing argument to mixin')
elif utility.is_variable(arg[0]):
tmp = scope.variables(arg[0])
if not tmp:
return None
val = tmp.value
else:
val = arg
var = Variable([var, None, val])
else:
return None
return var
def _parse_arg(self, var, arg, scope):
""" Parse a single argument to mixin.
args:
var (Variable object): variable
arg (mixed): argument
scope (Scope object): current scope
returns:
Variable object or None
"""
if isinstance(var, Variable):
# kwarg
if arg:
if utility.is_variable(arg[0]):
tmp = scope.variables(arg[0])
if not tmp:
return None
val = tmp.value
else:
val = arg
var = Variable(var.tokens[:-1] + [val])
else:
# arg
if utility.is_variable(var):
if arg is None:
raise SyntaxError('Missing argument to mixin')
elif utility.is_variable(arg[0]):
tmp = scope.variables(arg[0])
if not tmp:
return None
# kwarg
if arg:
if utility.is_variable(arg[0]):
tmp = scope.variables(arg[0])
if not tmp:
return None
val = tmp.value
else:
val = arg
var = Variable(var.tokens[:-1] + [val])
else:
# arg
if utility.is_variable(var):
if arg is None:
raise SyntaxError('Missing argument to mixin')
elif utility.is_variable(arg[0]):
tmp = scope.variables(arg[0])
if not tmp:
return None
val = tmp.value
else:
val = arg
var = Variable([var, None, val])
else:
return None
return var
def replace_vars(self, tokens):
"""
Replace variables in tokenlist
"""
return [self.swap(t)
if utility.is_variable(t)
else t
for t in tokens]