Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/pycompat.py @ 44821:afcad425a0b6 stable
pycompat: fix crash when default locale is unknown
Instead, fall back to the filesystem encoding if the default locale is unknown.
author | Manuel Jacob <me@manueljacob.de> |
---|---|
date | Wed, 24 Jun 2020 04:25:34 +0200 |
parents | 7be784f301fa |
children | f2de8f31cb59 |
comparison
equal
deleted
inserted
replaced
44820:3d41172f2ac9 | 44821:afcad425a0b6 |
---|---|
176 # encoding, which will pass CP_ACP to the underlying Windows API to | 176 # encoding, which will pass CP_ACP to the underlying Windows API to |
177 # produce bytes. | 177 # produce bytes. |
178 if os.name == r'nt': | 178 if os.name == r'nt': |
179 sysargv = [a.encode("mbcs", "ignore") for a in sys.argv] | 179 sysargv = [a.encode("mbcs", "ignore") for a in sys.argv] |
180 else: | 180 else: |
181 | |
182 def getdefaultlocale_if_known(): | |
183 try: | |
184 return locale.getdefaultlocale() | |
185 except ValueError: | |
186 return None, None | |
187 | |
181 encoding = ( | 188 encoding = ( |
182 locale.getlocale()[1] | 189 locale.getlocale()[1] |
183 or locale.getdefaultlocale()[1] | 190 or getdefaultlocale_if_known()[1] |
184 or sys.getfilesystemencoding() | 191 or sys.getfilesystemencoding() |
185 ) | 192 ) |
186 sysargv = [a.encode(encoding, "surrogateescape") for a in sys.argv] | 193 sysargv = [a.encode(encoding, "surrogateescape") for a in sys.argv] |
187 | 194 |
188 bytechr = struct.Struct('>B').pack | 195 bytechr = struct.Struct('>B').pack |