comparison mercurial/hgweb.py @ 1120:df25ee778ac2

Handle a nonexistent repository with a 404 error. Based on changeset 62ea868cafbfa3acb7e5dba6982ecb46a1637246 from Vincent Wagelaar <vincent@ricardis.tudelft.nl> in http://hannibal.lr-s.tudelft.nl/~vincent/fcgi
author Ollivier Robert <roberto@keltia.freenix.fr>
date Sat, 27 Aug 2005 23:43:08 -0700
parents 7fca9752d945
children 14a69c4988cd
comparison
equal deleted inserted replaced
1119:7fca9752d945 1120:df25ee778ac2
66 sys.stdout.write('Content-disposition: attachment; filename=%s\n' 66 sys.stdout.write('Content-disposition: attachment; filename=%s\n'
67 % file) 67 % file)
68 if size > 0: 68 if size > 0:
69 sys.stdout.write('Content-length: %d\n' % size) 69 sys.stdout.write('Content-length: %d\n' % size)
70 sys.stdout.write('\n') 70 sys.stdout.write('\n')
71
72 def httpnotfound(filename):
73 sys.stdout.write("Status: 404\r\n\r\n")
74 sys.stdout.write("File not found: (%s)" % (filename, ))
71 75
72 def write(*things): 76 def write(*things):
73 for thing in things: 77 for thing in things:
74 if hasattr(thing, "__iter__"): 78 if hasattr(thing, "__iter__"):
75 for part in thing: 79 for part in thing:
936 try: 940 try:
937 virtual = os.environ["PATH_INFO"] 941 virtual = os.environ["PATH_INFO"]
938 except: 942 except:
939 virtual = "" 943 virtual = ""
940 944
941 if virtual[1:]: 945 virtual = virtual.strip('/')
942 if self.cp.has_option("paths", virtual[1:]): 946
943 real = self.cp.get("paths", virtual[1:]) 947 if len(virtual):
948 try:
949 real = self.cp.get("paths", virtual)
944 h = hgweb(real) 950 h = hgweb(real)
945 h.run() 951 h.run()
952 return
953 except NoOptionError:
954 httpnotfound(virtual)
946 return 955 return
947 956
948 def header(**map): 957 def header(**map):
949 yield tmpl("header", **map) 958 yield tmpl("header", **map)
950 959