Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/util.py @ 3835:d1ce5461beed
Allow the user to specify the fallback encoding for the changelog
Example: use EUC-JP instead of ISO-8859-1:
[ui]
fallbackencoding = EUC-JP
author | Alexis S. L. Carvalho <alexis@cecm.usp.br> |
---|---|
date | Fri, 08 Dec 2006 22:01:05 -0200 |
parents | fc5ba0ab7f45 |
children | abaa2cd00d2b |
comparison
equal
deleted
inserted
replaced
3834:a7b61c3b0f93 | 3835:d1ce5461beed |
---|---|
17 demandload(globals(), "cStringIO errno getpass popen2 re shutil sys tempfile") | 17 demandload(globals(), "cStringIO errno getpass popen2 re shutil sys tempfile") |
18 demandload(globals(), "os threading time calendar ConfigParser locale") | 18 demandload(globals(), "os threading time calendar ConfigParser locale") |
19 | 19 |
20 _encoding = os.environ.get("HGENCODING") or locale.getpreferredencoding() | 20 _encoding = os.environ.get("HGENCODING") or locale.getpreferredencoding() |
21 _encodingmode = os.environ.get("HGENCODINGMODE", "strict") | 21 _encodingmode = os.environ.get("HGENCODINGMODE", "strict") |
22 _fallbackencoding = 'ISO-8859-1' | |
22 | 23 |
23 def tolocal(s): | 24 def tolocal(s): |
24 """ | 25 """ |
25 Convert a string from internal UTF-8 to local encoding | 26 Convert a string from internal UTF-8 to local encoding |
26 | 27 |
28 implementation of locale support may contain latin1 or possibly | 29 implementation of locale support may contain latin1 or possibly |
29 other character sets. We attempt to decode everything strictly | 30 other character sets. We attempt to decode everything strictly |
30 using UTF-8, then Latin-1, and failing that, we use UTF-8 and | 31 using UTF-8, then Latin-1, and failing that, we use UTF-8 and |
31 replace unknown characters. | 32 replace unknown characters. |
32 """ | 33 """ |
33 for e in "utf-8 latin1".split(): | 34 for e in ('UTF-8', _fallbackencoding): |
34 try: | 35 try: |
35 u = s.decode(e) # attempt strict decoding | 36 u = s.decode(e) # attempt strict decoding |
36 return u.encode(_encoding, "replace") | 37 return u.encode(_encoding, "replace") |
37 except UnicodeDecodeError: | 38 except UnicodeDecodeError: |
38 pass | 39 pass |