From 2f1893a96862f108d76aaeb8ab59429c5b60b997 Mon Sep 17 00:00:00 2001 From: FocusedWolf Date: Thu, 24 Mar 2016 04:52:45 -0400 Subject: [PATCH] Fix LC_MESSAGES AttributeError Adds code to check if locale has the 'LC_MESSAGES' attribute before executing the following line of code: locale.getlocale(locale.LC_MESSAGES)[1] Fixes #1555 --- powerline/lib/encoding.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/powerline/lib/encoding.py b/powerline/lib/encoding.py index 798fc396..76a51d81 100644 --- a/powerline/lib/encoding.py +++ b/powerline/lib/encoding.py @@ -43,9 +43,15 @@ def get_preferred_output_encoding(): Falls back to ASCII, so that output is most likely to be displayed correctly. ''' + if hasattr(locale, 'LC_MESSAGES'): + return ( + locale.getlocale(locale.LC_MESSAGES)[1] + or locale.getdefaultlocale()[1] + or 'ascii' + ) + return ( - locale.getlocale(locale.LC_MESSAGES)[1] - or locale.getdefaultlocale()[1] + locale.getdefaultlocale()[1] or 'ascii' ) @@ -57,9 +63,15 @@ def get_preferred_input_encoding(): Falls back to latin1 so that function is less likely to throw as decoded output is primary searched for ASCII values. ''' + if hasattr(locale, 'LC_MESSAGES'): + return ( + locale.getlocale(locale.LC_MESSAGES)[1] + or locale.getdefaultlocale()[1] + or 'latin1' + ) + return ( - locale.getlocale(locale.LC_MESSAGES)[1] - or locale.getdefaultlocale()[1] + locale.getdefaultlocale()[1] or 'latin1' )