Merge pull request #1556 from FocusedWolf/1555-fix-attribute-error-lc_messages

Fix LC_MESSAGES AttributeError
This commit is contained in:
Nikolai Aleksandrovich Pavlov 2016-03-24 22:55:21 +03:00
commit 6ff06016da

View File

@ -43,12 +43,18 @@ def get_preferred_output_encoding():
Falls back to ASCII, so that output is most likely to be displayed Falls back to ASCII, so that output is most likely to be displayed
correctly. correctly.
''' '''
if hasattr(locale, 'LC_MESSAGES'):
return ( return (
locale.getlocale(locale.LC_MESSAGES)[1] locale.getlocale(locale.LC_MESSAGES)[1]
or locale.getdefaultlocale()[1] or locale.getdefaultlocale()[1]
or 'ascii' or 'ascii'
) )
return (
locale.getdefaultlocale()[1]
or 'ascii'
)
def get_preferred_input_encoding(): def get_preferred_input_encoding():
'''Get encoding that should be used for reading shell command output '''Get encoding that should be used for reading shell command output
@ -57,12 +63,18 @@ def get_preferred_input_encoding():
Falls back to latin1 so that function is less likely to throw as decoded Falls back to latin1 so that function is less likely to throw as decoded
output is primary searched for ASCII values. output is primary searched for ASCII values.
''' '''
if hasattr(locale, 'LC_MESSAGES'):
return ( return (
locale.getlocale(locale.LC_MESSAGES)[1] locale.getlocale(locale.LC_MESSAGES)[1]
or locale.getdefaultlocale()[1] or locale.getdefaultlocale()[1]
or 'latin1' or 'latin1'
) )
return (
locale.getdefaultlocale()[1]
or 'latin1'
)
def get_preferred_arguments_encoding(): def get_preferred_arguments_encoding():
'''Get encoding that should be used for command-line arguments '''Get encoding that should be used for command-line arguments