from string import Template

TMP_NAME = '"${name}": '

TOK_ARRAY_BEGIN = '['
TOK_ARRAY_END = ']'
TOK_OBJECT_BEGIN = '{'
TOK_OBJECT_END = '}'
TOK_LEVEL = '    '
TOK_SEP = ','

VAL_STRING_DEFAULT = '""'
VAL_NUMBER_INT_DEFAULT = '0'
VAL_NUMBER_FLOAT_DEFAULT = '0.0'
VAL_BOOLEAN_DEFAULT = 'false'


def render_name(n):
    s = Template(TMP_NAME)
    d = dict(name=n)
    return s.safe_substitute(d)


def array_begin():
    return TOK_ARRAY_BEGIN


def array_end():
    return TOK_ARRAY_END


def object_begin():
    return TOK_OBJECT_BEGIN


def object_end():
    return TOK_OBJECT_END

# level starts from 1, use 'l - 1'.


def level(l):
    if l > 0:
        l -= 1
    return l * TOK_LEVEL


def sep():
    return TOK_SEP


def string_default_value():
    return VAL_STRING_DEFAULT


def int_default_value():
    return VAL_NUMBER_INT_DEFAULT


def float_default_value():
    return VAL_NUMBER_FLOAT_DEFAULT


def boolean_default_value():
    return VAL_BOOLEAN_DEFAULT
