comparison mercurial/encoding.py @ 47560:af633293a5bd

windows: replicate the normalizing behavior of os.environ On Windows, `os.environ` normalizes environment variables to uppercase. Our current bytes-based environ substitution object is a simple dict, so we add the normalization behavior. This fixes test-http-peer.t on Windows. Differential Revision: https://phab.mercurial-scm.org/D10998
author Raphaël Gomès <rgomes@octobus.net>
date Thu, 08 Jul 2021 15:55:15 +0200
parents 53a864a60281
children d6ee6456bd5f
comparison
equal deleted inserted replaced
47559:53a864a60281 47560:af633293a5bd
336 336
337 337
338 if not _nativeenviron: 338 if not _nativeenviron:
339 # now encoding and helper functions are available, recreate the environ 339 # now encoding and helper functions are available, recreate the environ
340 # dict to be exported to other modules 340 # dict to be exported to other modules
341 environ = { 341 if pycompat.iswindows and pycompat.ispy3:
342 tolocal(k.encode('utf-8')): tolocal(v.encode('utf-8')) 342
343 for k, v in os.environ.items() # re-exports 343 class WindowsEnviron(dict):
344 } 344 """`os.environ` normalizes environment variables to uppercase on windows"""
345
346 def get(self, key, default=None):
347 return super().get(upper(key), default)
348
349 environ = WindowsEnviron()
350
351 for k, v in os.environ.items(): # re-exports
352 environ[tolocal(k.encode('utf-8'))] = tolocal(v.encode('utf-8'))
353
345 354
346 if pycompat.ispy3: 355 if pycompat.ispy3:
347 # os.getcwd() on Python 3 returns string, but it has os.getcwdb() which 356 # os.getcwd() on Python 3 returns string, but it has os.getcwdb() which
348 # returns bytes. 357 # returns bytes.
349 if pycompat.iswindows: 358 if pycompat.iswindows: