aboutsummaryrefslogblamecommitdiff
path: root/external/dummy.py
blob: 2dc47ba95a8d1920b7492ad904a6b66a9eae7120 (plain) (tree)





































                                                                  
#!/usr/bin/env python3

import sys
import json

sys.stderr.write("(python) dummy starting")
sys.stderr.flush()

if __name__ == "__main__":
    username = ""
    while True:
        line = sys.stdin.readline()
        sys.stderr.write("(python) got: {}\n".format(line))
        sys.stderr.flush()

        cmd = json.loads(line)

        reply = {
            "_type": "rep_ok",
            "_id": cmd["_id"],
        }

        if cmd["_type"] == "configure":
            username = cmd["data"]["user"]
        if cmd["_type"]  == "get_user":
            reply["user"] = username

        repline = json.dumps(reply)
        sys.stderr.write("(python) sending: {}\n".format(repline))
        sys.stderr.flush()
        sys.stdout.write(repline + "\n")
        sys.stdout.flush()

        if cmd["_type"] == "close":
            break

sys.stderr.write("(python) dummy stopping")
sys.stderr.flush()