gopher.py 文件源码

python
阅读 30 收藏 0 点赞 0 评论 0

项目:python2-tracer 作者: extremecoders-re 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号