comparison mercurial/httprepo.py @ 15246:7b15dd9125b3

httprepo: make __del__ more stable in error situations Some errors could leave self.urlopener uninitialized and thus cause strange crashes in __del__. This member variable is now "declared statically" and checked for assignment before use.
author Mads Kiilerich <mads@kiilerich.com>
date Thu, 13 Oct 2011 04:27:49 +0200
parents 85322c19c831
children
comparison
equal deleted inserted replaced
15245:aa2c35057f47 15246:7b15dd9125b3
26 class httprepository(wireproto.wirerepository): 26 class httprepository(wireproto.wirerepository):
27 def __init__(self, ui, path): 27 def __init__(self, ui, path):
28 self.path = path 28 self.path = path
29 self.caps = None 29 self.caps = None
30 self.handler = None 30 self.handler = None
31 self.urlopener = None
31 u = util.url(path) 32 u = util.url(path)
32 if u.query or u.fragment: 33 if u.query or u.fragment:
33 raise util.Abort(_('unsupported URL component: "%s"') % 34 raise util.Abort(_('unsupported URL component: "%s"') %
34 (u.query or u.fragment)) 35 (u.query or u.fragment))
35 36
40 self.ui.debug('using %s\n' % self._url) 41 self.ui.debug('using %s\n' % self._url)
41 42
42 self.urlopener = url.opener(ui, authinfo) 43 self.urlopener = url.opener(ui, authinfo)
43 44
44 def __del__(self): 45 def __del__(self):
45 for h in self.urlopener.handlers: 46 if self.urlopener:
46 h.close() 47 for h in self.urlopener.handlers:
47 getattr(h, "close_all", lambda : None)() 48 h.close()
49 getattr(h, "close_all", lambda : None)()
48 50
49 def url(self): 51 def url(self):
50 return self.path 52 return self.path
51 53
52 # look up capabilities only when needed 54 # look up capabilities only when needed