summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJochen Sprickerhof <git@jochen.sprickerhof.de>2020-06-26 22:26:23 +0200
committerJochen Sprickerhof <git@jochen.sprickerhof.de>2020-06-26 22:42:29 +0200
commitfd010f8336407ad1a42522b424d2ea7b7800ebc4 (patch)
treed0932de396f1a428238c4037163168b1eadaea06
parent56194f9dd7f9288361c37bbc694f18762c5158d7 (diff)
downloadurwid-fd010f8336407ad1a42522b424d2ea7b7800ebc4.tar.gz
Ignore resetting to invalid locale (Closes: #377)
Resetting the locale was introduced in 5dcf236, before that an invalid locale was ignored. Restore the old behavior insofar that only valid locales are restored. This fixes the unit tests of scottkosty/vit with unset LANG.
-rw-r--r--urwid/util.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/urwid/util.py b/urwid/util.py
index 17c049d..acd62f6 100644
--- a/urwid/util.py
+++ b/urwid/util.py
@@ -55,7 +55,10 @@ def detect_encoding():
else:
raise
finally:
- locale.setlocale(locale.LC_ALL, initial)
+ try:
+ locale.setlocale(locale.LC_ALL, initial)
+ except locale.Error:
+ pass
if 'detected_encoding' not in locals():
detected_encoding = detect_encoding()