mercurial/pycompat.py
changeset 45021 a25343d16ebe
parent 45018 f2de8f31cb59
child 45033 f2dc337117b9
equal deleted inserted replaced
45020:3fadbdc47aed 45021:a25343d16ebe
    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
    16 import os
    17 import os
    17 import shlex
    18 import shlex
    18 import sys
    19 import sys
    19 import tempfile
    20 import tempfile
    20 
    21 
    89     """
    90     """
    90     if f is identity:
    91     if f is identity:
    91         # fast path mainly for py2
    92         # fast path mainly for py2
    92         return xs
    93         return xs
    93     return _rapply(f, xs)
    94     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
    94 
   115 
    95 
   116 
    96 if ispy3:
   117 if ispy3:
    97     import builtins
   118     import builtins
    98     import codecs
   119     import codecs