mirror of
https://github.com/facebook/sapling.git
synced 2024-10-07 23:38:50 +03:00
hgweb: return content iterator instead of using write() callable
This commit is contained in:
parent
d50a34e7a6
commit
35c3380f04
@ -169,20 +169,20 @@ class hgweb(object):
|
||||
|
||||
req.write(content)
|
||||
del tmpl
|
||||
return req
|
||||
return ''.join(content),
|
||||
|
||||
except revlog.LookupError, err:
|
||||
req.respond(HTTP_NOT_FOUND, ctype)
|
||||
msg = str(err)
|
||||
if 'manifest' not in msg:
|
||||
msg = 'revision not found: %s' % err.name
|
||||
req.write(tmpl('error', error=msg))
|
||||
return ''.join(tmpl('error', error=msg)),
|
||||
except (RepoError, revlog.RevlogError), inst:
|
||||
req.respond(HTTP_SERVER_ERROR, ctype)
|
||||
req.write(tmpl('error', error=str(inst)))
|
||||
return ''.join(tmpl('error', error=str(inst))),
|
||||
except ErrorResponse, inst:
|
||||
req.respond(inst.code, ctype)
|
||||
req.write(tmpl('error', error=inst.message))
|
||||
return ''.join(tmpl('error', error=inst.message)),
|
||||
|
||||
def templater(self, req):
|
||||
|
||||
|
@ -70,8 +70,7 @@ class hgwebdir(object):
|
||||
|
||||
def __call__(self, env, respond):
|
||||
req = wsgirequest(env, respond)
|
||||
self.run_wsgi(req)
|
||||
return req
|
||||
return self.run_wsgi(req)
|
||||
|
||||
def run_wsgi(self, req):
|
||||
|
||||
@ -90,14 +89,12 @@ class hgwebdir(object):
|
||||
fname = virtual[7:]
|
||||
else:
|
||||
fname = req.form['static'][0]
|
||||
req.write(staticfile(static, fname, req))
|
||||
return
|
||||
return staticfile(static, fname, req),
|
||||
|
||||
# top-level index
|
||||
elif not virtual:
|
||||
req.respond(HTTP_OK, ctype)
|
||||
req.write(self.makeindex(req, tmpl))
|
||||
return
|
||||
return ''.join(self.makeindex(req, tmpl)),
|
||||
|
||||
# nested indexes and hgwebs
|
||||
|
||||
@ -108,8 +105,7 @@ class hgwebdir(object):
|
||||
req.env['REPO_NAME'] = virtual
|
||||
try:
|
||||
repo = hg.repository(self.parentui, real)
|
||||
hgweb(repo).run_wsgi(req)
|
||||
return
|
||||
return hgweb(repo).run_wsgi(req)
|
||||
except IOError, inst:
|
||||
msg = inst.strerror
|
||||
raise ErrorResponse(HTTP_SERVER_ERROR, msg)
|
||||
@ -120,8 +116,7 @@ class hgwebdir(object):
|
||||
subdir = virtual + '/'
|
||||
if [r for r in repos if r.startswith(subdir)]:
|
||||
req.respond(HTTP_OK, ctype)
|
||||
req.write(self.makeindex(req, tmpl, subdir))
|
||||
return
|
||||
return ''.join(self.makeindex(req, tmpl, subdir)),
|
||||
|
||||
up = virtual.rfind('/')
|
||||
if up < 0:
|
||||
@ -130,11 +125,11 @@ class hgwebdir(object):
|
||||
|
||||
# prefixes not found
|
||||
req.respond(HTTP_NOT_FOUND, ctype)
|
||||
req.write(tmpl("notfound", repo=virtual))
|
||||
return ''.join(tmpl("notfound", repo=virtual)),
|
||||
|
||||
except ErrorResponse, err:
|
||||
req.respond(err.code, ctype)
|
||||
req.write(tmpl('error', error=err.message or ''))
|
||||
return ''.join(tmpl('error', error=err.message or '')),
|
||||
finally:
|
||||
tmpl = None
|
||||
|
||||
|
@ -43,15 +43,17 @@ env = {
|
||||
|
||||
output = StringIO()
|
||||
env['QUERY_STRING'] = 'style=atom'
|
||||
hgweb('.', name = 'repo')(env, startrsp)
|
||||
print output.getvalue()
|
||||
content = hgweb('.', name = 'repo')(env, startrsp)
|
||||
sys.stdout.write(output.getvalue())
|
||||
sys.stdout.write(''.join(content))
|
||||
print '---- ERRORS'
|
||||
print errors.getvalue()
|
||||
|
||||
output = StringIO()
|
||||
env['QUERY_STRING'] = 'style=raw'
|
||||
hgwebdir({'repo': '.'})(env, startrsp)
|
||||
print output.getvalue()
|
||||
content = hgwebdir({'repo': '.'})(env, startrsp)
|
||||
sys.stdout.write(output.getvalue())
|
||||
sys.stdout.write(''.join(content))
|
||||
print '---- ERRORS'
|
||||
print errors.getvalue()
|
||||
EOF
|
||||
|
@ -35,7 +35,6 @@ summary: test
|
||||
</entry>
|
||||
|
||||
</feed>
|
||||
|
||||
---- ERRORS
|
||||
|
||||
---- HEADERS
|
||||
@ -45,6 +44,5 @@ summary: test
|
||||
|
||||
repo/
|
||||
|
||||
|
||||
---- ERRORS
|
||||
|
||||
|
@ -44,32 +44,36 @@ env = {
|
||||
output = StringIO()
|
||||
env['PATH_INFO'] = '/'
|
||||
env['QUERY_STRING'] = 'style=atom'
|
||||
hgweb('.', name = 'repo')(env, startrsp)
|
||||
print output.getvalue()
|
||||
content = hgweb('.', name = 'repo')(env, startrsp)
|
||||
sys.stdout.write(output.getvalue())
|
||||
sys.stdout.write(''.join(content))
|
||||
print '---- ERRORS'
|
||||
print errors.getvalue()
|
||||
|
||||
output = StringIO()
|
||||
env['PATH_INFO'] = '/file/tip/'
|
||||
env['QUERY_STRING'] = 'style=raw'
|
||||
hgweb('.', name = 'repo')(env, startrsp)
|
||||
print output.getvalue()
|
||||
content = hgweb('.', name = 'repo')(env, startrsp)
|
||||
sys.stdout.write(output.getvalue())
|
||||
sys.stdout.write(''.join(content))
|
||||
print '---- ERRORS'
|
||||
print errors.getvalue()
|
||||
|
||||
output = StringIO()
|
||||
env['PATH_INFO'] = '/'
|
||||
env['QUERY_STRING'] = 'style=raw'
|
||||
hgwebdir({'repo': '.'})(env, startrsp)
|
||||
print output.getvalue()
|
||||
content = hgwebdir({'repo': '.'})(env, startrsp)
|
||||
sys.stdout.write(output.getvalue())
|
||||
sys.stdout.write(''.join(content))
|
||||
print '---- ERRORS'
|
||||
print errors.getvalue()
|
||||
|
||||
output = StringIO()
|
||||
env['PATH_INFO'] = '/repo/file/tip/'
|
||||
env['QUERY_STRING'] = 'style=raw'
|
||||
hgwebdir({'repo': '.'})(env, startrsp)
|
||||
print output.getvalue()
|
||||
content = hgwebdir({'repo': '.'})(env, startrsp)
|
||||
sys.stdout.write(output.getvalue())
|
||||
sys.stdout.write(''.join(content))
|
||||
print '---- ERRORS'
|
||||
print errors.getvalue()
|
||||
EOF
|
||||
|
@ -35,7 +35,6 @@ summary: test
|
||||
</entry>
|
||||
|
||||
</feed>
|
||||
|
||||
---- ERRORS
|
||||
|
||||
---- HEADERS
|
||||
@ -46,7 +45,6 @@ summary: test
|
||||
-rw-r--r-- 4 bar
|
||||
|
||||
|
||||
|
||||
---- ERRORS
|
||||
|
||||
---- HEADERS
|
||||
@ -56,7 +54,6 @@ summary: test
|
||||
|
||||
/repo/
|
||||
|
||||
|
||||
---- ERRORS
|
||||
|
||||
---- HEADERS
|
||||
@ -67,6 +64,5 @@ summary: test
|
||||
-rw-r--r-- 4 bar
|
||||
|
||||
|
||||
|
||||
---- ERRORS
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user