mercurial/encoding.py
changeset 39839 9e8fcd2e78c1
parent 39819 fb628c048d64
child 41836 25694a78e4a4
equal deleted inserted replaced
39838:bce1c1af7518 39839: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