Author: Armin Rigo <ar...@tunes.org> Branch: Changeset: r44290:66bb978bc47f Date: 2011-05-18 18:40 +0200 http://bitbucket.org/pypy/pypy/changeset/66bb978bc47f/
Log: Fixes: - actually *restore* the saved original locale setting! - catch and ignore rlocale.LocaleError instead of crashing RPython diff --git a/pypy/module/sys/interp_encoding.py b/pypy/module/sys/interp_encoding.py --- a/pypy/module/sys/interp_encoding.py +++ b/pypy/module/sys/interp_encoding.py @@ -43,16 +43,21 @@ # encoding = base_encoding if rlocale.HAVE_LANGINFO and rlocale.CODESET: - oldlocale = rlocale.setlocale(rlocale.LC_CTYPE, None) - rlocale.setlocale(rlocale.LC_CTYPE, "") - loc_codeset = rlocale.nl_langinfo(rlocale.CODESET) - if loc_codeset: - codecmod = space.getbuiltinmodule('_codecs') - w_res = space.call_function(space.getattr(codecmod, - space.wrap('lookup')), - space.wrap(loc_codeset)) - if space.is_true(w_res): - encoding = loc_codeset + try: + oldlocale = rlocale.setlocale(rlocale.LC_CTYPE, None) + rlocale.setlocale(rlocale.LC_CTYPE, "") + try: + loc_codeset = rlocale.nl_langinfo(rlocale.CODESET) + if loc_codeset: + codecmod = space.getbuiltinmodule('_codecs') + w_res = space.call_method(codecmod, 'lookup', + space.wrap(loc_codeset)) + if space.is_true(w_res): + encoding = loc_codeset + finally: + rlocale.setlocale(rlocale.LC_CTYPE, oldlocale) + except rlocale.LocaleError: + pass return encoding def getfilesystemencoding(space): _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit