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) |