Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def to_json():
def numeric(t):
return [
t.representation, t.value,
'integer' if t.int_value is not None else 'number']
return {
type(None): lambda _: None,
str: lambda s: s,
int: lambda s: s,
list: lambda l: [to_json(el) for el in l],
tuple: lambda l: [to_json(el) for el in l],
Encoding: lambda e: e.name,
ParseError: lambda e: ['error', e.kind],
Comment: lambda t: '/* … */',
WhitespaceToken: lambda t: ' ',
LiteralToken: lambda t: t.value,
IdentToken: lambda t: ['ident', t.value],
AtKeywordToken: lambda t: ['at-keyword', t.value],
HashToken: lambda t: ['hash', t.value,
'id' if t.is_identifier else 'unrestricted'],
StringToken: lambda t: ['string', t.value],
URLToken: lambda t: ['url', t.value],
NumberToken: lambda t: ['number'] + numeric(t),
PercentageToken: lambda t: ['percentage'] + numeric(t),
DimensionToken: lambda t: ['dimension'] + numeric(t) + [t.unit],
UnicodeRangeToken: lambda t: ['unicode-range', t.start, t.end],