annotate src/testdir/test_channel.py @ 8798:176647a751d7 v7.4.1687

commit https://github.com/vim/vim/commit/bdf0bda968a53a55149a4c83a10a60c28e431305 Author: Bram Moolenaar <Bram@vim.org> Date: Wed Mar 30 21:06:57 2016 +0200 patch 7.4.1687 Problem: The channel close_cb option does not work. Solution: Use jo_close_partial instead of jo_err_partial. (Damien)
author Christian Brabandt <cb@256bit.org>
date Wed, 30 Mar 2016 22:15:10 +0200
parents 4c38a4733578
children 176e34b0d678
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1 #!/usr/bin/python
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2 #
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3 # Server that will accept connections from a Vim channel.
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
4 # Used by test_channel.vim.
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5 #
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6 # This requires Python 2.6 or later.
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
7
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
8 from __future__ import print_function
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
9 import json
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
10 import socket
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
11 import sys
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
12 import time
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
13 import threading
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
14
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
15 try:
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
16 # Python 3
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
17 import socketserver
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
18 except ImportError:
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
19 # Python 2
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
20 import SocketServer as socketserver
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
21
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
22 class ThreadedTCPRequestHandler(socketserver.BaseRequestHandler):
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
23
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
24 def handle(self):
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
25 print("=== socket opened ===")
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
26 while True:
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
27 try:
7914
35973ce58c84 commit https://github.com/vim/vim/commit/608a8919cae982cb38e38725a843df47b234dae6
Christian Brabandt <cb@256bit.org>
parents: 7912
diff changeset
28 received = self.request.recv(4096).decode('utf-8')
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
29 except socket.error:
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
30 print("=== socket error ===")
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
31 break
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
32 except IOError:
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
33 print("=== socket closed ===")
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
34 break
7914
35973ce58c84 commit https://github.com/vim/vim/commit/608a8919cae982cb38e38725a843df47b234dae6
Christian Brabandt <cb@256bit.org>
parents: 7912
diff changeset
35 if received == '':
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
36 print("=== socket closed ===")
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
37 break
8663
b2a48aabe21f commit https://github.com/vim/vim/commit/a63cdb5ed685181c377ee89f1d1de6a97dfeb151
Christian Brabandt <cb@256bit.org>
parents: 8655
diff changeset
38 print("received: {0}".format(received))
7912
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
39
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
40 # We may receive two messages at once. Take the part up to the
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
41 # matching "]" (recognized by finding "][").
7914
35973ce58c84 commit https://github.com/vim/vim/commit/608a8919cae982cb38e38725a843df47b234dae6
Christian Brabandt <cb@256bit.org>
parents: 7912
diff changeset
42 todo = received
35973ce58c84 commit https://github.com/vim/vim/commit/608a8919cae982cb38e38725a843df47b234dae6
Christian Brabandt <cb@256bit.org>
parents: 7912
diff changeset
43 while todo != '':
35973ce58c84 commit https://github.com/vim/vim/commit/608a8919cae982cb38e38725a843df47b234dae6
Christian Brabandt <cb@256bit.org>
parents: 7912
diff changeset
44 splitidx = todo.find('][')
7912
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
45 if splitidx < 0:
7914
35973ce58c84 commit https://github.com/vim/vim/commit/608a8919cae982cb38e38725a843df47b234dae6
Christian Brabandt <cb@256bit.org>
parents: 7912
diff changeset
46 used = todo
35973ce58c84 commit https://github.com/vim/vim/commit/608a8919cae982cb38e38725a843df47b234dae6
Christian Brabandt <cb@256bit.org>
parents: 7912
diff changeset
47 todo = ''
7912
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
48 else:
7914
35973ce58c84 commit https://github.com/vim/vim/commit/608a8919cae982cb38e38725a843df47b234dae6
Christian Brabandt <cb@256bit.org>
parents: 7912
diff changeset
49 used = todo[:splitidx + 1]
35973ce58c84 commit https://github.com/vim/vim/commit/608a8919cae982cb38e38725a843df47b234dae6
Christian Brabandt <cb@256bit.org>
parents: 7912
diff changeset
50 todo = todo[splitidx + 1:]
35973ce58c84 commit https://github.com/vim/vim/commit/608a8919cae982cb38e38725a843df47b234dae6
Christian Brabandt <cb@256bit.org>
parents: 7912
diff changeset
51 if used != received:
8663
b2a48aabe21f commit https://github.com/vim/vim/commit/a63cdb5ed685181c377ee89f1d1de6a97dfeb151
Christian Brabandt <cb@256bit.org>
parents: 8655
diff changeset
52 print("using: {0}".format(used))
7912
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
53
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
54 try:
7914
35973ce58c84 commit https://github.com/vim/vim/commit/608a8919cae982cb38e38725a843df47b234dae6
Christian Brabandt <cb@256bit.org>
parents: 7912
diff changeset
55 decoded = json.loads(used)
7912
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
56 except ValueError:
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
57 print("json decoding failed")
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
58 decoded = [-1, '']
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
59
7912
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
60 # Send a response if the sequence number is positive.
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
61 if decoded[0] >= 0:
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
62 if decoded[1] == 'hello!':
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
63 # simply send back a string
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
64 response = "got it"
8382
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8210
diff changeset
65 elif decoded[1].startswith("echo "):
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8210
diff changeset
66 # send back the argument
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8210
diff changeset
67 response = decoded[1][5:]
7912
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
68 elif decoded[1] == 'make change':
7918
ce5a7a613867 commit https://github.com/vim/vim/commit/66624ff0d9e1de2fc5eb4f95f3a3a2ed70b10138
Christian Brabandt <cb@256bit.org>
parents: 7916
diff changeset
69 # Send two ex commands at the same time, before
ce5a7a613867 commit https://github.com/vim/vim/commit/66624ff0d9e1de2fc5eb4f95f3a3a2ed70b10138
Christian Brabandt <cb@256bit.org>
parents: 7916
diff changeset
70 # replying to the request.
7912
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
71 cmd = '["ex","call append(\\"$\\",\\"added1\\")"]'
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
72 cmd += '["ex","call append(\\"$\\",\\"added2\\")"]'
8663
b2a48aabe21f commit https://github.com/vim/vim/commit/a63cdb5ed685181c377ee89f1d1de6a97dfeb151
Christian Brabandt <cb@256bit.org>
parents: 8655
diff changeset
73 print("sending: {0}".format(cmd))
7916
54602dcac207 commit https://github.com/vim/vim/commit/3b05b135e3ee4cfd59983fd63461e8f7642c1713
Christian Brabandt <cb@256bit.org>
parents: 7914
diff changeset
74 self.request.sendall(cmd.encode('utf-8'))
7912
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
75 response = "ok"
8746
4c38a4733578 commit https://github.com/vim/vim/commit/c4dcd60c76666bf113719f929709ad6120eb6528
Christian Brabandt <cb@256bit.org>
parents: 8744
diff changeset
76 elif decoded[1] == 'bad command':
4c38a4733578 commit https://github.com/vim/vim/commit/c4dcd60c76666bf113719f929709ad6120eb6528
Christian Brabandt <cb@256bit.org>
parents: 8744
diff changeset
77 cmd = '["ex","foo bar"]'
4c38a4733578 commit https://github.com/vim/vim/commit/c4dcd60c76666bf113719f929709ad6120eb6528
Christian Brabandt <cb@256bit.org>
parents: 8744
diff changeset
78 print("sending: {0}".format(cmd))
4c38a4733578 commit https://github.com/vim/vim/commit/c4dcd60c76666bf113719f929709ad6120eb6528
Christian Brabandt <cb@256bit.org>
parents: 8744
diff changeset
79 self.request.sendall(cmd.encode('utf-8'))
4c38a4733578 commit https://github.com/vim/vim/commit/c4dcd60c76666bf113719f929709ad6120eb6528
Christian Brabandt <cb@256bit.org>
parents: 8744
diff changeset
80 response = "ok"
7939
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
81 elif decoded[1] == 'do normal':
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
82 # Send a normal command.
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
83 cmd = '["normal","G$s more\u001b"]'
8663
b2a48aabe21f commit https://github.com/vim/vim/commit/a63cdb5ed685181c377ee89f1d1de6a97dfeb151
Christian Brabandt <cb@256bit.org>
parents: 8655
diff changeset
84 print("sending: {0}".format(cmd))
7939
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
85 self.request.sendall(cmd.encode('utf-8'))
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
86 response = "ok"
7912
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
87 elif decoded[1] == 'eval-works':
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
88 # Send an eval request. We ignore the response.
8159
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8153
diff changeset
89 cmd = '["expr","\\"foo\\" . 123", -1]'
8663
b2a48aabe21f commit https://github.com/vim/vim/commit/a63cdb5ed685181c377ee89f1d1de6a97dfeb151
Christian Brabandt <cb@256bit.org>
parents: 8655
diff changeset
90 print("sending: {0}".format(cmd))
7916
54602dcac207 commit https://github.com/vim/vim/commit/3b05b135e3ee4cfd59983fd63461e8f7642c1713
Christian Brabandt <cb@256bit.org>
parents: 7914
diff changeset
91 self.request.sendall(cmd.encode('utf-8'))
7912
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
92 response = "ok"
8744
ff9973bbbfcb commit https://github.com/vim/vim/commit/fa8b2e173dd5f6c4a5cfd326abdcf68b8eebf90d
Christian Brabandt <cb@256bit.org>
parents: 8663
diff changeset
93 elif decoded[1] == 'eval-special':
ff9973bbbfcb commit https://github.com/vim/vim/commit/fa8b2e173dd5f6c4a5cfd326abdcf68b8eebf90d
Christian Brabandt <cb@256bit.org>
parents: 8663
diff changeset
94 # Send an eval request. We ignore the response.
ff9973bbbfcb commit https://github.com/vim/vim/commit/fa8b2e173dd5f6c4a5cfd326abdcf68b8eebf90d
Christian Brabandt <cb@256bit.org>
parents: 8663
diff changeset
95 cmd = '["expr","\\"foo\x7f\x10\x01bar\\"", -2]'
ff9973bbbfcb commit https://github.com/vim/vim/commit/fa8b2e173dd5f6c4a5cfd326abdcf68b8eebf90d
Christian Brabandt <cb@256bit.org>
parents: 8663
diff changeset
96 print("sending: {0}".format(cmd))
ff9973bbbfcb commit https://github.com/vim/vim/commit/fa8b2e173dd5f6c4a5cfd326abdcf68b8eebf90d
Christian Brabandt <cb@256bit.org>
parents: 8663
diff changeset
97 self.request.sendall(cmd.encode('utf-8'))
ff9973bbbfcb commit https://github.com/vim/vim/commit/fa8b2e173dd5f6c4a5cfd326abdcf68b8eebf90d
Christian Brabandt <cb@256bit.org>
parents: 8663
diff changeset
98 response = "ok"
ff9973bbbfcb commit https://github.com/vim/vim/commit/fa8b2e173dd5f6c4a5cfd326abdcf68b8eebf90d
Christian Brabandt <cb@256bit.org>
parents: 8663
diff changeset
99 elif decoded[1] == 'eval-getline':
ff9973bbbfcb commit https://github.com/vim/vim/commit/fa8b2e173dd5f6c4a5cfd326abdcf68b8eebf90d
Christian Brabandt <cb@256bit.org>
parents: 8663
diff changeset
100 # Send an eval request. We ignore the response.
ff9973bbbfcb commit https://github.com/vim/vim/commit/fa8b2e173dd5f6c4a5cfd326abdcf68b8eebf90d
Christian Brabandt <cb@256bit.org>
parents: 8663
diff changeset
101 cmd = '["expr","getline(3)", -3]'
ff9973bbbfcb commit https://github.com/vim/vim/commit/fa8b2e173dd5f6c4a5cfd326abdcf68b8eebf90d
Christian Brabandt <cb@256bit.org>
parents: 8663
diff changeset
102 print("sending: {0}".format(cmd))
ff9973bbbfcb commit https://github.com/vim/vim/commit/fa8b2e173dd5f6c4a5cfd326abdcf68b8eebf90d
Christian Brabandt <cb@256bit.org>
parents: 8663
diff changeset
103 self.request.sendall(cmd.encode('utf-8'))
ff9973bbbfcb commit https://github.com/vim/vim/commit/fa8b2e173dd5f6c4a5cfd326abdcf68b8eebf90d
Christian Brabandt <cb@256bit.org>
parents: 8663
diff changeset
104 response = "ok"
7912
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
105 elif decoded[1] == 'eval-fails':
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
106 # Send an eval request that will fail.
8744
ff9973bbbfcb commit https://github.com/vim/vim/commit/fa8b2e173dd5f6c4a5cfd326abdcf68b8eebf90d
Christian Brabandt <cb@256bit.org>
parents: 8663
diff changeset
107 cmd = '["expr","xxx", -4]'
8663
b2a48aabe21f commit https://github.com/vim/vim/commit/a63cdb5ed685181c377ee89f1d1de6a97dfeb151
Christian Brabandt <cb@256bit.org>
parents: 8655
diff changeset
108 print("sending: {0}".format(cmd))
7916
54602dcac207 commit https://github.com/vim/vim/commit/3b05b135e3ee4cfd59983fd63461e8f7642c1713
Christian Brabandt <cb@256bit.org>
parents: 7914
diff changeset
109 self.request.sendall(cmd.encode('utf-8'))
7912
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
110 response = "ok"
7965
646d5148fee2 commit https://github.com/vim/vim/commit/55fab439a6f3bba6dbe780ac034b84d5822a1a96
Christian Brabandt <cb@256bit.org>
parents: 7939
diff changeset
111 elif decoded[1] == 'eval-error':
646d5148fee2 commit https://github.com/vim/vim/commit/55fab439a6f3bba6dbe780ac034b84d5822a1a96
Christian Brabandt <cb@256bit.org>
parents: 7939
diff changeset
112 # Send an eval request that works but the result can't
646d5148fee2 commit https://github.com/vim/vim/commit/55fab439a6f3bba6dbe780ac034b84d5822a1a96
Christian Brabandt <cb@256bit.org>
parents: 7939
diff changeset
113 # be encoded.
8744
ff9973bbbfcb commit https://github.com/vim/vim/commit/fa8b2e173dd5f6c4a5cfd326abdcf68b8eebf90d
Christian Brabandt <cb@256bit.org>
parents: 8663
diff changeset
114 cmd = '["expr","function(\\"tr\\")", -5]'
8663
b2a48aabe21f commit https://github.com/vim/vim/commit/a63cdb5ed685181c377ee89f1d1de6a97dfeb151
Christian Brabandt <cb@256bit.org>
parents: 8655
diff changeset
115 print("sending: {0}".format(cmd))
7965
646d5148fee2 commit https://github.com/vim/vim/commit/55fab439a6f3bba6dbe780ac034b84d5822a1a96
Christian Brabandt <cb@256bit.org>
parents: 7939
diff changeset
116 self.request.sendall(cmd.encode('utf-8'))
646d5148fee2 commit https://github.com/vim/vim/commit/55fab439a6f3bba6dbe780ac034b84d5822a1a96
Christian Brabandt <cb@256bit.org>
parents: 7939
diff changeset
117 response = "ok"
7918
ce5a7a613867 commit https://github.com/vim/vim/commit/66624ff0d9e1de2fc5eb4f95f3a3a2ed70b10138
Christian Brabandt <cb@256bit.org>
parents: 7916
diff changeset
118 elif decoded[1] == 'eval-bad':
ce5a7a613867 commit https://github.com/vim/vim/commit/66624ff0d9e1de2fc5eb4f95f3a3a2ed70b10138
Christian Brabandt <cb@256bit.org>
parents: 7916
diff changeset
119 # Send an eval request missing the third argument.
8159
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8153
diff changeset
120 cmd = '["expr","xxx"]'
8663
b2a48aabe21f commit https://github.com/vim/vim/commit/a63cdb5ed685181c377ee89f1d1de6a97dfeb151
Christian Brabandt <cb@256bit.org>
parents: 8655
diff changeset
121 print("sending: {0}".format(cmd))
7918
ce5a7a613867 commit https://github.com/vim/vim/commit/66624ff0d9e1de2fc5eb4f95f3a3a2ed70b10138
Christian Brabandt <cb@256bit.org>
parents: 7916
diff changeset
122 self.request.sendall(cmd.encode('utf-8'))
ce5a7a613867 commit https://github.com/vim/vim/commit/66624ff0d9e1de2fc5eb4f95f3a3a2ed70b10138
Christian Brabandt <cb@256bit.org>
parents: 7916
diff changeset
123 response = "ok"
8655
1eb302bf2475 commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents: 8653
diff changeset
124 elif decoded[1] == 'malformed1':
8653
d80edead9675 commit https://github.com/vim/vim/commit/ac74d5e86cd16b42e81ba48f58f3d45c72758248
Christian Brabandt <cb@256bit.org>
parents: 8404
diff changeset
125 cmd = '["ex",":"]wrong!["ex","smi"]'
8663
b2a48aabe21f commit https://github.com/vim/vim/commit/a63cdb5ed685181c377ee89f1d1de6a97dfeb151
Christian Brabandt <cb@256bit.org>
parents: 8655
diff changeset
126 print("sending: {0}".format(cmd))
8653
d80edead9675 commit https://github.com/vim/vim/commit/ac74d5e86cd16b42e81ba48f58f3d45c72758248
Christian Brabandt <cb@256bit.org>
parents: 8404
diff changeset
127 self.request.sendall(cmd.encode('utf-8'))
d80edead9675 commit https://github.com/vim/vim/commit/ac74d5e86cd16b42e81ba48f58f3d45c72758248
Christian Brabandt <cb@256bit.org>
parents: 8404
diff changeset
128 response = "ok"
8655
1eb302bf2475 commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents: 8653
diff changeset
129 elif decoded[1] == 'malformed2':
1eb302bf2475 commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents: 8653
diff changeset
130 cmd = '"unterminated string'
8663
b2a48aabe21f commit https://github.com/vim/vim/commit/a63cdb5ed685181c377ee89f1d1de6a97dfeb151
Christian Brabandt <cb@256bit.org>
parents: 8655
diff changeset
131 print("sending: {0}".format(cmd))
8655
1eb302bf2475 commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents: 8653
diff changeset
132 self.request.sendall(cmd.encode('utf-8'))
1eb302bf2475 commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents: 8653
diff changeset
133 response = "ok"
1eb302bf2475 commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents: 8653
diff changeset
134 # Need to wait for Vim to give up, otherwise the double
1eb302bf2475 commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents: 8653
diff changeset
135 # quote in the "ok" response terminates the string.
1eb302bf2475 commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents: 8653
diff changeset
136 time.sleep(0.2)
1eb302bf2475 commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents: 8653
diff changeset
137 elif decoded[1] == 'malformed3':
1eb302bf2475 commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents: 8653
diff changeset
138 cmd = '["ex","missing ]"'
8663
b2a48aabe21f commit https://github.com/vim/vim/commit/a63cdb5ed685181c377ee89f1d1de6a97dfeb151
Christian Brabandt <cb@256bit.org>
parents: 8655
diff changeset
139 print("sending: {0}".format(cmd))
8655
1eb302bf2475 commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents: 8653
diff changeset
140 self.request.sendall(cmd.encode('utf-8'))
1eb302bf2475 commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents: 8653
diff changeset
141 response = "ok"
1eb302bf2475 commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents: 8653
diff changeset
142 # Need to wait for Vim to give up, otherwise the ]
1eb302bf2475 commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents: 8653
diff changeset
143 # in the "ok" response terminates the list.
1eb302bf2475 commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents: 8653
diff changeset
144 time.sleep(0.2)
1eb302bf2475 commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents: 8653
diff changeset
145 elif decoded[1] == 'split':
1eb302bf2475 commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents: 8653
diff changeset
146 cmd = '["ex","let '
8663
b2a48aabe21f commit https://github.com/vim/vim/commit/a63cdb5ed685181c377ee89f1d1de6a97dfeb151
Christian Brabandt <cb@256bit.org>
parents: 8655
diff changeset
147 print("sending: {0}".format(cmd))
8655
1eb302bf2475 commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents: 8653
diff changeset
148 self.request.sendall(cmd.encode('utf-8'))
1eb302bf2475 commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents: 8653
diff changeset
149 time.sleep(0.01)
1eb302bf2475 commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents: 8653
diff changeset
150 cmd = 'g:split = 123"]'
8663
b2a48aabe21f commit https://github.com/vim/vim/commit/a63cdb5ed685181c377ee89f1d1de6a97dfeb151
Christian Brabandt <cb@256bit.org>
parents: 8655
diff changeset
151 print("sending: {0}".format(cmd))
8655
1eb302bf2475 commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents: 8653
diff changeset
152 self.request.sendall(cmd.encode('utf-8'))
1eb302bf2475 commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents: 8653
diff changeset
153 response = "ok"
7939
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
154 elif decoded[1] == 'an expr':
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
155 # Send an expr request.
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
156 cmd = '["expr","setline(\\"$\\", [\\"one\\",\\"two\\",\\"three\\"])"]'
8663
b2a48aabe21f commit https://github.com/vim/vim/commit/a63cdb5ed685181c377ee89f1d1de6a97dfeb151
Christian Brabandt <cb@256bit.org>
parents: 8655
diff changeset
157 print("sending: {0}".format(cmd))
7939
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
158 self.request.sendall(cmd.encode('utf-8'))
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
159 response = "ok"
8159
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8153
diff changeset
160 elif decoded[1] == 'call-func':
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8153
diff changeset
161 cmd = '["call","MyFunction",[1,2,3], 0]'
8663
b2a48aabe21f commit https://github.com/vim/vim/commit/a63cdb5ed685181c377ee89f1d1de6a97dfeb151
Christian Brabandt <cb@256bit.org>
parents: 8655
diff changeset
162 print("sending: {0}".format(cmd))
8159
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8153
diff changeset
163 self.request.sendall(cmd.encode('utf-8'))
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8153
diff changeset
164 response = "ok"
7939
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
165 elif decoded[1] == 'redraw':
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
166 cmd = '["redraw",""]'
8663
b2a48aabe21f commit https://github.com/vim/vim/commit/a63cdb5ed685181c377ee89f1d1de6a97dfeb151
Christian Brabandt <cb@256bit.org>
parents: 8655
diff changeset
167 print("sending: {0}".format(cmd))
7939
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
168 self.request.sendall(cmd.encode('utf-8'))
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
169 response = "ok"
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
170 elif decoded[1] == 'redraw!':
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
171 cmd = '["redraw","force"]'
8663
b2a48aabe21f commit https://github.com/vim/vim/commit/a63cdb5ed685181c377ee89f1d1de6a97dfeb151
Christian Brabandt <cb@256bit.org>
parents: 8655
diff changeset
172 print("sending: {0}".format(cmd))
7939
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
173 self.request.sendall(cmd.encode('utf-8'))
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
174 response = "ok"
7937
2e905dfc6999 commit https://github.com/vim/vim/commit/6076fe1986255d32b7a078a28bf9e7bea19d6f30
Christian Brabandt <cb@256bit.org>
parents: 7920
diff changeset
175 elif decoded[1] == 'empty-request':
2e905dfc6999 commit https://github.com/vim/vim/commit/6076fe1986255d32b7a078a28bf9e7bea19d6f30
Christian Brabandt <cb@256bit.org>
parents: 7920
diff changeset
176 cmd = '[]'
8663
b2a48aabe21f commit https://github.com/vim/vim/commit/a63cdb5ed685181c377ee89f1d1de6a97dfeb151
Christian Brabandt <cb@256bit.org>
parents: 8655
diff changeset
177 print("sending: {0}".format(cmd))
7937
2e905dfc6999 commit https://github.com/vim/vim/commit/6076fe1986255d32b7a078a28bf9e7bea19d6f30
Christian Brabandt <cb@256bit.org>
parents: 7920
diff changeset
178 self.request.sendall(cmd.encode('utf-8'))
2e905dfc6999 commit https://github.com/vim/vim/commit/6076fe1986255d32b7a078a28bf9e7bea19d6f30
Christian Brabandt <cb@256bit.org>
parents: 7920
diff changeset
179 response = "ok"
7912
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
180 elif decoded[1] == 'eval-result':
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
181 # Send back the last received eval result.
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
182 response = last_eval
8009
b2cfa3416ba0 commit https://github.com/vim/vim/commit/f6157284de71d8881f3b89fbd79d1ecbf842929f
Christian Brabandt <cb@256bit.org>
parents: 7993
diff changeset
183 elif decoded[1] == 'call me':
b2cfa3416ba0 commit https://github.com/vim/vim/commit/f6157284de71d8881f3b89fbd79d1ecbf842929f
Christian Brabandt <cb@256bit.org>
parents: 7993
diff changeset
184 cmd = '[0,"we called you"]'
8663
b2a48aabe21f commit https://github.com/vim/vim/commit/a63cdb5ed685181c377ee89f1d1de6a97dfeb151
Christian Brabandt <cb@256bit.org>
parents: 8655
diff changeset
185 print("sending: {0}".format(cmd))
8009
b2cfa3416ba0 commit https://github.com/vim/vim/commit/f6157284de71d8881f3b89fbd79d1ecbf842929f
Christian Brabandt <cb@256bit.org>
parents: 7993
diff changeset
186 self.request.sendall(cmd.encode('utf-8'))
b2cfa3416ba0 commit https://github.com/vim/vim/commit/f6157284de71d8881f3b89fbd79d1ecbf842929f
Christian Brabandt <cb@256bit.org>
parents: 7993
diff changeset
187 response = "ok"
b2cfa3416ba0 commit https://github.com/vim/vim/commit/f6157284de71d8881f3b89fbd79d1ecbf842929f
Christian Brabandt <cb@256bit.org>
parents: 7993
diff changeset
188 elif decoded[1] == 'call me again':
b2cfa3416ba0 commit https://github.com/vim/vim/commit/f6157284de71d8881f3b89fbd79d1ecbf842929f
Christian Brabandt <cb@256bit.org>
parents: 7993
diff changeset
189 cmd = '[0,"we did call you"]'
8663
b2a48aabe21f commit https://github.com/vim/vim/commit/a63cdb5ed685181c377ee89f1d1de6a97dfeb151
Christian Brabandt <cb@256bit.org>
parents: 8655
diff changeset
190 print("sending: {0}".format(cmd))
8009
b2cfa3416ba0 commit https://github.com/vim/vim/commit/f6157284de71d8881f3b89fbd79d1ecbf842929f
Christian Brabandt <cb@256bit.org>
parents: 7993
diff changeset
191 self.request.sendall(cmd.encode('utf-8'))
b2cfa3416ba0 commit https://github.com/vim/vim/commit/f6157284de71d8881f3b89fbd79d1ecbf842929f
Christian Brabandt <cb@256bit.org>
parents: 7993
diff changeset
192 response = ""
8404
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
193 elif decoded[1] == 'send zero':
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
194 cmd = '[0,"zero index"]'
8663
b2a48aabe21f commit https://github.com/vim/vim/commit/a63cdb5ed685181c377ee89f1d1de6a97dfeb151
Christian Brabandt <cb@256bit.org>
parents: 8655
diff changeset
195 print("sending: {0}".format(cmd))
8404
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
196 self.request.sendall(cmd.encode('utf-8'))
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
197 response = "sent zero"
8210
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8159
diff changeset
198 elif decoded[1] == 'close me':
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8159
diff changeset
199 print("closing")
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8159
diff changeset
200 self.request.close()
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8159
diff changeset
201 response = ""
8159
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8153
diff changeset
202 elif decoded[1] == 'wait a bit':
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8153
diff changeset
203 time.sleep(0.2)
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8153
diff changeset
204 response = "waited"
7912
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
205 elif decoded[1] == '!quit!':
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
206 # we're done
7920
1ebc7be4dbbf commit https://github.com/vim/vim/commit/b3e2f00f39d6edafda6e5508a926ebd244997a0f
Christian Brabandt <cb@256bit.org>
parents: 7918
diff changeset
207 self.server.shutdown()
7993
0756eab66b71 commit https://github.com/vim/vim/commit/b92abad0c58de36d0b0afdcd4ec05261fa1fa84c
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
208 return
7912
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
209 elif decoded[1] == '!crash!':
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
210 # Crash!
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
211 42 / 0
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
212 else:
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
213 response = "what?"
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
214
8009
b2cfa3416ba0 commit https://github.com/vim/vim/commit/f6157284de71d8881f3b89fbd79d1ecbf842929f
Christian Brabandt <cb@256bit.org>
parents: 7993
diff changeset
215 if response == "":
b2cfa3416ba0 commit https://github.com/vim/vim/commit/f6157284de71d8881f3b89fbd79d1ecbf842929f
Christian Brabandt <cb@256bit.org>
parents: 7993
diff changeset
216 print("no response")
b2cfa3416ba0 commit https://github.com/vim/vim/commit/f6157284de71d8881f3b89fbd79d1ecbf842929f
Christian Brabandt <cb@256bit.org>
parents: 7993
diff changeset
217 else:
b2cfa3416ba0 commit https://github.com/vim/vim/commit/f6157284de71d8881f3b89fbd79d1ecbf842929f
Christian Brabandt <cb@256bit.org>
parents: 7993
diff changeset
218 encoded = json.dumps([decoded[0], response])
8663
b2a48aabe21f commit https://github.com/vim/vim/commit/a63cdb5ed685181c377ee89f1d1de6a97dfeb151
Christian Brabandt <cb@256bit.org>
parents: 8655
diff changeset
219 print("sending: {0}".format(encoded))
8009
b2cfa3416ba0 commit https://github.com/vim/vim/commit/f6157284de71d8881f3b89fbd79d1ecbf842929f
Christian Brabandt <cb@256bit.org>
parents: 7993
diff changeset
220 self.request.sendall(encoded.encode('utf-8'))
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
221
7912
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
222 # Negative numbers are used for "eval" responses.
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
223 elif decoded[0] < 0:
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
224 last_eval = decoded
7906
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7902
diff changeset
225
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
226 class ThreadedTCPServer(socketserver.ThreadingMixIn, socketserver.TCPServer):
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
227 pass
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
228
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
229 def writePortInFile(port):
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
230 # Write the port number in Xportnr, so that the test knows it.
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
231 f = open("Xportnr", "w")
8663
b2a48aabe21f commit https://github.com/vim/vim/commit/a63cdb5ed685181c377ee89f1d1de6a97dfeb151
Christian Brabandt <cb@256bit.org>
parents: 8655
diff changeset
232 f.write("{0}".format(port))
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
233 f.close()
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
234
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
235 if __name__ == "__main__":
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
236 HOST, PORT = "localhost", 0
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
237
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
238 # Wait half a second before opening the port to test waittime in ch_open().
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
239 # We do want to get the port number, get that first. We cannot open the
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
240 # socket, guess a port is free.
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
241 if len(sys.argv) >= 2 and sys.argv[1] == 'delay':
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
242 PORT = 13684
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
243 writePortInFile(PORT)
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
244
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
245 print("Wait for it...")
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
246 time.sleep(0.5)
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
247
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
248 server = ThreadedTCPServer((HOST, PORT), ThreadedTCPRequestHandler)
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
249 ip, port = server.server_address
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
250
7937
2e905dfc6999 commit https://github.com/vim/vim/commit/6076fe1986255d32b7a078a28bf9e7bea19d6f30
Christian Brabandt <cb@256bit.org>
parents: 7920
diff changeset
251 # Start a thread with the server. That thread will then start a new thread
2e905dfc6999 commit https://github.com/vim/vim/commit/6076fe1986255d32b7a078a28bf9e7bea19d6f30
Christian Brabandt <cb@256bit.org>
parents: 7920
diff changeset
252 # for each connection.
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
253 server_thread = threading.Thread(target=server.serve_forever)
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
254 server_thread.start()
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
255
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
256 writePortInFile(port)
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
257
8663
b2a48aabe21f commit https://github.com/vim/vim/commit/a63cdb5ed685181c377ee89f1d1de6a97dfeb151
Christian Brabandt <cb@256bit.org>
parents: 8655
diff changeset
258 print("Listening on port {0}".format(port))
7920
1ebc7be4dbbf commit https://github.com/vim/vim/commit/b3e2f00f39d6edafda6e5508a926ebd244997a0f
Christian Brabandt <cb@256bit.org>
parents: 7918
diff changeset
259
1ebc7be4dbbf commit https://github.com/vim/vim/commit/b3e2f00f39d6edafda6e5508a926ebd244997a0f
Christian Brabandt <cb@256bit.org>
parents: 7918
diff changeset
260 # Main thread terminates, but the server continues running
1ebc7be4dbbf commit https://github.com/vim/vim/commit/b3e2f00f39d6edafda6e5508a926ebd244997a0f
Christian Brabandt <cb@256bit.org>
parents: 7918
diff changeset
261 # until server.shutdown() is called.
8153
240deebfadde commit https://github.com/vim/vim/commit/ddbe7d26b10c4374f406b807ae161826cf2096e1
Christian Brabandt <cb@256bit.org>
parents: 8114
diff changeset
262 try:
240deebfadde commit https://github.com/vim/vim/commit/ddbe7d26b10c4374f406b807ae161826cf2096e1
Christian Brabandt <cb@256bit.org>
parents: 8114
diff changeset
263 while server_thread.isAlive():
240deebfadde commit https://github.com/vim/vim/commit/ddbe7d26b10c4374f406b807ae161826cf2096e1
Christian Brabandt <cb@256bit.org>
parents: 8114
diff changeset
264 server_thread.join(1)
240deebfadde commit https://github.com/vim/vim/commit/ddbe7d26b10c4374f406b807ae161826cf2096e1
Christian Brabandt <cb@256bit.org>
parents: 8114
diff changeset
265 except (KeyboardInterrupt, SystemExit):
240deebfadde commit https://github.com/vim/vim/commit/ddbe7d26b10c4374f406b807ae161826cf2096e1
Christian Brabandt <cb@256bit.org>
parents: 8114
diff changeset
266 server.shutdown()