def flush_data(address, taskname, data):
    if data:
        urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "data": json.dumps(data), "taskname": taskname})), timeout=10).read()
    return []

def fetch_output(address, taskname):
    val = urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "get_output", "taskname": taskname})), timeout=10).read()
    l, r = output.split("&", 1)
    if "value" in l:
        output = r
    else:
        output = l
    _, output = output.split("=", 1)
    return output

def send_to_mv(address, taskname, lst):
    data = []
    variables = {}

    for c in lst:
        if isinstance(c, int):
            data = flush_data(address, taskname, data)
            variables[c] = fetch_output(address, taskname)
        else:
            data.append(c)

    return variables
