Send a debug command and get response.
(sock, cmd: str, session_id: str = None, timeout: float = 60)
| 108 | |
| 109 | |
| 110 | def send_debug_cmd(sock, cmd: str, session_id: str = None, timeout: float = 60) -> tuple: |
| 111 | """Send a debug command and get response.""" |
| 112 | req = {"type": "debug_command", "id": 1, "command": cmd} |
| 113 | if session_id: |
| 114 | req["session_id"] = session_id |
| 115 | |
| 116 | sock.send((json.dumps(req) + '\n').encode()) |
| 117 | sock.settimeout(timeout) |
| 118 | |
| 119 | data = b"" |
| 120 | while True: |
| 121 | chunk = sock.recv(65536) |
| 122 | if not chunk: |
| 123 | break |
| 124 | data += chunk |
| 125 | if b'\n' in data: |
| 126 | break |
| 127 | |
| 128 | resp = json.loads(data.decode().strip()) |
| 129 | return resp.get('ok', False), resp.get('output', ''), resp.get('error', '') |
| 130 | |
| 131 | |
| 132 | def run_jcode_oauth(prompt: str) -> dict: |