Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/hgweb/server.py @ 26848:d962e955da08
hgweb.server: drop support for Python 2.4
author | Siddharth Agarwal <sid0@fb.com> |
---|---|
date | Sat, 24 Oct 2015 16:23:42 -0700 |
parents | 56b2bcea2529 |
children | 37fcfe52c68c |
comparison
equal
deleted
inserted
replaced
26847:9f16787cbefd | 26848:d962e955da08 |
---|---|
195 def _done(self): | 195 def _done(self): |
196 if self._chunked: | 196 if self._chunked: |
197 self.wfile.write('0\r\n\r\n') | 197 self.wfile.write('0\r\n\r\n') |
198 self.wfile.flush() | 198 self.wfile.flush() |
199 | 199 |
200 class _httprequesthandleropenssl(_httprequesthandler): | |
201 """HTTPS handler based on pyOpenSSL""" | |
202 | |
203 url_scheme = 'https' | |
204 | |
205 @staticmethod | |
206 def preparehttpserver(httpserver, ssl_cert): | |
207 try: | |
208 import OpenSSL | |
209 OpenSSL.SSL.Context | |
210 except ImportError: | |
211 raise error.Abort(_("SSL support is unavailable")) | |
212 ctx = OpenSSL.SSL.Context(OpenSSL.SSL.TLSv1_METHOD) | |
213 ctx.use_privatekey_file(ssl_cert) | |
214 ctx.use_certificate_file(ssl_cert) | |
215 sock = socket.socket(httpserver.address_family, httpserver.socket_type) | |
216 httpserver.socket = OpenSSL.SSL.Connection(ctx, sock) | |
217 httpserver.server_bind() | |
218 httpserver.server_activate() | |
219 | |
220 def setup(self): | |
221 self.connection = self.request | |
222 self.rfile = socket._fileobject(self.request, "rb", self.rbufsize) | |
223 self.wfile = socket._fileobject(self.request, "wb", self.wbufsize) | |
224 | |
225 def do_write(self): | |
226 import OpenSSL | |
227 try: | |
228 _httprequesthandler.do_write(self) | |
229 except OpenSSL.SSL.SysCallError as inst: | |
230 if inst.args[0] != errno.EPIPE: | |
231 raise | |
232 | |
233 def handle_one_request(self): | |
234 import OpenSSL | |
235 try: | |
236 _httprequesthandler.handle_one_request(self) | |
237 except (OpenSSL.SSL.SysCallError, OpenSSL.SSL.ZeroReturnError): | |
238 self.close_connection = True | |
239 pass | |
240 | |
241 class _httprequesthandlerssl(_httprequesthandler): | 200 class _httprequesthandlerssl(_httprequesthandler): |
242 """HTTPS handler based on Python's ssl module""" | 201 """HTTPS handler based on Python's ssl module""" |
243 | 202 |
244 url_scheme = 'https' | 203 url_scheme = 'https' |
245 | 204 |
309 super(IPv6HTTPServer, self).__init__(*args, **kwargs) | 268 super(IPv6HTTPServer, self).__init__(*args, **kwargs) |
310 | 269 |
311 def create_server(ui, app): | 270 def create_server(ui, app): |
312 | 271 |
313 if ui.config('web', 'certificate'): | 272 if ui.config('web', 'certificate'): |
314 if sys.version_info >= (2, 6): | 273 handler = _httprequesthandlerssl |
315 handler = _httprequesthandlerssl | |
316 else: | |
317 handler = _httprequesthandleropenssl | |
318 else: | 274 else: |
319 handler = _httprequesthandler | 275 handler = _httprequesthandler |
320 | 276 |
321 if ui.configbool('web', 'ipv6'): | 277 if ui.configbool('web', 'ipv6'): |
322 cls = IPv6HTTPServer | 278 cls = IPv6HTTPServer |