Mercurial > public > mercurial-scm > hg
comparison mercurial/url.py @ 29662:b76ea1384bf2
url: drop compatibility wrapper of socket.create_connection()
It should be available on Python 2.6+.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Mon, 18 Jul 2016 23:12:09 +0900 |
parents | 6fd751fa58d3 |
children | 44ea12756fef |
comparison
equal
deleted
inserted
replaced
29661:a181dbef8e7f | 29662:b76ea1384bf2 |
---|---|
149 else: | 149 else: |
150 orgsend(self, data) | 150 orgsend(self, data) |
151 return _sendfile | 151 return _sendfile |
152 | 152 |
153 has_https = util.safehasattr(urlreq, 'httpshandler') | 153 has_https = util.safehasattr(urlreq, 'httpshandler') |
154 if has_https: | |
155 try: | |
156 _create_connection = socket.create_connection | |
157 except AttributeError: | |
158 _GLOBAL_DEFAULT_TIMEOUT = object() | |
159 | |
160 def _create_connection(address, timeout=_GLOBAL_DEFAULT_TIMEOUT, | |
161 source_address=None): | |
162 # lifted from Python 2.6 | |
163 | |
164 msg = "getaddrinfo returns an empty list" | |
165 host, port = address | |
166 for res in socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM): | |
167 af, socktype, proto, canonname, sa = res | |
168 sock = None | |
169 try: | |
170 sock = socket.socket(af, socktype, proto) | |
171 if timeout is not _GLOBAL_DEFAULT_TIMEOUT: | |
172 sock.settimeout(timeout) | |
173 if source_address: | |
174 sock.bind(source_address) | |
175 sock.connect(sa) | |
176 return sock | |
177 | |
178 except socket.error as msg: | |
179 if sock is not None: | |
180 sock.close() | |
181 | |
182 raise socket.error(msg) | |
183 | 154 |
184 class httpconnection(keepalive.HTTPConnection): | 155 class httpconnection(keepalive.HTTPConnection): |
185 # must be able to send big bundle as stream. | 156 # must be able to send big bundle as stream. |
186 send = _gen_sendfile(keepalive.HTTPConnection.send) | 157 send = _gen_sendfile(keepalive.HTTPConnection.send) |
187 | 158 |
335 httplib.HTTPConnection.__init__(self, host, port, *args, **kwargs) | 306 httplib.HTTPConnection.__init__(self, host, port, *args, **kwargs) |
336 self.key_file = key_file | 307 self.key_file = key_file |
337 self.cert_file = cert_file | 308 self.cert_file = cert_file |
338 | 309 |
339 def connect(self): | 310 def connect(self): |
340 self.sock = _create_connection((self.host, self.port)) | 311 self.sock = socket.create_connection((self.host, self.port)) |
341 | 312 |
342 host = self.host | 313 host = self.host |
343 if self.realhostport: # use CONNECT proxy | 314 if self.realhostport: # use CONNECT proxy |
344 _generic_proxytunnel(self) | 315 _generic_proxytunnel(self) |
345 host = self.realhostport.rsplit(':', 1)[0] | 316 host = self.realhostport.rsplit(':', 1)[0] |