comparison mercurial/hgweb/server.py @ 20529:ca970d6acedb stable

hgweb: make sure sys module is loaded prior to reload hack If sys is still a demandmod, reload(sys) fails with "TypeError: reload() argument must be module".
author Yuya Nishihara <yuya@tcha.org>
date Wed, 19 Feb 2014 21:16:43 +0900
parents 6863d42eb59a
children c289fb3624b8
comparison
equal deleted inserted replaced
20523:f2a0a0e76b4c 20529:ca970d6acedb
329 # Python 2.x's mimetypes module attempts to decode strings 329 # Python 2.x's mimetypes module attempts to decode strings
330 # from Windows' ANSI APIs as ascii (fail), then re-encode them 330 # from Windows' ANSI APIs as ascii (fail), then re-encode them
331 # as ascii (clown fail), because the default Python Unicode 331 # as ascii (clown fail), because the default Python Unicode
332 # codec is hardcoded as ascii. 332 # codec is hardcoded as ascii.
333 333
334 sys.argv # unwrap demand-loader so that reload() works
334 reload(sys) # resurrect sys.setdefaultencoding() 335 reload(sys) # resurrect sys.setdefaultencoding()
335 oldenc = sys.getdefaultencoding() 336 oldenc = sys.getdefaultencoding()
336 sys.setdefaultencoding("latin1") # or any full 8-bit encoding 337 sys.setdefaultencoding("latin1") # or any full 8-bit encoding
337 mimetypes.init() 338 mimetypes.init()
338 sys.setdefaultencoding(oldenc) 339 sys.setdefaultencoding(oldenc)