##// END OF EJS Templates
pycompat: stop setting LC_CTYPE unconditionally...
Manuel Jacob -
r45545:90409803 default draft
parent child Browse files
Show More
@@ -1710,7 +1710,8 b' def _chistedit(ui, repo, freeargs, opts)'
1710 ctxs = []
1710 ctxs = []
1711 for i, r in enumerate(revs):
1711 for i, r in enumerate(revs):
1712 ctxs.append(histeditrule(ui, repo[r], i))
1712 ctxs.append(histeditrule(ui, repo[r], i))
1713 rc = curses.wrapper(functools.partial(_chisteditmain, repo, ctxs))
1713 with util.with_lc_ctype():
1714 rc = curses.wrapper(functools.partial(_chisteditmain, repo, ctxs))
1714 curses.echo()
1715 curses.echo()
1715 curses.endwin()
1716 curses.endwin()
1716 if rc is False:
1717 if rc is False:
@@ -569,7 +569,8 b' def chunkselector(ui, headerlist, operat'
569 if util.safehasattr(signal, b'SIGTSTP'):
569 if util.safehasattr(signal, b'SIGTSTP'):
570 origsigtstp = signal.getsignal(signal.SIGTSTP)
570 origsigtstp = signal.getsignal(signal.SIGTSTP)
571 try:
571 try:
572 curses.wrapper(chunkselector.main)
572 with util.with_lc_ctype():
573 curses.wrapper(chunkselector.main)
573 if chunkselector.initexc is not None:
574 if chunkselector.initexc is not None:
574 raise chunkselector.initexc
575 raise chunkselector.initexc
575 # ncurses does not restore signal handler for SIGTSTP
576 # ncurses does not restore signal handler for SIGTSTP
@@ -13,7 +13,6 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
17 import os
16 import os
18 import shlex
17 import shlex
19 import sys
18 import sys
@@ -94,26 +93,6 b' def rapply(f, xs):'
94 return _rapply(f, xs)
93 return _rapply(f, xs)
95
94
96
95
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
117 if ispy3:
96 if ispy3:
118 import builtins
97 import builtins
119 import codecs
98 import codecs
@@ -22,6 +22,7 b' import errno'
22 import gc
22 import gc
23 import hashlib
23 import hashlib
24 import itertools
24 import itertools
25 import locale
25 import mmap
26 import mmap
26 import os
27 import os
27 import platform as pyplatform
28 import platform as pyplatform
@@ -3596,3 +3597,32 b' def uvarintdecodestream(fh):'
3596 if not (byte & 0x80):
3597 if not (byte & 0x80):
3597 return result
3598 return result
3598 shift += 7
3599 shift += 7
3600
3601
3602 # Passing the '' locale means that the locale should be set according to the
3603 # user settings (environment variables).
3604 # Python sometimes avoids setting the global locale settings. When interfacing
3605 # with C code (e.g. the curses module or the Subversion bindings), the global
3606 # locale settings must be initialized correctly. Python 2 does not initialize
3607 # the global locale settings on interpreter startup. Python 3 sometimes
3608 # initializes LC_CTYPE, but not consistently at least on Windows. Therefore we
3609 # explicitly initialize it to get consistent behavior if it's not already
3610 # initialized. Since CPython commit 177d921c8c03d30daa32994362023f777624b10d,
3611 # LC_CTYPE is always initialized. If we require Python 3.8+, we should re-check
3612 # if we can remove this code.
3613 @contextlib.contextmanager
3614 def with_lc_ctype():
3615 oldloc = locale.setlocale(locale.LC_CTYPE, None)
3616 if oldloc == 'C':
3617 try:
3618 try:
3619 locale.setlocale(locale.LC_CTYPE, '')
3620 except locale.Error:
3621 # The likely case is that the locale from the environment
3622 # variables is unknown.
3623 pass
3624 yield
3625 finally:
3626 locale.setlocale(locale.LC_CTYPE, oldloc)
3627 else:
3628 yield
General Comments 0
You need to be logged in to leave comments. Login now