Skip to content

Commit ce96f69

Browse files
committed
Get rid of a bunch more raw_input references
1 parent 9e2b966 commit ce96f69

42 files changed

Lines changed: 222 additions & 144 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Demo/pdist/cmptree.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
import time
77
import os
88

9+
def raw_input(prompt):
10+
sys.stdout.write(prompt)
11+
sys.stdout.flush()
12+
return sys.stdin.readline()
13+
914
def main():
1015
pwd = os.getcwd()
1116
s = raw_input("chdir [%s] " % pwd)

Demo/pdist/mac.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
import sys
2-
import string
32
import rcvs
43

4+
def raw_input(prompt):
5+
sys.stdout.write(prompt)
6+
sys.stdout.flush()
7+
return sys.stdin.readline()
8+
59
def main():
610
while 1:
711
try:
812
line = raw_input('$ ')
913
except EOFError:
1014
break
11-
words = string.split(line)
15+
words = line.split()
1216
if not words:
1317
continue
1418
if words[0] != 'rcvs':
1519
words.insert(0, 'rcvs')
1620
sys.argv = words
1721
rcvs.main()
1822

19-
main()
23+
if __name__ == '__main__':
24+
main()

Demo/pdist/rcvs.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
from cvslib import CVS, File
3636
import md5
3737
import os
38-
import string
3938
import sys
4039
from cmdfw import CommandFrameWork
4140

@@ -269,13 +268,13 @@ def commit(self, files, message = ""):
269268

270269
def mailinfo(self, files, message = ""):
271270
towhom = "sjoerd@cwi.nl, jack@cwi.nl" # XXX
272-
mailtext = MAILFORM % (towhom, string.join(files),
273-
string.join(files), message)
271+
mailtext = MAILFORM % (towhom, ' '.join(files),
272+
' '.join(files), message)
274273
print '-'*70
275274
print mailtext
276275
print '-'*70
277276
ok = raw_input("OK to mail to %s? " % towhom)
278-
if string.lower(string.strip(ok)) in ('y', 'ye', 'yes'):
277+
if ok.lower().strip() in ('y', 'ye', 'yes'):
279278
p = os.popen(SENDMAIL, "w")
280279
p.write(mailtext)
281280
sts = p.close()

Demo/pdist/sumtree.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import time
2+
import sys
23
import FSProxy
34

45
def main():
@@ -9,7 +10,9 @@ def main():
910
proxy._close()
1011
t2 = time.time()
1112
print t2-t1, "seconds"
12-
raw_input("[Return to exit] ")
13+
sys.stdout.write("[Return to exit] ")
14+
sys.stdout.flush()
15+
sys.stdin.readline()
1316

1417
def sumtree(proxy):
1518
print "PWD =", proxy.pwd()

Demo/scripts/unbirthday.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
import time
1010
import calendar
1111

12+
def raw_input(prompt):
13+
sys.stdout.write(prompt)
14+
sys.stdout.flush()
15+
return sys.stdin.readline()
16+
1217
def main():
1318
# Note that the range checks below also check for bad types,
1419
# e.g. 3.14 or (). However syntactically invalid replies

Demo/sockets/ftp.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ def getdata(r):
130130
sys.stdout.write(data)
131131
print '(end of data connection)'
132132

133+
def raw_input(prompt):
134+
sys.stdout.write(prompt)
135+
sys.stdout.flush()
136+
return sys.stdin.readline()
137+
133138
# Get a command from the user.
134139
#
135140
def getcommand():
@@ -143,4 +148,5 @@ def getcommand():
143148

144149
# Call the main program.
145150
#
146-
main()
151+
if __name__ == '__main__':
152+
main()

Demo/sockets/gopher.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#
55
# Usage: gopher [ [selector] host [port] ]
66

