comparison mercurial/pycompat.py @ 45018:f2dc337117b9

compat: back out a25343d16ebe (initialize LC_CTYPE locale on all Python ...) As Yuya Nishihara pointed out, setting LC_CTYPE changes the behavior of some str methods on Python 2.
author Manuel Jacob <me@manueljacob.de>
date Sun, 28 Jun 2020 17:52:29 +0200
parents a25343d16ebe
children 9694895749ad
comparison
equal deleted inserted replaced
45017:a65c60f3280e 45018:f2dc337117b9
11 from __future__ import absolute_import 11 from __future__ import absolute_import
12 12
13 import getopt 13 import getopt
14 import inspect 14 import inspect
15 import json 15 import json
16 import locale
17 import os 16 import os
18 import shlex 17 import shlex
19 import sys 18 import sys
20 import tempfile 19 import tempfile
21 20
90 """ 89 """
91 if f is identity: 90 if f is identity:
92 # fast path mainly for py2 91 # fast path mainly for py2
93 return xs 92 return xs
94 return _rapply(f, xs) 93 return _rapply(f, xs)
95
96
97 # Passing the '' locale means that the locale should be set according to the
98 # user settings (environment variables).
99 # Python sometimes avoids setting the global locale settings. When interfacing
100 # with C code (e.g. the curses module or the Subversion bindings), the global
101 # locale settings must be initialized correctly. Python 2 does not initialize
102 # the global locale settings on interpreter startup. Python 3 sometimes
103 # initializes LC_CTYPE, but not consistently at least on Windows. Therefore we
104 # explicitly initialize it to get consistent behavior if it's not already
105 # initialized. Since CPython commit 177d921c8c03d30daa32994362023f777624b10d,
106 # LC_CTYPE is always initialized. If we require Python 3.8+, we should re-check
107 # if we can remove this code.
108 if locale.setlocale(locale.LC_CTYPE, None) == 'C':
109 try:
110 locale.setlocale(locale.LC_CTYPE, '')
111 except locale.Error:
112 # The likely case is that the locale from the environment variables is
113 # unknown.
114 pass
115 94
116 95
117 if ispy3: 96 if ispy3:
118 import builtins 97 import builtins
119 import codecs 98 import codecs