mercurial/util.py
branchstable
changeset 45011 1bab6b61b62b
parent 44629 d37975386798
child 45019 4a503c1b664a
equal deleted inserted replaced
45004:2632c1ed8f34 45011:1bab6b61b62b
    20 import contextlib
    20 import contextlib
    21 import errno
    21 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
    28 import re as remod
    29 import re as remod
    29 import shutil
    30 import shutil
  3624         byte = ord(readexactly(fh, 1))
  3625         byte = ord(readexactly(fh, 1))
  3625         result |= (byte & 0x7F) << shift
  3626         result |= (byte & 0x7F) << shift
  3626         if not (byte & 0x80):
  3627         if not (byte & 0x80):
  3627             return result
  3628             return result
  3628         shift += 7
  3629         shift += 7
       
  3630 
       
  3631 
       
  3632 # Passing the '' locale means that the locale should be set according to the
       
  3633 # user settings (environment variables).
       
  3634 # Python sometimes avoids setting the global locale settings. When interfacing
       
  3635 # with C code (e.g. the curses module or the Subversion bindings), the global
       
  3636 # locale settings must be initialized correctly. Python 2 does not initialize
       
  3637 # the global locale settings on interpreter startup. Python 3 sometimes
       
  3638 # initializes LC_CTYPE, but not consistently at least on Windows. Therefore we
       
  3639 # explicitly initialize it to get consistent behavior if it's not already
       
  3640 # initialized. Since CPython commit 177d921c8c03d30daa32994362023f777624b10d,
       
  3641 # LC_CTYPE is always initialized. If we require Python 3.8+, we should re-check
       
  3642 # if we can remove this code.
       
  3643 @contextlib.contextmanager
       
  3644 def with_lc_ctype():
       
  3645     oldloc = locale.setlocale(locale.LC_CTYPE, None)
       
  3646     if oldloc == 'C':
       
  3647         try:
       
  3648             try:
       
  3649                 locale.setlocale(locale.LC_CTYPE, '')
       
  3650             except locale.Error:
       
  3651                 # The likely case is that the locale from the environment
       
  3652                 # variables is unknown.
       
  3653                 pass
       
  3654             yield
       
  3655         finally:
       
  3656             locale.setlocale(locale.LC_CTYPE, oldloc)
       
  3657     else:
       
  3658         yield