Skip to content

Commit 21e0fa0

Browse files
author
Paul Sokolovsky
committed
webrepl_cli.py: Add symbolic names for WebREPL operations.
Also, better name request structure pattern.
1 parent cde822c commit 21e0fa0

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

webrepl_cli.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
1616
#SANDBOX = "/tmp/webrepl/"
1717
DEBUG = 0
1818

19-
WEBREPL_FILE = "<2sBBQLH64s"
20-
19+
WEBREPL_REQ_S = "<2sBBQLH64s"
20+
WEBREPL_PUT_FILE = 1
21+
WEBREPL_GET_FILE = 2
2122

2223
def debugmsg(msg):
2324
if DEBUG:
@@ -102,7 +103,7 @@ def read_resp(ws):
102103
def put_file(ws, local_file, remote_file):
103104
sz = os.stat(local_file)[6]
104105
dest_fname = (SANDBOX + remote_file).encode("utf-8")
105-
rec = struct.pack(WEBREPL_FILE, b"WA", 1, 0, 0, sz, len(dest_fname), dest_fname)
106+
rec = struct.pack(WEBREPL_REQ_S, b"WA", WEBREPL_PUT_FILE, 0, 0, sz, len(dest_fname), dest_fname)
106107
debugmsg("%r %d" % (rec, len(rec)))
107108
ws.write(rec[:10])
108109
ws.write(rec[10:])
@@ -122,7 +123,7 @@ def put_file(ws, local_file, remote_file):
122123

123124
def get_file(ws, local_file, remote_file):
124125
src_fname = (SANDBOX + remote_file).encode("utf-8")
125-
rec = struct.pack(WEBREPL_FILE, b"WA", 2, 0, 0, 0, len(src_fname), src_fname)
126+
rec = struct.pack(WEBREPL_REQ_S, b"WA", WEBREPL_GET_FILE, 0, 0, 0, len(src_fname), src_fname)
126127
debugmsg("%r %d" % (rec, len(rec)))
127128
ws.write(rec)
128129
assert read_resp(ws) == 0

0 commit comments

Comments
 (0)