comparison mercurial/util.py @ 4540:133a52d70958

Respect locale environment variables on darwin. In python 2.4+ on darwin, locale.getpreferredencoding() returns mac-roman regardless of what LC_CTYPE, LANG etc are set to. This can produce hard-to-notice conversion errors if input text is not in mac-roman. So this patch overrides it with setlocale/getlocale if the environment has been customized, on the assumption that the user has done so deliberately.
author Brendan Cully <brendan@kublai.com>
date Mon, 11 Jun 2007 12:14:31 -0700
parents 36abb07c79d4
children eaf87cd19337
comparison
equal deleted inserted replaced
4539:e6c69a2491ed 4540:133a52d70958
15 from i18n import _ 15 from i18n import _
16 import cStringIO, errno, getpass, popen2, re, shutil, sys, tempfile 16 import cStringIO, errno, getpass, popen2, re, shutil, sys, tempfile
17 import os, threading, time, calendar, ConfigParser, locale, glob 17 import os, threading, time, calendar, ConfigParser, locale, glob
18 18
19 try: 19 try:
20 _encoding = os.environ.get("HGENCODING") or locale.getpreferredencoding() \ 20 _encoding = os.environ.get("HGENCODING")
21 or "ascii" 21 if sys.platform == 'darwin' and not _encoding:
22 # On darwin, getpreferredencoding ignores the locale environment and
23 # always returns mac-roman. We override this if the environment is
24 # not C (has been customized by the user).
25 locale.setlocale(locale.LC_CTYPE, '')
26 _encoding = locale.getlocale()[1]
27 if not _encoding:
28 _encoding = locale.getpreferredencoding() or 'ascii'
22 except locale.Error: 29 except locale.Error:
23 _encoding = 'ascii' 30 _encoding = 'ascii'
24 _encodingmode = os.environ.get("HGENCODINGMODE", "strict") 31 _encodingmode = os.environ.get("HGENCODINGMODE", "strict")
25 _fallbackencoding = 'ISO-8859-1' 32 _fallbackencoding = 'ISO-8859-1'
26 33