comparison mercurial/hgweb/hgwebdir_mod.py @ 6796:943f066c0d58

Backed out changeset 4879468fa28f (incorrect Content-Length on Windows)
author Dirkjan Ochtman <dirkjan@ochtman.nl>
date Wed, 02 Jul 2008 12:02:33 +0200
parents 4879468fa28f
children 8909070fd05e
comparison
equal deleted inserted replaced
6785:4879468fa28f 6796:943f066c0d58
68 import mercurial.hgweb.wsgicgi as wsgicgi 68 import mercurial.hgweb.wsgicgi as wsgicgi
69 wsgicgi.launch(self) 69 wsgicgi.launch(self)
70 70
71 def __call__(self, env, respond): 71 def __call__(self, env, respond):
72 req = wsgirequest(env, respond) 72 req = wsgirequest(env, respond)
73 return self.run_wsgi(req) 73 self.run_wsgi(req)
74 return req
74 75
75 def run_wsgi(self, req): 76 def run_wsgi(self, req):
76 77
77 try: 78 try:
78 try: 79 try:
87 static = os.path.join(templater.templatepath(), 'static') 88 static = os.path.join(templater.templatepath(), 'static')
88 if virtual.startswith('static/'): 89 if virtual.startswith('static/'):
89 fname = virtual[7:] 90 fname = virtual[7:]
90 else: 91 else:
91 fname = req.form['static'][0] 92 fname = req.form['static'][0]
92 return staticfile(static, fname, req), 93 req.write(staticfile(static, fname, req))
94 return
93 95
94 # top-level index 96 # top-level index
95 elif not virtual: 97 elif not virtual:
96 req.respond(HTTP_OK, ctype) 98 req.respond(HTTP_OK, ctype)
97 return ''.join(self.makeindex(req, tmpl)), 99 req.write(self.makeindex(req, tmpl))
100 return
98 101
99 # nested indexes and hgwebs 102 # nested indexes and hgwebs
100 103
101 repos = dict(self.repos) 104 repos = dict(self.repos)
102 while virtual: 105 while virtual:
103 real = repos.get(virtual) 106 real = repos.get(virtual)
104 if real: 107 if real:
105 req.env['REPO_NAME'] = virtual 108 req.env['REPO_NAME'] = virtual
106 try: 109 try:
107 repo = hg.repository(self.parentui, real) 110 repo = hg.repository(self.parentui, real)
108 return hgweb(repo).run_wsgi(req) 111 hgweb(repo).run_wsgi(req)
112 return
109 except IOError, inst: 113 except IOError, inst:
110 msg = inst.strerror 114 msg = inst.strerror
111 raise ErrorResponse(HTTP_SERVER_ERROR, msg) 115 raise ErrorResponse(HTTP_SERVER_ERROR, msg)
112 except RepoError, inst: 116 except RepoError, inst:
113 raise ErrorResponse(HTTP_SERVER_ERROR, str(inst)) 117 raise ErrorResponse(HTTP_SERVER_ERROR, str(inst))
114 118
115 # browse subdirectories 119 # browse subdirectories
116 subdir = virtual + '/' 120 subdir = virtual + '/'
117 if [r for r in repos if r.startswith(subdir)]: 121 if [r for r in repos if r.startswith(subdir)]:
118 req.respond(HTTP_OK, ctype) 122 req.respond(HTTP_OK, ctype)
119 return ''.join(self.makeindex(req, tmpl, subdir)), 123 req.write(self.makeindex(req, tmpl, subdir))
124 return
120 125
121 up = virtual.rfind('/') 126 up = virtual.rfind('/')
122 if up < 0: 127 if up < 0:
123 break 128 break
124 virtual = virtual[:up] 129 virtual = virtual[:up]
125 130
126 # prefixes not found 131 # prefixes not found
127 req.respond(HTTP_NOT_FOUND, ctype) 132 req.respond(HTTP_NOT_FOUND, ctype)
128 return ''.join(tmpl("notfound", repo=virtual)), 133 req.write(tmpl("notfound", repo=virtual))
129 134
130 except ErrorResponse, err: 135 except ErrorResponse, err:
131 req.respond(err.code, ctype) 136 req.respond(err.code, ctype)
132 return ''.join(tmpl('error', error=err.message or '')), 137 req.write(tmpl('error', error=err.message or ''))
133 finally: 138 finally:
134 tmpl = None 139 tmpl = None
135 140
136 def makeindex(self, req, tmpl, subdir=""): 141 def makeindex(self, req, tmpl, subdir=""):
137 142