Show More
@@ -8,21 +8,41 | |||
|
8 | 8 | import error |
|
9 | 9 | import sys, unicodedata, locale, os |
|
10 | 10 | |
|
11 | _encodingfixup = {'646': 'ascii', 'ANSI_X3.4-1968': 'ascii'} | |
|
11 | def _getpreferredencoding(): | |
|
12 | ''' | |
|
13 | On darwin, getpreferredencoding ignores the locale environment and | |
|
14 | always returns mac-roman. http://bugs.python.org/issue6202 fixes this | |
|
15 | for Python 2.7 and up. This is the same corrected code for earlier | |
|
16 | Python versions. | |
|
17 | ||
|
18 | However, we can't use a version check for this method, as some distributions | |
|
19 | patch Python to fix this. Instead, we use it as a 'fixer' for the mac-roman | |
|
20 | encoding, as it is unlikely that this encoding is the actually expected. | |
|
21 | ''' | |
|
22 | try: | |
|
23 | locale.CODESET | |
|
24 | except AttributeError: | |
|
25 | # Fall back to parsing environment variables :-( | |
|
26 | return locale.getdefaultlocale()[1] | |
|
27 | ||
|
28 | oldloc = locale.setlocale(locale.LC_CTYPE) | |
|
29 | locale.setlocale(locale.LC_CTYPE, "") | |
|
30 | result = locale.nl_langinfo(locale.CODESET) | |
|
31 | locale.setlocale(locale.LC_CTYPE, oldloc) | |
|
32 | ||
|
33 | return result | |
|
34 | ||
|
35 | _encodingfixers = { | |
|
36 | '646': lambda: 'ascii', | |
|
37 | 'ANSI_X3.4-1968': lambda: 'ascii', | |
|
38 | 'mac-roman': _getpreferredencoding | |
|
39 | } | |
|
12 | 40 | |
|
13 | 41 | try: |
|
14 | 42 | encoding = os.environ.get("HGENCODING") |
|
15 | if sys.platform == 'darwin' and not encoding: | |
|
16 | # On darwin, getpreferredencoding ignores the locale environment and | |
|
17 | # always returns mac-roman. We override this if the environment is | |
|
18 | # not C (has been customized by the user). | |
|
19 | lc = locale.setlocale(locale.LC_CTYPE, '') | |
|
20 | if lc == 'UTF-8': | |
|
21 | locale.setlocale(locale.LC_CTYPE, 'en_US.UTF-8') | |
|
22 | encoding = locale.getlocale()[1] | |
|
23 | 43 | if not encoding: |
|
24 | 44 | encoding = locale.getpreferredencoding() or 'ascii' |
|
25 |
encoding = _encodingfix |
|
|
45 | encoding = _encodingfixers.get(encoding, lambda: encoding)() | |
|
26 | 46 | except locale.Error: |
|
27 | 47 | encoding = 'ascii' |
|
28 | 48 | encodingmode = os.environ.get("HGENCODINGMODE", "strict") |
@@ -140,6 +140,12 def xmlescape(text): | |||
|
140 | 140 | .replace("'", ''')) # ' invalid in HTML |
|
141 | 141 | return re.sub('[\x00-\x08\x0B\x0C\x0E-\x1F]', ' ', text) |
|
142 | 142 | |
|
143 | def uescape(c): | |
|
144 | if ord(c) < 0x80: | |
|
145 | return c | |
|
146 | else: | |
|
147 | return '\\u%04x' % ord(c) | |
|
148 | ||
|
143 | 149 | _escapes = [ |
|
144 | 150 | ('\\', '\\\\'), ('"', '\\"'), ('\t', '\\t'), ('\n', '\\n'), |
|
145 | 151 | ('\r', '\\r'), ('\f', '\\f'), ('\b', '\\b'), |
@@ -148,7 +154,7 def xmlescape(text): | |||
|
148 | 154 | def jsonescape(s): |
|
149 | 155 | for k, v in _escapes: |
|
150 | 156 | s = s.replace(k, v) |
|
151 | return s | |
|
157 | return ''.join(uescape(c) for c in s) | |
|
152 | 158 | |
|
153 | 159 | def json(obj): |
|
154 | 160 | if obj is None or obj is False or obj is True: |
@@ -157,9 +163,9 def json(obj): | |||
|
157 | 163 | return str(obj) |
|
158 | 164 | elif isinstance(obj, str): |
|
159 | 165 | u = unicode(obj, encoding.encoding, 'replace') |
|
160 |
return '"%s"' % jsonescape(u) |
|
|
166 | return '"%s"' % jsonescape(u) | |
|
161 | 167 | elif isinstance(obj, unicode): |
|
162 |
return '"%s"' % jsonescape(obj) |
|
|
168 | return '"%s"' % jsonescape(obj) | |
|
163 | 169 | elif hasattr(obj, 'keys'): |
|
164 | 170 | out = [] |
|
165 | 171 | for k, v in obj.iteritems(): |
@@ -984,5 +984,5 ul#graphnodes li .info { | |||
|
984 | 984 | } |
|
985 | 985 | % Stop and restart with HGENCODING=cp932 |
|
986 | 986 | % Graph json escape of multibyte character |
|
987 |
var data = [["40b4d6888e92", [0, 1], [[0, 0, 1]], " |
|
|
987 | var data = [["40b4d6888e92", [0, 1], [[0, 0, 1]], "\u80fd", "test", "1970-01-01", ["stable", true], ["tip"]], ["1d22e65f027e", [0, 1], [[0, 0, 1]], "branch", "test", "1970-01-01", ["stable", false], []], ["a4f92ed23982", [0, 1], [[0, 0, 1]], "Added tag 1.0 for changeset 2ef0ac749a14", "test", "1970-01-01", ["default", true], []], ["2ef0ac749a14", [0, 1], [], "base", "test", "1970-01-01", ["default", false], ["1.0"]]]; | |
|
988 | 988 | % ERRORS ENCOUNTERED |
@@ -41,7 +41,7 EOF | |||
|
41 | 41 | # of the very long subject line |
|
42 | 42 | echo '% pull (minimal config)' |
|
43 | 43 | hg --traceback --cwd b pull ../a 2>&1 | |
|
44 | python -c 'import sys,re; print re.sub("\n\t", " ", sys.stdin.read()),' | | |
|
44 | python -c 'import sys,re; print re.sub("([n:])\\n[\\t ]", "\\1 ", sys.stdin.read()),' | | |
|
45 | 45 | sed -e 's/\(Message-Id:\).*/\1/' \ |
|
46 | 46 | -e 's/changeset \([0-9a-f]* *\)in .*test-notif/changeset \1in test-notif/' \ |
|
47 | 47 | -e 's/^details: .*test-notify/details: test-notify/' \ |
General Comments 0
You need to be logged in to leave comments.
Login now