comparison mercurial/hgweb/hgweb_mod.py @ 36876:97f44b0720e2

hgweb: port archive command to modern response API Well, I tried to go with PEP 3333's recommendations and only allow our WSGI application to emit data via a response generator. Unfortunately, the "archive" command calls into the zipfile and tarfile modules and these operator on file objects and must send their data to an object with write(). There's no easy way turn these write() calls into a generator. So, we teach our response type how to expose a file object like object that can be used to write() output. We try to keep the API consistent with how things work currently: callers must call a setbody*(), then sendresponse() to trigger sending of headers, and only then can they get a handle on the object to perform writing. This required overloading the return value of @webcommand functions even more. Fortunately, we're almost completely ported off the legacy API. So we should be able to simplify matters in the near future. A test relying on this functionality has also been updated to use the new API. Differential Revision: https://phab.mercurial-scm.org/D2792
author Gregory Szorc <gregory.szorc@gmail.com>
date Sat, 10 Mar 2018 20:16:20 -0800
parents 89002d07a114
children 02bea04b4c54
comparison
equal deleted inserted replaced
36875:16499427f6de 36876:97f44b0720e2
406 res.headers['Content-Type'] = ctype 406 res.headers['Content-Type'] = ctype
407 content = getattr(webcommands, cmd)(rctx, wsgireq, tmpl) 407 content = getattr(webcommands, cmd)(rctx, wsgireq, tmpl)
408 408
409 if content is res: 409 if content is res:
410 return res.sendresponse() 410 return res.sendresponse()
411 411 elif content is True:
412 wsgireq.respond(HTTP_OK, ctype) 412 return []
413 413 else:
414 return content 414 wsgireq.respond(HTTP_OK, ctype)
415 return content
415 416
416 except (error.LookupError, error.RepoLookupError) as err: 417 except (error.LookupError, error.RepoLookupError) as err:
417 wsgireq.respond(HTTP_NOT_FOUND, ctype) 418 wsgireq.respond(HTTP_NOT_FOUND, ctype)
418 msg = pycompat.bytestr(err) 419 msg = pycompat.bytestr(err)
419 if (util.safehasattr(err, 'name') and 420 if (util.safehasattr(err, 'name') and