Mercurial > hg
changeset 2467:4e78dc71d946
http client: better work with authorization errors, broken sockets.
author | Vadim Gelfer <vadim.gelfer@gmail.com> |
---|---|
date | Tue, 20 Jun 2006 15:23:54 -0700 |
parents | e10665147d26 |
children | 1ac0574f1768 |
files | mercurial/httprepo.py |
diffstat | 1 files changed, 20 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/httprepo.py Tue Jun 20 15:23:01 2006 -0700 +++ b/mercurial/httprepo.py Tue Jun 20 15:23:54 2006 -0700 @@ -10,7 +10,7 @@ from i18n import gettext as _ from demandload import * demandload(globals(), "hg os urllib urllib2 urlparse zlib util httplib") -demandload(globals(), "keepalive tempfile socket") +demandload(globals(), "errno keepalive tempfile socket") class passwordmgr(urllib2.HTTPPasswordMgrWithDefaultRealm): def __init__(self, ui): @@ -192,6 +192,10 @@ cu = "%s?%s" % (self.url, qs) try: resp = urllib2.urlopen(urllib2.Request(cu, data, headers)) + except urllib2.HTTPError, inst: + if inst.code == 401: + raise util.Abort(_('authorization failed')) + raise except httplib.HTTPException, inst: self.ui.debug(_('http error while sending %s command\n') % cmd) self.ui.print_exc() @@ -278,17 +282,22 @@ for chunk in util.filechunkiter(cg): fp.write(chunk) length = fp.tell() - rfp = self.do_cmd( - 'unbundle', data=fp, - headers={'content-length': length, - 'content-type': 'application/octet-stream'}, - heads=' '.join(map(hex, heads))) try: - ret = int(rfp.readline()) - self.ui.write(rfp.read()) - return ret - finally: - rfp.close() + rfp = self.do_cmd( + 'unbundle', data=fp, + headers={'content-length': length, + 'content-type': 'application/octet-stream'}, + heads=' '.join(map(hex, heads))) + try: + ret = int(rfp.readline()) + self.ui.write(rfp.read()) + return ret + finally: + rfp.close() + except socket.error, err: + if err[0] in (errno.ECONNRESET, errno.EPIPE): + raise util.Abort(_('push failed: %s'), err[1]) + raise util.Abort(err[1]) finally: fp.close() os.unlink(tempname)