comparison mercurial/httprepo.py @ 2015:1a09814a5b1f

Catch HTTPException when reading from remote http repository. If the server dies very early, an httplib.IncompleteRead exception may be raised, because httplib can't read a single byte. Catching all HTTPException subclasses here will prevent ugly backtraces for similar things, too.
author Thomas Arendsen Hein <thomas@intevation.de>
date Wed, 29 Mar 2006 12:45:33 +0200
parents 8a8ab47cccde
children 7761597b5da3
comparison
equal deleted inserted replaced
2014:416f9e9e5f1b 2015:1a09814a5b1f
7 7
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") 12 demandload(globals(), "hg os urllib urllib2 urlparse zlib util httplib")
13 13
14 class httprepository(remoterepository): 14 class httprepository(remoterepository):
15 def __init__(self, ui, path): 15 def __init__(self, ui, path):
16 # fix missing / after hostname 16 # fix missing / after hostname
17 s = urlparse.urlsplit(path) 17 s = urlparse.urlsplit(path)
127 f = self.do_cmd("changegroup", roots=n) 127 f = self.do_cmd("changegroup", roots=n)
128 bytes = 0 128 bytes = 0
129 129
130 def zgenerator(f): 130 def zgenerator(f):
131 zd = zlib.decompressobj() 131 zd = zlib.decompressobj()
132 for chnk in f: 132 try:
133 yield zd.decompress(chnk) 133 for chnk in f:
134 yield zd.decompress(chnk)
135 except httplib.HTTPException, inst:
136 raise IOError(None, _('connection ended unexpectedly'))
134 yield zd.flush() 137 yield zd.flush()
135 138
136 return util.chunkbuffer(zgenerator(util.filechunkiter(f))) 139 return util.chunkbuffer(zgenerator(util.filechunkiter(f)))
137 140
138 class httpsrepository(httprepository): 141 class httpsrepository(httprepository):