from uuid import UUID
from scanner import Symbol

def tostr(value):
    if isinstance(value, Symbol):
        return str(value)
    elif isinstance(value, str):
        return '"%s"' % value
    elif isinstance(value, float):
        return '%.14f' % value
    elif isinstance(value, UUID):
        return '{%s}' % str(value).upper()
    elif value is None:
        return '-'
    else:
        return str(value)

def encode(lists, indent=2, level=0):
    if indent == 0:
        raise ValueError('Indent should be present')
    result = '<'
    for i, item in enumerate(lists):
        if not isinstance(item, list):
            raise TypeError('%r is not RPP serializable' % item)
        if i > 0:
            result += ' ' * (level + 1) * indent
        if all(not isinstance(x, list) for x in item):
            name, values = item[0].upper(), item[1:]
            strvalues = map(tostr, values)
            result += ' '.join([name] + strvalues)
        else:
            result += encode(item, level=(level + 1))
        result += '\n' if indent else ' '
    result += (' ' * level * indent) + '>'
    return result

from uuid import UUID
from scanner import Symbol

def tostr(value):
    if isinstance(value, Symbol):
        return str(value)
    elif isinstance(value, str):
        return '"%s"' % value
    elif isinstance(value, float):
        return '%.14f' % value
    elif isinstance(value, UUID):
        return '{%s}' % str(value).upper()
    elif value is None:
        return '-'
    else:
        return str(value)

def encode(lists, indent=2, level=0):
    if indent == 0:
        raise ValueError('Indent should be present')
    result = '<'
    for i, item in enumerate(lists):
        if not isinstance(item, list):
            raise TypeError('%r is not RPP serializable' % item)
        if i > 0:
            result += ' ' * (level + 1) * indent
        if all(not isinstance(x, list) for x in item):
            name, values = item[0].upper(), item[1:]
            strvalues = map(tostr, values)
            result += name
            for value, strvalue in zip(values, strvalues):
                if isinstance(value, Symbol):
                    result += '\n' + (' ' * (level + 1) * indent) + strvalue
                else:
                    result += ' ' + strvalue
        else:
            result += encode(item, level=(level + 1))
        result += '\n' if indent else ' '
    result += (' ' * level * indent) + '>'
    return result

Insert new line for each Symbol object