def bufconvert(fmt, nums):
    buf = io.BytesIO()
    bufstack = []
    fmt = str(fmt)
    while len(fmt) > 0:
        step, fmt = fmt[0], fmt[1:]
        if step == '{':
            bufstack.append(buf)
            buf = io.BytesIO()
            continue
        if step == '}':
            bufstack[-1].write(buf.getvalue())
            buf = bufstack.pop()
            continue
        if step == ':':
            # transform
            step, fmt = fmt[0], fmt[1:]
            buf = buftransform(buf, step)
            continue
        if step == '%':
            # urldecode
            step, fmt = fmt[0:2], fmt[2:]
            # print '%:', repr(step), 'remain:', repr(fmt)
            buf.write(chr(int(step, 16)))
            continue
        if step in ("'", '"'):
            step, fmt = fmt.split(step, 1)
            buf.write(step.encode('UTF-8'))
            continue

        try:
            step = out_ops[step]
        except __HOLE__:
            raise KeyError('Unsupported output format', step)

        step(buf, nums.pop(0))

    assert len(bufstack) == 0, 'Too many buffers on stack'

    return buf
dataset/ETHPy150Open blixt/py-starbound/sbon-numconv.py/bufconvert