annotate Demo/sockets/rpython.py @ 79675:c0a2294de787 2.7

Issue #16199: Backport 2to3 typo fix from 3.2.
author Chris Jerdonek <chris.jerdonek@gmail.com>
date Thu, 11 Oct 2012 16:15:46 -0700
parents 2bc66f1df7cc
children 7d16b42fcdbd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4573
73758db2f464 /usr/local/bin/python -> /usr/bin/env python
Guido van Rossum <guido@python.org>
parents: 2655
diff changeset
1 #! /usr/bin/env python
2655
db3dace278ac added rpython
Guido van Rossum <guido@python.org>
parents:
diff changeset
2
db3dace278ac added rpython
Guido van Rossum <guido@python.org>
parents:
diff changeset
3 # Remote python client.
db3dace278ac added rpython
Guido van Rossum <guido@python.org>
parents:
diff changeset
4 # Execute Python commands remotely and send output back.
db3dace278ac added rpython
Guido van Rossum <guido@python.org>
parents:
diff changeset
5
db3dace278ac added rpython
Guido van Rossum <guido@python.org>
parents:
diff changeset
6 import sys
db3dace278ac added rpython
Guido van Rossum <guido@python.org>
parents:
diff changeset
7 import string
db3dace278ac added rpython
Guido van Rossum <guido@python.org>
parents:
diff changeset
8 from socket import *
db3dace278ac added rpython
Guido van Rossum <guido@python.org>
parents:
diff changeset
9
db3dace278ac added rpython
Guido van Rossum <guido@python.org>
parents:
diff changeset
10 PORT = 4127
db3dace278ac added rpython
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 BUFSIZE = 1024
db3dace278ac added rpython
Guido van Rossum <guido@python.org>
parents:
diff changeset
12
db3dace278ac added rpython
Guido van Rossum <guido@python.org>
parents:
diff changeset
13 def main():
32735
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
14 if len(sys.argv) < 3:
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
15 print "usage: rpython host command"
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
16 sys.exit(2)
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
17 host = sys.argv[1]
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
18 port = PORT
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
19 i = string.find(host, ':')
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
20 if i >= 0:
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
21 port = string.atoi(port[i+1:])
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
22 host = host[:i]
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
23 command = string.join(sys.argv[2:])
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
24 s = socket(AF_INET, SOCK_STREAM)
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
25 s.connect((host, port))
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
26 s.send(command)
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
27 s.shutdown(1)
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
28 reply = ''
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
29 while 1:
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
30 data = s.recv(BUFSIZE)
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
31 if not data: break
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
32 reply = reply + data
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
33 print reply,
2655
db3dace278ac added rpython
Guido van Rossum <guido@python.org>
parents:
diff changeset
34
db3dace278ac added rpython
Guido van Rossum <guido@python.org>
parents:
diff changeset
35 main()