GIF89a; EcchiShell v1.0
//lib64/lib64/lib64/python2.7/Demo/sockets/

type(''): port = repr(port) sts = os.system('set -x; exec telnet ' + host + ' ' + port) if sts: print 'Exit status:', sts # "Browse" a binary file, i.e. save it to a file def browse_binary(selector, host, port): f = open_savefile() if not f: return x = SaveWithProgress(f) get_alt_binary(selector, host, port, x.write, 8*1024) x.close() # "Browse" a sound file, i.e. play it or save it def browse_sound(selector, host, port): browse_binary(selector, host, port) # Dictionary mapping types to browser functions typebrowser = {'0': browse_textfile, '1': browse_menu, \ '4': browse_binary, '5': browse_binary, '6': browse_textfile, \ '7': browse_search, \ '8': browse_telnet, '9': browse_binary, 's': browse_sound} # Class used to save lines, appending a newline to each line class SaveLines: def __init__(self, f): self.f = f def writeln(self, line): self.f.write(line + '\n') def close(self): sts = self.f.close() if sts: print 'Exit status:', sts # Class used to save data while showing progress class SaveWithProgress: def __init__(self, f): self.f = f def write(self, data): sys.stdout.write('#') sys.stdout.flush() self.f.write(data) def close(self): print sts = self.f.close() if sts: print 'Exit status:', sts # Ask for and open a save file, or return None if not to save def open_savefile(): try: savefile = raw_input( \ 'Save as file [CR == don\'t save; |pipeline or ~user/... OK]: ') except EOFError: print return None savefile = string.strip(savefile) if not savefile: return None if savefile[0] == '|': cmd = string.strip(savefile[1:]) try: p = os.popen(cmd, 'w') except IOError, msg: print repr(cmd), ':', msg return None print 'Piping through', repr(cmd), '...' return p if savefile[0] == '~': savefile = os.path.expanduser(savefile) try: f = open(savefile, 'w') except IOError, msg: print repr(savefile), ':', msg return None print 'Saving to', repr(savefile), '...' return f # Test program def test(): if sys.argv[4:]: print 'usage: gopher [ [selector] host [port] ]' sys.exit(2) elif sys.argv[3:]: browser(sys.argv[1], sys.argv[2], sys.argv[3]) elif sys.argv[2:]: try: port = string.atoi(sys.argv[2]) selector = '' host = sys.argv[1] except string.atoi_error: selector = sys.argv[1] host = sys.argv[2] port = '' browser(selector, host, port) elif sys.argv[1:]: browser('', sys.argv[1]) else: browser() # Call the test program as a main program test()