##// END OF EJS Templates
Merge with stable
Patrick Mezard -
r11893:aa50d072 merge default
parent child Browse files
Show More
@@ -8,21 +8,41 b''
8 import error
8 import error
9 import sys, unicodedata, locale, os
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 try:
41 try:
14 encoding = os.environ.get("HGENCODING")
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 if not encoding:
43 if not encoding:
24 encoding = locale.getpreferredencoding() or 'ascii'
44 encoding = locale.getpreferredencoding() or 'ascii'
25 encoding = _encodingfixup.get(encoding, encoding)
45 encoding = _encodingfixers.get(encoding, lambda: encoding)()
26 except locale.Error:
46 except locale.Error:
27 encoding = 'ascii'
47 encoding = 'ascii'
28 encodingmode = os.environ.get("HGENCODINGMODE", "strict")
48 encodingmode = os.environ.get("HGENCODINGMODE", "strict")
@@ -140,6 +140,12 b' def xmlescape(text):'
140 .replace("'", ''')) # ' invalid in HTML
140 .replace("'", ''')) # ' invalid in HTML
141 return re.sub('[\x00-\x08\x0B\x0C\x0E-\x1F]', ' ', text)
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 _escapes = [
149 _escapes = [
144 ('\\', '\\\\'), ('"', '\\"'), ('\t', '\\t'), ('\n', '\\n'),
150 ('\\', '\\\\'), ('"', '\\"'), ('\t', '\\t'), ('\n', '\\n'),
145 ('\r', '\\r'), ('\f', '\\f'), ('\b', '\\b'),
151 ('\r', '\\r'), ('\f', '\\f'), ('\b', '\\b'),
@@ -148,7 +154,7 b' def xmlescape(text):'
148 def jsonescape(s):
154 def jsonescape(s):
149 for k, v in _escapes:
155 for k, v in _escapes:
150 s = s.replace(k, v)
156 s = s.replace(k, v)
151 return s
157 return ''.join(uescape(c) for c in s)
152
158
153 def json(obj):
159 def json(obj):
154 if obj is None or obj is False or obj is True:
160 if obj is None or obj is False or obj is True:
@@ -157,9 +163,9 b' def json(obj):'
157 return str(obj)
163 return str(obj)
158 elif isinstance(obj, str):
164 elif isinstance(obj, str):
159 u = unicode(obj, encoding.encoding, 'replace')
165 u = unicode(obj, encoding.encoding, 'replace')
160 return '"%s"' % jsonescape(u).encode('utf-8')
166 return '"%s"' % jsonescape(u)
161 elif isinstance(obj, unicode):
167 elif isinstance(obj, unicode):
162 return '"%s"' % jsonescape(obj).encode('utf-8')
168 return '"%s"' % jsonescape(obj)
163 elif hasattr(obj, 'keys'):
169 elif hasattr(obj, 'keys'):
164 out = []
170 out = []
165 for k, v in obj.iteritems():
171 for k, v in obj.iteritems():
@@ -984,5 +984,5 b' ul#graphnodes li .info {'
984 }
984 }
985 % Stop and restart with HGENCODING=cp932
985 % Stop and restart with HGENCODING=cp932
986 % Graph json escape of multibyte character
986 % Graph json escape of multibyte character
987 var data = [["40b4d6888e92", [0, 1], [[0, 0, 1]], "", "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"]]];
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 % ERRORS ENCOUNTERED
988 % ERRORS ENCOUNTERED
@@ -41,7 +41,7 b' EOF'
41 # of the very long subject line
41 # of the very long subject line
42 echo '% pull (minimal config)'
42 echo '% pull (minimal config)'
43 hg --traceback --cwd b pull ../a 2>&1 |
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 sed -e 's/\(Message-Id:\).*/\1/' \
45 sed -e 's/\(Message-Id:\).*/\1/' \
46 -e 's/changeset \([0-9a-f]* *\)in .*test-notif/changeset \1in test-notif/' \
46 -e 's/changeset \([0-9a-f]* *\)in .*test-notif/changeset \1in test-notif/' \
47 -e 's/^details: .*test-notify/details: test-notify/' \
47 -e 's/^details: .*test-notify/details: test-notify/' \
General Comments 0
You need to be logged in to leave comments. Login now