Mercurial > public > mercurial-scm > hg
diff mercurial/hgweb/protocol.py @ 14614:afccc64eea73
ui: use I/O descriptors internally
and as a result:
- fix webproto to redirect the ui descriptors instead of sys.stdout/err
- fix sshserver to use the ui descriptors
author | Idan Kamara <idankk86@gmail.com> |
---|---|
date | Wed, 08 Jun 2011 01:39:20 +0300 |
parents | 1ffeeb91c55d |
children | f4522df38c65 |
line wrap: on
line diff
--- a/mercurial/hgweb/protocol.py Tue Jun 07 13:39:09 2011 +0300 +++ b/mercurial/hgweb/protocol.py Wed Jun 08 01:39:20 2011 +0300 @@ -5,16 +5,17 @@ # This software may be used and distributed according to the terms of the # GNU General Public License version 2 or any later version. -import cgi, cStringIO, zlib, sys, urllib +import cgi, cStringIO, zlib, urllib from mercurial import util, wireproto from common import HTTP_OK HGTYPE = 'application/mercurial-0.1' class webproto(object): - def __init__(self, req): + def __init__(self, req, ui): self.req = req self.response = '' + self.ui = ui def getargs(self, args): knownargs = self._args() data = {} @@ -46,8 +47,12 @@ for s in util.filechunkiter(self.req, limit=length): fp.write(s) def redirect(self): - self.oldio = sys.stdout, sys.stderr - sys.stderr = sys.stdout = cStringIO.StringIO() + self.oldio = self.ui.fout, self.ui.ferr + self.ui.ferr = self.ui.fout = cStringIO.StringIO() + def restore(self): + val = self.ui.fout.getvalue() + self.ui.ferr, self.ui.fout = self.oldio + return val def groupchunks(self, cg): z = zlib.compressobj() while True: @@ -66,7 +71,7 @@ return cmd in wireproto.commands def call(repo, req, cmd): - p = webproto(req) + p = webproto(req, repo.ui) rsp = wireproto.dispatch(repo, p, cmd) if isinstance(rsp, str): req.respond(HTTP_OK, HGTYPE, length=len(rsp)) @@ -75,14 +80,13 @@ req.respond(HTTP_OK, HGTYPE) return rsp.gen elif isinstance(rsp, wireproto.pushres): - val = sys.stdout.getvalue() - sys.stdout, sys.stderr = p.oldio + val = p.restore() req.respond(HTTP_OK, HGTYPE) return ['%d\n%s' % (rsp.res, val)] elif isinstance(rsp, wireproto.pusherr): # drain the incoming bundle req.drain() - sys.stdout, sys.stderr = p.oldio + p.restore() rsp = '0\n%s\n' % rsp.res req.respond(HTTP_OK, HGTYPE, length=len(rsp)) return [rsp]