44#
55# Usage: gopher [ [selector] host [port] ]
66
7- import string
87import sys
98import os
109import 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
222226def 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 = ''
0 commit comments