def telnet(self, addr): scheme, host, port, path, search, anchor = \ wwwlib.parse_addr(addr) if scheme <> 'telnet': print 'Not a telnet address' return cmd = 'telnet ' + host cmd = 'xterm -e ' + cmd + ' &' sts = os.system(cmd) if sts: print `cmd` print 'Exit status:', sts
def telnet(self, addr): scheme, host, port, path, search, anchor = \ wwwlib.parse_addr(addr) if scheme <> 'telnet': print 'Not a telnet address' return cmd = 'telnet ' + host cmd = 'xterm -e ' + cmd + ' &' sts = os.system(cmd) if sts: print ` cmd ` print 'Exit status:', sts
def do_find(self, arg): if not self.cur_isindex: print '*** Not an index' return words = string.split(arg) if not words: print '*** What do you want to find?' return scheme, host, port, path, search, anchor = \ wwwlib.parse_addr(self.cur_addr) search = '?' + string.joinfields(words, '+') addr = wwwlib.unparse_addr(scheme,host,port,path,search,'') self.follow(addr)
def key_i(self): # find keyword in index try: reply = stdwin.askstr('Find keyword(s) in index:', '') except KeyboardInterrupt: return words = string.split(reply) if not words: return scheme, host, port, path, search, anchor = \ wwwlib.parse_addr(self.cur_addr) if len(search) > 1: hist = H_NOP else: hist = H_PUSH search = '?' + string.joinfields(words, '+') addr = wwwlib.unparse_addr(scheme,host,port,path,search,'') self.follow(addr, hist)
def key_i(self): # find keyword in index try: reply = stdwin.askstr('Find keyword(s) in index:', '') except KeyboardInterrupt: return words = string.split(reply) if not words: return scheme, host, port, path, search, anchor = \ wwwlib.parse_addr(self.cur_addr) if len(search) > 1: hist = H_NOP else: hist = H_PUSH search = '?' + string.joinfields(words, '+') addr = wwwlib.unparse_addr(scheme, host, port, path, search, '') self.follow(addr, hist)
def serve(s, client): log('connection from', client) request = s.recv(1024) key = request[:4] if string.lower(key) <> 'get ': log('bad request from', client, ` request ` [:40]) return if request[-1:] == '\n': request = request[:-1] if request[-1:] == '\r': request = request[:-1] addr = string.strip(request[4:]) scheme, host, port, path, search, anchor = wwwlib.parse_addr(addr) if scheme and scheme <> 'http': log('request bad scheme from', client, 'in', ` addr `) s.send('Bad scheme in requested address\n') return if host and host <> thishost: log('request bad host from', client, 'in', ` addr `) s.send('Non-local host in requested address\n') return if port and port <> ` thisport `: log('request bad port from', client, 'in', ` addr `) s.send('Unexpected host in requested address\n') return if search: log('request with search key from', client, 'in', ` addr `) s.send('Search key not supported by this server\n') return while path[:1] == '/': path = path[1:] path = os.path.normpath(path) if path[:1] == '.': log('request illegal path from', client, 'in', ` addr `) s.send('Illegal path in requested address\n') return path = thisdir + path if not os.path.isfile(path): log('request non-file path from', client, 'in', ` addr `) s.send('Invalid path in requested address\n') return try: f = open(path, 'r') except IOError, msg: log('IOError', msg, 'opening', path, 'for', client) s.send('Access violation in requested address\n') return
def serve(input, output, client): request = input.readline() if request[-1:] == '\n': request = request[:-1] if request[-1:] == '\r': request = request[:-1] words = string.split(request) if len(words) < 2 or string.lower(words[0]) <> 'get': log('bad request from', client, ` request ` [:40]) return addr = words[1] scheme, host, port, path, search, anchor = wwwlib.parse_addr(addr) if scheme and scheme <> 'http': log('request bad scheme from', client, 'in', ` addr `) output.write('Bad scheme in requested address\n') return if host and host <> thishost: log('request bad host from', client, 'in', ` addr `) output.write('Non-local host in requested address\n') return if port and port <> ` thisport `: log('request bad port from', client, 'in', ` addr `) output.write('Unexpected host in requested address\n') return if search: log('request with search key from', client, 'in', ` addr `) output.write('Search key not supported by this server\n') return while path[:1] == '/': path = path[1:] path = os.path.normpath(path) if path[:1] == '.': log('request illegal path from', client, 'in', ` addr `) output.write('Illegal path in requested address\n') return path = DIR + path if not os.path.isfile(path): log('request non-file path from', client, 'in', ` addr `) output.write('Invalid path in requested address\n') return try: f = open(path, 'r') except IOError, msg: log('IOError', str(msg), 'opening', path, 'for', client) output.write('Access violation in requested address\n') return
def serve(s, client): log('connection from', client) request = s.recv(1024) key = request[:4] if string.lower(key) <> 'get ': log('bad request from', client, `request`[:40]) return if request[-1:] == '\n': request = request[:-1] if request[-1:] == '\r': request = request[:-1] addr = string.strip(request[4:]) scheme, host, port, path, search, anchor = wwwlib.parse_addr(addr) if scheme and scheme <> 'http': log('request bad scheme from', client, 'in', `addr`) s.send('Bad scheme in requested address\n') return if host and host <> thishost: log('request bad host from', client, 'in', `addr`) s.send('Non-local host in requested address\n') return if port and port <> `thisport`: log('request bad port from', client, 'in', `addr`) s.send('Unexpected host in requested address\n') return if search: log('request with search key from', client, 'in', `addr`) s.send('Search key not supported by this server\n') return while path[:1] == '/': path = path[1:] path = os.path.normpath(path) if path[:1] == '.': log('request illegal path from', client, 'in', `addr`) s.send('Illegal path in requested address\n') return path = thisdir + path if not os.path.isfile(path): log('request non-file path from', client, 'in', `addr`) s.send('Invalid path in requested address\n') return try: f = open(path, 'r') except IOError, msg: log('IOError', msg, 'opening', path, 'for', client) s.send('Access violation in requested address\n') return
import dbm import string import sys import wwwlib import regex done = dbm.open('@done', 'r', 0) addrlist = done.keys() print 'Found', len(addrlist), 'documents' byhost = {} for addr in addrlist: scheme, host, port, path, search, anchor = \ wwwlib.parse_addr(addr) if not byhost.has_key(host): byhost[host] = [] byhost[host].append(addr) print 'Found', len(byhost), 'hosts' hosts = byhost.keys() for i in range(len(hosts)): parts = string.splitfields(hosts[i], '.') parts.reverse() hosts[i] = parts hosts.sort() for i in range(len(hosts)): parts = hosts[i] parts.reverse()