comparison mercurial/encoding.py @ 39844:9e8fcd2e78c1

encoding: remove unnecessary lambdas from _encodingfixers They have been unnecessary since 1a3a08b5d4d5 (encoding: remove workaround for locale.getpreferredencoding(), 2017-05-13). Also rename the variable since "fixer" sounds like a function. Differential Revision: https://phab.mercurial-scm.org/D4743
author Martin von Zweigbergk <martinvonz@google.com>
date Tue, 25 Sep 2018 08:53:20 -0700
parents fb628c048d64
children 25694a78e4a4
comparison
equal deleted inserted replaced
39843:bce1c1af7518 39844:9e8fcd2e78c1
66 # preferred encoding isn't known yet; use utf-8 to avoid unicode error 66 # preferred encoding isn't known yet; use utf-8 to avoid unicode error
67 # and recreate it once encoding is settled 67 # and recreate it once encoding is settled
68 environ = dict((k.encode(u'utf-8'), v.encode(u'utf-8')) 68 environ = dict((k.encode(u'utf-8'), v.encode(u'utf-8'))
69 for k, v in os.environ.items()) # re-exports 69 for k, v in os.environ.items()) # re-exports
70 70
71 _encodingfixers = { 71 _encodingrewrites = {
72 '646': lambda: 'ascii', 72 '646': 'ascii',
73 'ANSI_X3.4-1968': lambda: 'ascii', 73 'ANSI_X3.4-1968': 'ascii',
74 } 74 }
75 # cp65001 is a Windows variant of utf-8, which isn't supported on Python 2. 75 # cp65001 is a Windows variant of utf-8, which isn't supported on Python 2.
76 # No idea if it should be rewritten to the canonical name 'utf-8' on Python 3. 76 # No idea if it should be rewritten to the canonical name 'utf-8' on Python 3.
77 # https://bugs.python.org/issue13216 77 # https://bugs.python.org/issue13216
78 if pycompat.iswindows and not pycompat.ispy3: 78 if pycompat.iswindows and not pycompat.ispy3:
79 _encodingfixers['cp65001'] = lambda: 'utf-8' 79 _encodingrewrites['cp65001'] = 'utf-8'
80 80
81 try: 81 try:
82 encoding = environ.get("HGENCODING") 82 encoding = environ.get("HGENCODING")
83 if not encoding: 83 if not encoding:
84 encoding = locale.getpreferredencoding().encode('ascii') or 'ascii' 84 encoding = locale.getpreferredencoding().encode('ascii') or 'ascii'
85 encoding = _encodingfixers.get(encoding, lambda: encoding)() 85 encoding = _encodingrewrites.get(encoding, encoding)
86 except locale.Error: 86 except locale.Error:
87 encoding = 'ascii' 87 encoding = 'ascii'
88 encodingmode = environ.get("HGENCODINGMODE", "strict") 88 encodingmode = environ.get("HGENCODINGMODE", "strict")
89 fallbackencoding = 'ISO-8859-1' 89 fallbackencoding = 'ISO-8859-1'
90 90