merge with stable
authorMatt Mackall <mpm@selenic.com>
Wed, 05 Feb 2014 18:09:07 -0600
changeset 20368 cc00cd6c51c2
parent 20367 2ac278aab2b4 (current diff)
parent 20357 6863d42eb59a (diff)
child 20369 9c6b86dd2ed2
merge with stable
--- a/mercurial/hgweb/server.py	Fri Jan 24 16:57:44 2014 -0800
+++ b/mercurial/hgweb/server.py	Wed Feb 05 18:09:07 2014 -0600
@@ -322,7 +322,20 @@
         cls = MercurialHTTPServer
 
     # ugly hack due to python issue5853 (for threaded use)
-    import mimetypes; mimetypes.init()
+    try:
+        import mimetypes
+        mimetypes.init()
+    except UnicodeDecodeError:
+        # Python 2.x's mimetypes module attempts to decode strings
+        # from Windows' ANSI APIs as ascii (fail), then re-encode them
+        # as ascii (clown fail), because the default Python Unicode
+        # codec is hardcoded as ascii.
+
+        reload(sys) # resurrect sys.setdefaultencoding()
+        oldenc = sys.getdefaultencoding()
+        sys.setdefaultencoding("latin1") # or any full 8-bit encoding
+        mimetypes.init()
+        sys.setdefaultencoding(oldenc)
 
     address = ui.config('web', 'address', '')
     port = util.getport(ui.config('web', 'port', 8000))