Mercurial > hg
comparison mercurial/hgweb/server.py @ 20357:6863d42eb59a stable
hgweb: hack around mimetypes encoding thinko (issue4160)
A correct patch for this has existed in Python's BTS for 3 years
(http://bugs.python.org/issue9291), so waiting for it to be fixed
upstream is probably not a viable strategy. Instead, we add this
horrible hack to workaround the issue in existing copies of Python
2.4-2.7.
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Wed, 05 Feb 2014 17:23:35 -0600 |
parents | 52ed85d9ac26 |
children | ca970d6acedb |
comparison
equal
deleted
inserted
replaced
20355:7d269e7620c4 | 20357:6863d42eb59a |
---|---|
320 cls = IPv6HTTPServer | 320 cls = IPv6HTTPServer |
321 else: | 321 else: |
322 cls = MercurialHTTPServer | 322 cls = MercurialHTTPServer |
323 | 323 |
324 # ugly hack due to python issue5853 (for threaded use) | 324 # ugly hack due to python issue5853 (for threaded use) |
325 import mimetypes; mimetypes.init() | 325 try: |
326 import mimetypes | |
327 mimetypes.init() | |
328 except UnicodeDecodeError: | |
329 # Python 2.x's mimetypes module attempts to decode strings | |
330 # from Windows' ANSI APIs as ascii (fail), then re-encode them | |
331 # as ascii (clown fail), because the default Python Unicode | |
332 # codec is hardcoded as ascii. | |
333 | |
334 reload(sys) # resurrect sys.setdefaultencoding() | |
335 oldenc = sys.getdefaultencoding() | |
336 sys.setdefaultencoding("latin1") # or any full 8-bit encoding | |
337 mimetypes.init() | |
338 sys.setdefaultencoding(oldenc) | |
326 | 339 |
327 address = ui.config('web', 'address', '') | 340 address = ui.config('web', 'address', '') |
328 port = util.getport(ui.config('web', 'port', 8000)) | 341 port = util.getport(ui.config('web', 'port', 8000)) |
329 try: | 342 try: |
330 return cls(ui, app, (address, port), handler) | 343 return cls(ui, app, (address, port), handler) |