Beispiel #1
0
def publish(topic, text):
    tid = next_id()
    return pb.ClientMsg(pub=pb.ClientPub(
        id=tid,
        topic=topic,
        no_echo=True,
        content=json.dumps(text, ensure_ascii=False).encode('utf-8')))
Beispiel #2
0
def msg_hi(mid):
    onCompletion[str(mid)] = lambda params: print_server_params(params)
    return pb.ClientMsg(hi=pb.ClientHi(id=str(mid),
                                       user_agent=APP_NAME + "/" + VERSION +
                                       " gRPC-python",
                                       ver=VERSION,
                                       lang="EN"))
Beispiel #3
0
def leave(topic):
    tid = next_id()
    onCompletion[tid] = {
        'arg': topic,
        'action': lambda topicName, unused: del_subscription(topicName)
    }
    return pb.ClientMsg(leave=pb.ClientLeave(id=tid, topic=topic))
Beispiel #4
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))
Beispiel #5
0
def hello():
    tid = next_id()
    return pb.ClientMsg(hi=pb.ClientHi(id=tid,
                                       user_agent=APP_NAME + "/" + VERSION +
                                       " gRPC-python",
                                       ver=VERSION,
                                       lang="EN"))
Beispiel #6
0
def msg_login(mid, scheme, secret, uname=None, password=None):
    if secret is None or secret == '' and uname is not None:
        if password is None:
            password = ''
        secret = str(uname) + ":" + str(password)
    onCompletion[str(mid)] = lambda params: save_cookie(params)
    return pb.ClientMsg(login=pb.ClientLogin(
        id=str(mid), scheme=scheme, secret=secret.encode('utf-8')))
Beispiel #7
0
def login(cookie_file_name, scheme, secret):
    tid = next_id()
    onCompletion[tid] = {
        'arg': cookie_file_name,
        'action': lambda fname, params: save_auth_cookie(fname, params),
    }
    return pb.ClientMsg(
        login=pb.ClientLogin(id=tid, scheme=scheme, secret=secret))
Beispiel #8
0
def msg_set(mid, topic, user, fn, photo, private, auth, anon, mode):
    return pb.ClientMsg(set=pb.ClientSet(
        id=str(mid),
        topic=topic,
        query=pb.SetQuery(desc=pb.SetDesc(default_acs=pb.DefaultAcsMode(
            auth=auth, anon=anon),
                                          public=make_vcard(fn, photo),
                                          private=private),
                          sub=pb.SetSub(user_id=user, mode=mode))))
Beispiel #9
0
def msg_get(mid, topic, desc, sub, data):
    what = []
    if desc:
        what.append("desc")
    if sub:
        what.append("sub")
    if data:
        what.append("data")
    return pb.ClientMsg(get=pb.ClientGet(
        id=str(mid), topic=topic, query=pb.GetQuery(what=" ".join(what))))
Beispiel #10
0
def msg_note(mid, topic, what, seq):
    enum_what = None
    if what == 'kp':
        enum_what = pb.KP
        seq = None
    elif what == 'read':
        enum_what = pb.READ
        seq = int(seq)
    elif what == 'recv':
        enum_what = pb.READ
        seq = int(seq)
    return pb.ClientMsg(
        note=pb.ClientNote(topic=topic, what=enum_what, seq_id=seq))
Beispiel #11
0
def msg_account(mid, user, scheme, secret, uname, password, do_login, tags, fn,
                photo, private, auth, anon):
    if secret is None and uname is not None:
        if password is None:
            password = ''
        secret = str(uname) + ":" + str(password)
    return pb.ClientMsg(acc=pb.ClientAcc(
        id=str(mid),
        user_id=user,
        scheme=scheme,
        secret=secret,
        login=do_login,
        tags=tags.split(",") if tags else None,
        desc=pb.SetDesc(default_acs=pb.DefaultAcsMode(auth=auth, anon=anon),
                        public=make_vcard(fn, photo),
                        private=private)))
Beispiel #12
0
def msg_delete(mid, topic, what, param, hard):
    if topic is None and param is not None:
        topic = param
        param = None

    print(mid, topic, what, param, hard)
    enum_what = None
    before = None
    seq_list = None
    user = None
    if what == 'msg':
        enum_what = pb.ClientDel.MSG
        if param == 'all':
            seq_list = [pb.DelQuery(range=pb.SeqRange(low=1, hi=0x8FFFFFF))]
        elif param is not None:
            seq_list = [
                pb.DelQuery(seq_id=int(x.strip())) for x in param.split(',')
            ]
        print(seq_list)

    elif what == 'sub':
        enum_what = pb.ClientDel.SUB
        user = param
    elif what == 'topic':
        enum_what = pb.ClientDel.TOPIC

    # Field named 'del' conflicts with the keyword 'del. This is a work around.
    msg = pb.ClientMsg()
    xdel = getattr(msg, 'del')
    """
    setattr(msg, 'del', pb.ClientDel(id=str(id), topic=topic, what=enum_what, hard=hard,
        del_seq=seq_list, user_id=user))
    """
    xdel.id = str(mid)
    xdel.topic = topic
    xdel.what = enum_what
    if hard is not None:
        xdel.hard = hard
    if seq_list is not None:
        xdel.del_seq.extend(seq_list)
    if user is not None:
        xdel.user_id = user
    return msg
Beispiel #13
0
def note_read(topic, seq):
    return pb.ClientMsg(
        note=pb.ClientNote(topic=topic, what=pb.READ, seq_id=seq))