comparison mercurial/httprepo.py @ 6001:30d2fecaab76

merge with crew-stable
author Alexis S. L. Carvalho <alexis@cecm.usp.br>
date Sun, 03 Feb 2008 21:47:07 -0200
parents c301f15c965a 6f1fcbc58efa
children f89fd07fc51d
comparison
equal deleted inserted replaced
6000:8e7d64989bb8 6001:30d2fecaab76
101 101
102 class httpconnection(keepalive.HTTPConnection): 102 class httpconnection(keepalive.HTTPConnection):
103 # must be able to send big bundle as stream. 103 # must be able to send big bundle as stream.
104 send = _gen_sendfile(keepalive.HTTPConnection) 104 send = _gen_sendfile(keepalive.HTTPConnection)
105 105
106 class basehttphandler(keepalive.HTTPHandler): 106 class httphandler(keepalive.HTTPHandler):
107 def http_open(self, req): 107 def http_open(self, req):
108 return self.do_open(httpconnection, req) 108 return self.do_open(httpconnection, req)
109
110 def __del__(self):
111 self.close_all()
109 112
110 has_https = hasattr(urllib2, 'HTTPSHandler') 113 has_https = hasattr(urllib2, 'HTTPSHandler')
111 if has_https: 114 if has_https:
112 class httpsconnection(httplib.HTTPSConnection): 115 class httpsconnection(httplib.HTTPSConnection):
113 response_class = keepalive.HTTPResponse 116 response_class = keepalive.HTTPResponse
114 # must be able to send big bundle as stream. 117 # must be able to send big bundle as stream.
115 send = _gen_sendfile(httplib.HTTPSConnection) 118 send = _gen_sendfile(httplib.HTTPSConnection)
116 119
117 class httphandler(basehttphandler, urllib2.HTTPSHandler): 120 class httpshandler(keepalive.KeepAliveHandler, urllib2.HTTPSHandler):
118 def https_open(self, req): 121 def https_open(self, req):
119 return self.do_open(httpsconnection, req) 122 return self.do_open(httpsconnection, req)
120 else:
121 class httphandler(basehttphandler):
122 pass
123 123
124 # In python < 2.5 AbstractDigestAuthHandler raises a ValueError if 124 # In python < 2.5 AbstractDigestAuthHandler raises a ValueError if
125 # it doesn't know about the auth type requested. This can happen if 125 # it doesn't know about the auth type requested. This can happen if
126 # somebody is using BasicAuth and types a bad password. 126 # somebody is using BasicAuth and types a bad password.
127 class httpdigestauthhandler(urllib2.HTTPDigestAuthHandler): 127 class httpdigestauthhandler(urllib2.HTTPDigestAuthHandler):
201 self.ui = ui 201 self.ui = ui
202 self.ui.debug(_('using %s\n') % self._url) 202 self.ui.debug(_('using %s\n') % self._url)
203 203
204 proxyurl = ui.config("http_proxy", "host") or os.getenv('http_proxy') 204 proxyurl = ui.config("http_proxy", "host") or os.getenv('http_proxy')
205 # XXX proxyauthinfo = None 205 # XXX proxyauthinfo = None
206 self.handler = httphandler() 206 handlers = [httphandler()]
207 handlers = [self.handler] 207 if has_https:
208 handlers.append(httpshandler())
208 209
209 if proxyurl: 210 if proxyurl:
210 # proxy can be proper url or host[:port] 211 # proxy can be proper url or host[:port]
211 if not (proxyurl.startswith('http:') or 212 if not (proxyurl.startswith('http:') or
212 proxyurl.startswith('https:')): 213 proxyurl.startswith('https:')):
268 269
269 # 1.0 here is the _protocol_ version 270 # 1.0 here is the _protocol_ version
270 opener.addheaders = [('User-agent', 'mercurial/proto-1.0')] 271 opener.addheaders = [('User-agent', 'mercurial/proto-1.0')]
271 urllib2.install_opener(opener) 272 urllib2.install_opener(opener)
272 273
273 def __del__(self):
274 if self.handler:
275 self.handler.close_all()
276 self.handler = None
277
278 def url(self): 274 def url(self):
279 return self.path 275 return self.path
280 276
281 # look up capabilities only when needed 277 # look up capabilities only when needed
282 278