ยปCore Development>Code coverage>Tools/demo/rpython.py

Python code coverage for Tools/demo/rpython.py

#countcontent
1n/a#!/usr/bin/env python3
2n/a
3n/a"""
4n/aRemote python client.
5n/aExecute Python commands remotely and send output back.
6n/a"""
7n/a
8n/aimport sys
9n/afrom socket import socket, AF_INET, SOCK_STREAM, SHUT_WR
10n/a
11n/aPORT = 4127
12n/aBUFSIZE = 1024
13n/a
14n/adef main():
15n/a if len(sys.argv) < 3:
16n/a print("usage: rpython host command")
17n/a sys.exit(2)
18n/a host = sys.argv[1]
19n/a port = PORT
20n/a i = host.find(':')
21n/a if i >= 0:
22n/a port = int(port[i+1:])
23n/a host = host[:i]
24n/a command = ' '.join(sys.argv[2:])
25n/a s = socket(AF_INET, SOCK_STREAM)
26n/a s.connect((host, port))
27n/a s.send(command.encode())
28n/a s.shutdown(SHUT_WR)
29n/a reply = b''
30n/a while True:
31n/a data = s.recv(BUFSIZE)
32n/a if not data:
33n/a break
34n/a reply += data
35n/a print(reply.decode(), end=' ')
36n/a s.close()
37n/a
38n/amain()