Client message generator: reads user input as string, converts to pb.ClientMsg, and yields
(scheme, secret, args)
| 91 | |
| 92 | # Generator of protobuf messages. |
| 93 | def gen_message(scheme, secret, args): |
| 94 | """Client message generator: reads user input as string, |
| 95 | converts to pb.ClientMsg, and yields""" |
| 96 | import random |
| 97 | import threading |
| 98 | from input_handler import stdin |
| 99 | from commands import hiMsg, loginMsg, serialize_cmd |
| 100 | |
| 101 | random.seed() |
| 102 | id = random.randint(10000,60000) |
| 103 | |
| 104 | # Asynchronous input-output |
| 105 | tn_globals.InputThread = threading.Thread(target=stdin, args=(tn_globals.InputQueue,)) |
| 106 | tn_globals.InputThread.daemon = True |
| 107 | tn_globals.InputThread.start() |
| 108 | |
| 109 | try: |
| 110 | from importlib.metadata import version |
| 111 | except ImportError: |
| 112 | from importlib_metadata import version |
| 113 | import platform |
| 114 | |
| 115 | APP_NAME = "tn-cli" |
| 116 | APP_VERSION = "3.0.1" |
| 117 | LIB_VERSION = version("tinode_grpc") |
| 118 | GRPC_VERSION = version("grpcio") |
| 119 | |
| 120 | user_agent = APP_NAME + "/" + APP_VERSION + " (" + \ |
| 121 | platform.system() + "/" + platform.release() + "); gRPC-python/" + LIB_VERSION + "+" + GRPC_VERSION |
| 122 | |
| 123 | msg = hiMsg(id, args.background, user_agent, LIB_VERSION) |
| 124 | if tn_globals.Verbose: |
| 125 | stdoutln("\r=> " + to_json(msg)) |
| 126 | yield msg |
| 127 | |
| 128 | if scheme != None: |
| 129 | id += 1 |
| 130 | login = lambda:None |
| 131 | setattr(login, 'scheme', scheme) |
| 132 | setattr(login, 'secret', secret) |
| 133 | setattr(login, 'cred', None) |
| 134 | msg = loginMsg(id, login, args) |
| 135 | if tn_globals.Verbose: |
| 136 | stdoutln("\r=> " + to_json(msg)) |
| 137 | yield msg |
| 138 | |
| 139 | print_prompt = True |
| 140 | |
| 141 | while True: |
| 142 | try: |
| 143 | if not tn_globals.WaitingFor and tn_globals.InputQueue: |
| 144 | id += 1 |
| 145 | inp = tn_globals.InputQueue.popleft() |
| 146 | |
| 147 | if inp == 'exit' or inp == 'quit' or inp == '.exit' or inp == '.quit': |
| 148 | # Drain the output queue. |
| 149 | while pop_from_output_queue(): |
| 150 | pass |
no test coverage detected
searching dependent graphs…