diff options
author | Petri Lehtinen <petri@digip.org> | 2011-11-04 19:35:07 (GMT) |
---|---|---|
committer | Petri Lehtinen <petri@digip.org> | 2011-11-04 20:21:07 (GMT) |
commit | 3c85fe07f40a18d9f5733e85b213a6992c5b2ed4 (patch) | |
tree | c142b9710010953017c497ee9f88e463ccbe54d3 /Lib/locale.py | |
parent | 12b66b5217d7cbccbeb918683f6df8ab9ae84c3d (diff) | |
download | cpython-3c85fe07f40a18d9f5733e85b213a6992c5b2ed4.zip cpython-3c85fe07f40a18d9f5733e85b213a6992c5b2ed4.tar.gz cpython-3c85fe07f40a18d9f5733e85b213a6992c5b2ed4.tar.bz2 |
Issue #3067: Fix the error raised by locale.setlocale()
Diffstat (limited to 'Lib/locale.py')
-rw-r--r-- | Lib/locale.py | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/Lib/locale.py b/Lib/locale.py index 3dc4caf..58cf0a7 100644 --- a/Lib/locale.py +++ b/Lib/locale.py @@ -440,13 +440,17 @@ def _build_localename(localetuple): No aliasing or normalizing takes place. """ - language, encoding = localetuple - if language is None: - language = 'C' - if encoding is None: - return language - else: - return language + '.' + encoding + try: + language, encoding = localetuple + + if language is None: + language = 'C' + if encoding is None: + return language + else: + return language + '.' + encoding + except (TypeError, ValueError): + raise TypeError('Locale must be None, a string, or an iterable of two strings -- language code, encoding.') def getdefaultlocale(envvars=('LC_ALL', 'LC_CTYPE', 'LANG', 'LANGUAGE')): |