MCPcopy
hub / github.com/tinode/chat / serialize_cmd

Function serialize_cmd

tn-cli/commands.py:702–792  ·  view source on GitHub ↗

Take string read from the command line, convert in into a protobuf message

(string, id, args)

Source from the content-addressed store, hash-verified

700# Process command-line input string: execute local commands, generate
701# protobuf messages for remote commands.
702def serialize_cmd(string, id, args):
703 """Take string read from the command line, convert in into a protobuf message"""
704 global DELETE_MARKER
705
706 messages = {
707 "acc": accMsg,
708 "login": loginMsg,
709 "sub": subMsg,
710 "leave": leaveMsg,
711 "pub": pubMsg,
712 "get": getMsg,
713 "set": setMsg,
714 "del": delMsg,
715 "note": noteMsg,
716 }
717 try:
718 # Convert string into a dictionary
719 cmd = parse_input(string)
720 if cmd == None:
721 return None, None
722
723 elif cmd.cmd == "file":
724 # Start async upload
725 target = fileUpload if cmd.what == 'up' else fileDownload
726 upload_thread = threading.Thread(target=target, args=(id, derefVals(cmd), args), name="file_"+cmd.filename)
727 upload_thread.start()
728 cmd.no_yield = True
729 return True, cmd
730
731 # Process dictionary
732 elif cmd.cmd == ".log":
733 stdoutln(getVar(cmd.varname))
734 return None, None
735
736 elif cmd.cmd == ".use":
737 if cmd.user != "unchanged":
738 if cmd.user:
739 if len(cmd.user) > 3 and cmd.user.startswith("usr"):
740 tn_globals.DefaultUser = cmd.user
741 else:
742 stdoutln("Error: user ID '{}' is invalid".format(cmd.user))
743 else:
744 tn_globals.DefaultUser = None
745 stdoutln("Default user='{}'".format(tn_globals.DefaultUser))
746
747 if cmd.topic != "unchanged":
748 if cmd.topic:
749 if cmd.topic[:3] in ['me', 'fnd', 'sys', 'usr', 'grp', 'chn']:
750 tn_globals.DefaultTopic = cmd.topic
751 else:
752 stdoutln("Error: topic '{}' is invalid".format(cmd.topic))
753 else:
754 tn_globals.DefaultTopic = None
755 stdoutln("Default topic='{}'".format(tn_globals.DefaultTopic))
756
757 return None, None
758
759 elif cmd.cmd == ".sleep":

Callers 1

gen_messageFunction · 0.90

Calls 6

stdoutlnFunction · 0.90
parse_inputFunction · 0.85
derefValsFunction · 0.85
getVarFunction · 0.85
startMethod · 0.80
runMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…