##// END OF EJS Templates
compat: initialize LC_CTYPE locale on all Python versions and platforms...
Manuel Jacob -
r45923:a25343d1 default
parent child Browse files
Show More
@@ -13,6 +13,7 b' from __future__ import absolute_import'
13 import getopt
13 import getopt
14 import inspect
14 import inspect
15 import json
15 import json
16 import locale
16 import os
17 import os
17 import shlex
18 import shlex
18 import sys
19 import sys
@@ -93,6 +94,26 b' def rapply(f, xs):'
93 return _rapply(f, xs)
94 return _rapply(f, xs)
94
95
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
116
96 if ispy3:
117 if ispy3:
97 import builtins
118 import builtins
98 import codecs
119 import codecs
General Comments 0
You need to be logged in to leave comments. Login now