annotate src/testdir/test_channel.py @ 11148:87779062d706 v8.0.0461

patch 8.0.0461: test 45 hangs on MS-Windows commit https://github.com/vim/vim/commit/4a5a8dd6e5fa5581bd24b584a71b5fce9ba34bb8 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Mar 16 13:54:10 2017 +0100 patch 8.0.0461: test 45 hangs on MS-Windows Problem: Test 45 hangs on MS-Windows. Solution: Reset 'shiftwidth'. Also remove redundent function.
author Christian Brabandt <cb@256bit.org>
date Thu, 16 Mar 2017 14:00:05 +0100
parents a57b2284de93
children 33a2277b8d4d
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
9969
176e34b0d678 commit https://github.com/vim/vim/commit/f1f0792e55e72cdc7c833b30f565a9b02f18bb1e
Christian Brabandt <cb@256bit.org>
parents: 8746
diff changeset
41 # newline, which should be after the matching "]".
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 != '':
9969
176e34b0d678 commit https://github.com/vim/vim/commit/f1f0792e55e72cdc7c833b30f565a9b02f18bb1e
Christian Brabandt <cb@256bit.org>
parents: 8746
diff changeset
44 splitidx = todo.find('\n')
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:
9969
176e34b0d678 commit https://github.com/vim/vim/commit/f1f0792e55e72cdc7c833b30f565a9b02f18bb1e
Christian Brabandt <cb@256bit.org>
parents: 8746
diff changeset
49 used = todo[:splitidx]
7914
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"
10458
a57b2284de93 commit https://github.com/vim/vim/commit/3fad98e8af247af8ebc49730646282a71ccdd47a
Christian Brabandt <cb@256bit.org>
parents: 9969
diff changeset
129 # Need to wait for Vim to give up, otherwise it
a57b2284de93 commit https://github.com/vim/vim/commit/3fad98e8af247af8ebc49730646282a71ccdd47a
Christian Brabandt <cb@256bit.org>
parents: 9969
diff changeset
130 # sometimes fails on OS X.
a57b2284de93 commit https://github.com/vim/vim/commit/3fad98e8af247af8ebc49730646282a71ccdd47a
Christian Brabandt <cb@256bit.org>
parents: 9969
diff changeset
131 time.sleep(0.2)
8655
1eb302bf2475 commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents: 8653
diff changeset
132 elif decoded[1] == 'malformed2':
1eb302bf2475 commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents: 8653
diff changeset
133 cmd = '"unterminated string'
8663
b2a48aabe21f commit https://github.com/vim/vim/commit/a63cdb5ed685181c377ee89f1d1de6a97dfeb151
Christian Brabandt <cb@256bit.org>
parents: 8655
diff changeset
134 print("sending: {0}".format(cmd))
8655
1eb302bf2475 commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents: 8653
diff changeset
135 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
136 response = "ok"
1eb302bf2475 commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents: 8653
diff changeset
137 # 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
138 # 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
139 time.sleep(0.2)
1eb302bf2475 commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents: 8653
diff changeset
140 elif decoded[1] == 'malformed3':
1eb302bf2475 commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents: 8653
diff changeset
141 cmd = '["ex","missing ]"'
8663
b2a48aabe21f commit https://github.com/vim/vim/commit/a63cdb5ed685181c377ee89f1d1de6a97dfeb151
Christian Brabandt <cb@256bit.org>
parents: 8655
diff changeset
142 print("sending: {0}".format(cmd))
8655
1eb302bf2475 commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents: 8653
diff changeset
143 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
144 response = "ok"
1eb302bf2475 commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents: 8653
diff changeset
145 # 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
146 # 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
147 time.sleep(0.2)
1eb302bf2475 commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents: 8653
diff changeset
148 elif decoded[1] == 'split':
1eb302bf2475 commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents: 8653
diff changeset
149 cmd = '["ex","let '
8663
b2a48aabe21f commit https://github.com/vim/vim/commit/a63cdb5ed685181c377ee89f1d1de6a97dfeb151
Christian Brabandt <cb@256bit.org>
parents: 8655
diff changeset
150 print("sending: {0}".format(cmd))
8655
1eb302bf2475 commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents: 8653
diff changeset
151 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
152 time.sleep(0.01)
1eb302bf2475 commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents: 8653
diff changeset
153 cmd = 'g:split = 123"]'
8663
b2a48aabe21f commit https://github.com/vim/vim/commit/a63cdb5ed685181c377ee89f1d1de6a97dfeb151
Christian Brabandt <cb@256bit.org>
parents: 8655
diff changeset
154 print("sending: {0}".format(cmd))
8655
1eb302bf2475 commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents: 8653
diff changeset
155 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
156 response = "ok"
7939
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
157 elif decoded[1] == 'an expr':
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
158 # Send an expr request.
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
159 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
160 print("sending: {0}".format(cmd))
7939
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
161 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
162 response = "ok"
8159
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8153
diff changeset
163 elif decoded[1] == 'call-func':
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8153
diff changeset
164 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
165 print("sending: {0}".format(cmd))
8159
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8153
diff changeset
166 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
167 response = "ok"
7939
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
168 elif decoded[1] == 'redraw':
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
169 cmd = '["redraw",""]'
8663
b2a48aabe21f commit https://github.com/vim/vim/commit/a63cdb5ed685181c377ee89f1d1de6a97dfeb151
Christian Brabandt <cb@256bit.org>
parents: 8655
diff changeset
170 print("sending: {0}".format(cmd))
7939
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
171 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
172 response = "ok"
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
173 elif decoded[1] == 'redraw!':
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
174 cmd = '["redraw","force"]'
8663
b2a48aabe21f commit https://github.com/vim/vim/commit/a63cdb5ed685181c377ee89f1d1de6a97dfeb151
Christian Brabandt <cb@256bit.org>
parents: 8655
diff changeset
175 print("sending: {0}".format(cmd))
7939
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
176 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
177 response = "ok"
7937
2e905dfc6999 commit https://github.com/vim/vim/commit/6076fe1986255d32b7a078a28bf9e7bea19d6f30
Christian Brabandt <cb@256bit.org>
parents: 7920
diff changeset
178 elif decoded[1] == 'empty-request':
2e905dfc6999 commit https://github.com/vim/vim/commit/6076fe1986255d32b7a078a28bf9e7bea19d6f30
Christian Brabandt <cb@256bit.org>
parents: 7920
diff changeset
179 cmd = '[]'
8663
b2a48aabe21f commit https://github.com/vim/vim/commit/a63cdb5ed685181c377ee89f1d1de6a97dfeb151
Christian Brabandt <cb@256bit.org>
parents: 8655
diff changeset
180 print("sending: {0}".format(cmd))
7937
2e905dfc6999 commit https://github.com/vim/vim/commit/6076fe1986255d32b7a078a28bf9e7bea19d6f30
Christian Brabandt <cb@256bit.org>
parents: 7920
diff changeset
181 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
182 response = "ok"
7912
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
183 elif decoded[1] == 'eval-result':
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
184 # 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
185 response = last_eval
8009
b2cfa3416ba0 commit https://github.com/vim/vim/commit/f6157284de71d8881f3b89fbd79d1ecbf842929f
Christian Brabandt <cb@256bit.org>
parents: 7993
diff changeset
186 elif decoded[1] == 'call me':
b2cfa3416ba0 commit https://github.com/vim/vim/commit/f6157284de71d8881f3b89fbd79d1ecbf842929f
Christian Brabandt <cb@256bit.org>
parents: 7993
diff changeset
187 cmd = '[0,"we called you"]'
8663
b2a48aabe21f commit https://github.com/vim/vim/commit/a63cdb5ed685181c377ee89f1d1de6a97dfeb151
Christian Brabandt <cb@256bit.org>
parents: 8655
diff changeset
188 print("sending: {0}".format(cmd))
8009
b2cfa3416ba0 commit https://github.com/vim/vim/commit/f6157284de71d8881f3b89fbd79d1ecbf842929f
Christian Brabandt <cb@256bit.org>
parents: 7993
diff changeset
189 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
190 response = "ok"
b2cfa3416ba0 commit https://github.com/vim/vim/commit/f6157284de71d8881f3b89fbd79d1ecbf842929f
Christian Brabandt <cb@256bit.org>
parents: 7993
diff changeset
191 elif decoded[1] == 'call me again':
b2cfa3416ba0 commit https://github.com/vim/vim/commit/f6157284de71d8881f3b89fbd79d1ecbf842929f
Christian Brabandt <cb@256bit.org>
parents: 7993
diff changeset
192 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
193 print("sending: {0}".format(cmd))
8009
b2cfa3416ba0 commit https://github.com/vim/vim/commit/f6157284de71d8881f3b89fbd79d1ecbf842929f
Christian Brabandt <cb@256bit.org>
parents: 7993
diff changeset
194 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
195 response = ""
8404
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
196 elif decoded[1] == 'send zero':
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
197 cmd = '[0,"zero index"]'
8663
b2a48aabe21f commit https://github.com/vim/vim/commit/a63cdb5ed685181c377ee89f1d1de6a97dfeb151
Christian Brabandt <cb@256bit.org>
parents: 8655
diff changeset
198 print("sending: {0}".format(cmd))
8404
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
199 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
200 response = "sent zero"
8210
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8159
diff changeset
201 elif decoded[1] == 'close me':
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8159
diff changeset
202 print("closing")
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8159
diff changeset
203 self.request.close()
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8159
diff changeset
204 response = ""
8159
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8153
diff changeset
205 elif decoded[1] == 'wait a bit':
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8153
diff changeset
206 time.sleep(0.2)
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8153
diff changeset
207 response = "waited"
7912
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
208 elif decoded[1] == '!quit!':
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
209 # we're done
7920
1ebc7be4dbbf commit https://github.com/vim/vim/commit/b3e2f00f39d6edafda6e5508a926ebd244997a0f
Christian Brabandt <cb@256bit.org>
parents: 7918
diff changeset
210 self.server.shutdown()
7993
0756eab66b71 commit https://github.com/vim/vim/commit/b92abad0c58de36d0b0afdcd4ec05261fa1fa84c
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
211 return
7912
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
212 elif decoded[1] == '!crash!':
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
213 # Crash!
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
214 42 / 0
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
215 else:
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
216 response = "what?"
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
217
8009
b2cfa3416ba0 commit https://github.com/vim/vim/commit/f6157284de71d8881f3b89fbd79d1ecbf842929f
Christian Brabandt <cb@256bit.org>
parents: 7993
diff changeset
218 if response == "":
b2cfa3416ba0 commit https://github.com/vim/vim/commit/f6157284de71d8881f3b89fbd79d1ecbf842929f
Christian Brabandt <cb@256bit.org>
parents: 7993
diff changeset
219 print("no response")
b2cfa3416ba0 commit https://github.com/vim/vim/commit/f6157284de71d8881f3b89fbd79d1ecbf842929f
Christian Brabandt <cb@256bit.org>
parents: 7993
diff changeset
220 else:
b2cfa3416ba0 commit https://github.com/vim/vim/commit/f6157284de71d8881f3b89fbd79d1ecbf842929f
Christian Brabandt <cb@256bit.org>
parents: 7993
diff changeset
221 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
222 print("sending: {0}".format(encoded))
8009
b2cfa3416ba0 commit https://github.com/vim/vim/commit/f6157284de71d8881f3b89fbd79d1ecbf842929f
Christian Brabandt <cb@256bit.org>
parents: 7993
diff changeset
223 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
224
7912
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
225 # 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
226 elif decoded[0] < 0:
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
227 last_eval = decoded
7906
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7902
diff changeset
228
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
229 class ThreadedTCPServer(socketserver.ThreadingMixIn, socketserver.TCPServer):
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
230 pass
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
231
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
232 def writePortInFile(port):
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
233 # 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
234 f = open("Xportnr", "w")
8663
b2a48aabe21f commit https://github.com/vim/vim/commit/a63cdb5ed685181c377ee89f1d1de6a97dfeb151
Christian Brabandt <cb@256bit.org>
parents: 8655
diff changeset
235 f.write("{0}".format(port))
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
236 f.close()
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
237
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
238 if __name__ == "__main__":
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
239 HOST, PORT = "localhost", 0
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
240
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
241 # 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
242 # 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
243 # socket, guess a port is free.
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
244 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
245 PORT = 13684
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
246 writePortInFile(PORT)
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
247
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
248 print("Wait for it...")
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
249 time.sleep(0.5)
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
250
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
251 server = ThreadedTCPServer((HOST, PORT), ThreadedTCPRequestHandler)
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
252 ip, port = server.server_address
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
253
7937
2e905dfc6999 commit https://github.com/vim/vim/commit/6076fe1986255d32b7a078a28bf9e7bea19d6f30
Christian Brabandt <cb@256bit.org>
parents: 7920
diff changeset
254 # 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
255 # for each connection.
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
256 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
257 server_thread.start()
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
258
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
259 writePortInFile(port)
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
260
8663
b2a48aabe21f commit https://github.com/vim/vim/commit/a63cdb5ed685181c377ee89f1d1de6a97dfeb151
Christian Brabandt <cb@256bit.org>
parents: 8655
diff changeset
261 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
262
1ebc7be4dbbf commit https://github.com/vim/vim/commit/b3e2f00f39d6edafda6e5508a926ebd244997a0f
Christian Brabandt <cb@256bit.org>
parents: 7918
diff changeset
263 # 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
264 # until server.shutdown() is called.
8153
240deebfadde commit https://github.com/vim/vim/commit/ddbe7d26b10c4374f406b807ae161826cf2096e1
Christian Brabandt <cb@256bit.org>
parents: 8114
diff changeset
265 try:
240deebfadde commit https://github.com/vim/vim/commit/ddbe7d26b10c4374f406b807ae161826cf2096e1
Christian Brabandt <cb@256bit.org>
parents: 8114
diff changeset
266 while server_thread.isAlive():
240deebfadde commit https://github.com/vim/vim/commit/ddbe7d26b10c4374f406b807ae161826cf2096e1
Christian Brabandt <cb@256bit.org>
parents: 8114
diff changeset
267 server_thread.join(1)
240deebfadde commit https://github.com/vim/vim/commit/ddbe7d26b10c4374f406b807ae161826cf2096e1
Christian Brabandt <cb@256bit.org>
parents: 8114
diff changeset
268 except (KeyboardInterrupt, SystemExit):
240deebfadde commit https://github.com/vim/vim/commit/ddbe7d26b10c4374f406b807ae161826cf2096e1
Christian Brabandt <cb@256bit.org>
parents: 8114
diff changeset
269 server.shutdown()