7-
import string
87
import sys
98
import os
109
import socket
@@ -42,7 +41,7 @@ def open_socket(host, port):
4241
if not port:
4342
port = DEF_PORT
4443
elif type(port) == type(''):
45-
port = string.atoi(port)
44+
port = int(port)
4645
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
4746
s.connect((host, port))
4847
return s
@@ -73,7 +72,7 @@ def get_menu(selector, host, port):
7372
print '(Empty line from server)'
7473
continue
7574
typechar = line[0]
76-
parts = string.splitfields(line[1:], TAB)
75+
parts = line[1:].split(TAB)
7776
if len(parts) < 4:
7877
print '(Bad line from server: %r)' % (line,)
7978
continue
@@ -160,7 +159,7 @@ def browse_menu(selector, host, port):
160159
for i in range(len(list)):
161160
item = list[i]
162161
typechar, description = item[0], item[1]
163-
print string.rjust(repr(i+1), 3) + ':', description,
162+
print repr(i+1).rjust(3) + ':', description,
164163
if typename.has_key(typechar):
165164
print typename[typechar]
166165
else:
@@ -175,8 +174,8 @@ def browse_menu(selector, host, port):
175174
if not str:
176175
return
177176
try:
178-
choice = string.atoi(str)
179-
except string.atoi_error:
177+
choice = int(str)
178+
except ValueError:
180179
print 'Choice must be a number; try again:'
181180
continue
182181
if not 0 < choice <= len(list):
@@ -218,6 +217,11 @@ def browse_textfile(selector, host, port):
218217
print 'IOError:', msg
219218
x.close()
220219

220+
def raw_input(prompt):
221+
sys.stdout.write(prompt)
222+
sys.stdout.flush()
223+
return sys.stdin.readline()
224+
221225
# Browse a search index
222226
def browse_search(selector, host, port):
223227
while 1:
@@ -230,7 +234,7 @@ def browse_search(selector, host, port):
230234
except EOFError:
231235
print
232236
break
233-
query = string.strip(query)
237+
query = query.strip()
234238
if not query:
235239
break
236240
if '\t' in query:
@@ -300,11 +304,11 @@ def open_savefile():
300304
except EOFError:
301305
print
302306
return None
303-
savefile = string.strip(savefile)
307+
savefile = savefile.strip()
304308
if not savefile:
305309
return None
306310
if savefile[0] == '|':
307-
cmd = string.strip(savefile[1:])
311+
cmd = savefile[1:].strip()
308312
try:
309313
p = os.popen(cmd, 'w')
310314
except IOError, msg:
@@ -331,10 +335,10 @@ def test():
331335
browser(sys.argv[1], sys.argv[2], sys.argv[3])
332336
elif sys.argv[2:]:
333337
try:
334-
port = string.atoi(sys.argv[2])
338+
port = int(sys.argv[2])
335339
selector = ''
336340
host = sys.argv[1]
337-
except string.atoi_error:
341+
except ValueError:
338342
selector = sys.argv[1]
339343
host = sys.argv[2]
340344
port = ''

Demo/tkinter/guido/wish.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import _tkinter
44
import os
5+
import sys
56

67
tk = _tkinter.create(os.environ['DISPLAY'], 'wish', 'Tk', 1)
78
tk.call('update')
@@ -12,7 +13,9 @@
1213
if cmd: prompt = ''
1314
else: prompt = '% '
1415
try:
15-
line = raw_input(prompt)
16+
sys.stdout.write(prompt)
17+
sys.stdout.flush()
18+
line = sys.stdin.readline()
1619
except EOFError:
1720
break
1821
cmd = cmd + (line + '\n')

Doc/lib/libcmd.tex

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -186,13 +186,3 @@ \subsection{Cmd Objects}
186186
headers. If empty, no ruler line is drawn. It defaults to
187187
\character{=}.
188188
\end{memberdesc}
189-
190-
\begin{memberdesc}{use_rawinput}
191-
A flag, defaulting to true. If true, \method{cmdloop()} uses
192-
\function{raw_input()} to display a prompt and read the next command;
193-
if false, \method{sys.stdout.write()} and
194-
\method{sys.stdin.readline()} are used. (This means that by
195-
importing \refmodule{readline}, on systems that support it, the
196-
interpreter will automatically support \program{Emacs}-like line editing
197-
and command-history keystrokes.)
198-
\end{memberdesc}

Doc/lib/libcode.tex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ \subsection{Interactive Console Objects
167167
\begin{methoddesc}{raw_input}{\optional{prompt}}
168168
Write a prompt and read a line. The returned line does not include
169169
the trailing newline. When the user enters the \EOF{} key sequence,
170-
\exception{EOFError} is raised. The base implementation uses the
171-
built-in function \function{raw_input()}; a subclass may replace this
170+
\exception{EOFError} is raised. The base implementation reads from
171+
\code{sys.stdin}; a subclass may replace this
172172
with a different implementation.
173173
\end{methoddesc}

0 commit comments

Comments
 (0)