comparison mercurial/util.py @ 45034:4a503c1b664a

merge with stable
author Yuya Nishihara <yuya@tcha.org>
date Mon, 29 Jun 2020 20:53:32 +0900
parents 7af5c1f5b3a0 1bab6b61b62b
children 02b17231f6c3
comparison
equal deleted inserted replaced
45033:f2dc337117b9 45034:4a503c1b664a
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
3594 byte = ord(readexactly(fh, 1)) 3595 byte = ord(readexactly(fh, 1))
3595 result |= (byte & 0x7F) << shift 3596 result |= (byte & 0x7F) << shift
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