#!/usr/bin/env python
from __future__ import print_function
import sys

# Copied from https://github.com/coderanger/supervisor-stdout/blob/master/setup.py

# See pymacaron_async.supervisor for the event handler

def main():
    while 1:
        write_stdout('READY\n') # transition from ACKNOWLEDGED to READY
        line = sys.stdin.readline()  # read header line from stdin
        headers = dict([ x.split(':') for x in line.split() ])
        data = sys.stdin.read(int(headers['len'])) # read the event payload
        write_stdout('RESULT %s\n%s'%(len(data), data)) # transition from READY to ACKNOWLEDGED

if __name__ == '__main__':
    main()
