예제 #1
0
def subscribe(topic):
    tid = next_id()
    onCompletion[tid] = {
        'arg': topic,
        'action': lambda topicName, unused: add_subscription(topicName),
    }
    return pb.ClientMsg(sub=pb.ClientSub(id=tid, topic=topic))
def subscribe(topic):
    tid = next_id()
    add_future(tid, {
        'arg': topic,
        'action': lambda topicName, unused: add_subscription(topicName),
    })
    return pb.ClientMsg(sub=pb.ClientSub(id=tid, topic=topic))
예제 #3
0
def serialize_cmd(string, id):
    """Take string read from the command line, convert in into a protobuf message"""

    # Convert string into a dictionary
    cmd = parse_cmd(string)
    if cmd == None:
        return None

    # Process dictionary
    if cmd.cmd == "acc":
        return accMsg(id, cmd.user, cmd.scheme, cmd.secret, cmd.uname, cmd.password,
            cmd.do_login, cmd.tags, cmd.fn, cmd.photo, cmd.private, cmd.auth, cmd.anon)
    elif cmd.cmd == "login":
        return loginMsg(id, cmd.scheme, cmd.secret, cmd.uname, cmd.password)
    elif cmd.cmd == "sub":
        return pb.ClientMsg(sub=pb.ClientSub(id=str(id), topic=cmd.topic))
    elif cmd.cmd == "leave":
        return pb.ClientMsg(leave=pb.ClientLeave(id=str(id), topic=cmd.topic))
    elif cmd.cmd == "pub":
        return pb.ClientMsg(pub=pb.ClientPub(id=str(id), topic=cmd.topic, no_echo=True,
            content=json.dumps(cmd.content)))
    elif cmd.cmd == "get":
        return getMsg(id, cmd.topic, cmd.desc, cmd.sub, cmd.data)
    elif cmd.cmd == "set":
        return setMsg(id, cmd.topic, cmd.user, cmd.fn, cmd.photo, cmd.private, cmd.auth, cmd.anon, cmd.mode)
    elif cmd.cmd == "del":
        return delMsg(id, cmd.topic, cmd.what, cmd.param, cmd.hard)
    elif cmd.cmd == "note":
        return noteMsg(id, cmd.topic, cmd.what, cmd.seq)
    else:
        print("Unrecognized: " + cmd.cmd)
        return None
def subscribe_v2(topic, tid):
    add_future(tid, {
        'arg': topic,
        'action': lambda topicName, unused: add_subscription(topicName),
    })
    A = pb.ClientMsg(sub=pb.ClientSub(id=tid, topic=topic))
    print(A)
    return A
예제 #5
0
def subMsg(id, topic, fn, photo, private, auth, anon, mode, tags, get_query):
    if get_query:
        get_query = pb.GetQuery(what=get_query.split(",").join(" "))
    public = encode_to_bytes(make_vcard(fn, photo))
    private = encode_to_bytes(private)
    return pb.ClientMsg(sub=pb.ClientSub(id=str(id), topic=topic,
        set_query=pb.SetQuery(
            desc=pb.SetDesc(public=public, private=private, default_acs=pb.DefaultAcsMode(auth=auth, anon=anon)),
            sub=pb.SetSub(mode=mode),
            tags=tags.split(",") if tags else None), get_query=get_query))