def browse_menu(selector, host, port):
list = get_menu(selector, host, port)
while 1:
print '----- MENU -----'
print 'Selector:', repr(selector)
print 'Host:', host, ' Port:', port
print
for i in range(len(list)):
item = list[i]
typechar, description = item[0], item[1]
print string.rjust(repr(i+1), 3) + ':', description,
if typename.has_key(typechar):
print typename[typechar]
else:
print '<TYPE=' + repr(typechar) + '>'
print
while 1:
try:
str = raw_input('Choice [CR == up a level]: ')
except EOFError:
print
return
if not str:
return
try:
choice = string.atoi(str)
except string.atoi_error:
print 'Choice must be a number; try again:'
continue
if not 0 < choice <= len(list):
print 'Choice out of range; try again:'
continue
break
item = list[choice-1]
typechar = item[0]
[i_selector, i_host, i_port] = item[2:5]
if typebrowser.has_key(typechar):
browserfunc = typebrowser[typechar]
try:
browserfunc(i_selector, i_host, i_port)
except (IOError, socket.error):
print '***', sys.exc_type, ':', sys.exc_value
else:
print 'Unsupported object type'
# Browse a text file