comparison mercurial/httprepo.py @ 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 c91118f425d0
children eabcda3ed0dd
comparison
equal deleted inserted replaced
2466:e10665147d26 2467:4e78dc71d946
8 from node import * 8 from node import *
9 from remoterepo import * 9 from remoterepo import *
10 from i18n import gettext as _ 10 from i18n import gettext as _
11 from demandload import * 11 from demandload import *
12 demandload(globals(), "hg os urllib urllib2 urlparse zlib util httplib") 12 demandload(globals(), "hg os urllib urllib2 urlparse zlib util httplib")
13 demandload(globals(), "keepalive tempfile socket") 13 demandload(globals(), "errno keepalive tempfile socket")
14 14
15 class passwordmgr(urllib2.HTTPPasswordMgrWithDefaultRealm): 15 class passwordmgr(urllib2.HTTPPasswordMgrWithDefaultRealm):
16 def __init__(self, ui): 16 def __init__(self, ui):
17 urllib2.HTTPPasswordMgrWithDefaultRealm.__init__(self) 17 urllib2.HTTPPasswordMgrWithDefaultRealm.__init__(self)
18 self.ui = ui 18 self.ui = ui
190 q.update(args) 190 q.update(args)
191 qs = urllib.urlencode(q) 191 qs = urllib.urlencode(q)
192 cu = "%s?%s" % (self.url, qs) 192 cu = "%s?%s" % (self.url, qs)
193 try: 193 try:
194 resp = urllib2.urlopen(urllib2.Request(cu, data, headers)) 194 resp = urllib2.urlopen(urllib2.Request(cu, data, headers))
195 except urllib2.HTTPError, inst:
196 if inst.code == 401:
197 raise util.Abort(_('authorization failed'))
198 raise
195 except httplib.HTTPException, inst: 199 except httplib.HTTPException, inst:
196 self.ui.debug(_('http error while sending %s command\n') % cmd) 200 self.ui.debug(_('http error while sending %s command\n') % cmd)
197 self.ui.print_exc() 201 self.ui.print_exc()
198 raise IOError(None, inst) 202 raise IOError(None, inst)
199 try: 203 try:
276 fp = os.fdopen(fd, 'wb+') 280 fp = os.fdopen(fd, 'wb+')
277 try: 281 try:
278 for chunk in util.filechunkiter(cg): 282 for chunk in util.filechunkiter(cg):
279 fp.write(chunk) 283 fp.write(chunk)
280 length = fp.tell() 284 length = fp.tell()
281 rfp = self.do_cmd(
282 'unbundle', data=fp,
283 headers={'content-length': length,
284 'content-type': 'application/octet-stream'},
285 heads=' '.join(map(hex, heads)))
286 try: 285 try:
287 ret = int(rfp.readline()) 286 rfp = self.do_cmd(
288 self.ui.write(rfp.read()) 287 'unbundle', data=fp,
289 return ret 288 headers={'content-length': length,
290 finally: 289 'content-type': 'application/octet-stream'},
291 rfp.close() 290 heads=' '.join(map(hex, heads)))
291 try:
292 ret = int(rfp.readline())
293 self.ui.write(rfp.read())
294 return ret
295 finally:
296 rfp.close()
297 except socket.error, err:
298 if err[0] in (errno.ECONNRESET, errno.EPIPE):
299 raise util.Abort(_('push failed: %s'), err[1])
300 raise util.Abort(err[1])
292 finally: 301 finally:
293 fp.close() 302 fp.close()
294 os.unlink(tempname) 303 os.unlink(tempname)
295 304
296 class httpsrepository(httprepository): 305 class httpsrepository(httprepository):