summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2009-08-14 05:45:08 +0000
committerZac Medico <zmedico@gentoo.org>2009-08-14 05:45:08 +0000
commitbdb5e16a137ee9f228d7028a2ea7f97b8f7acb09 (patch)
treed42d460fa023746a397361353af8fe6a4eca9a51
parenta5832535ef4e08143bfe93399f68fd22ba24f183 (diff)
downloadportage-bdb5e16a137ee9f228d7028a2ea7f97b8f7acb09.tar.gz
portage-bdb5e16a137ee9f228d7028a2ea7f97b8f7acb09.tar.bz2
portage-bdb5e16a137ee9f228d7028a2ea7f97b8f7acb09.zip
Make _ensure_default_encoding() provide a fallback for the codec returned
by sys.getfilesystemencoding(). svn path=/main/trunk/; revision=14021
-rw-r--r--pym/portage/__init__.py17
1 files changed, 15 insertions, 2 deletions
diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py
index 4f2bb4204..94e38e4fb 100644
--- a/pym/portage/__init__.py
+++ b/pym/portage/__init__.py
@@ -313,8 +313,10 @@ def _ensure_default_encoding():
default_fallback = 'utf_8'
default_encoding = sys.getdefaultencoding().lower().replace('-', '_')
+ filesystem_encoding = sys.getfilesystemencoding().lower().replace('-', '_')
required_encodings = set(['ascii', 'utf_8'])
required_encodings.add(default_encoding)
+ required_encodings.add(filesystem_encoding)
missing_encodings = set()
for codec_name in required_encodings:
try:
@@ -330,13 +332,23 @@ def _ensure_default_encoding():
if default_encoding in missing_encodings and \
default_encoding not in encodings:
# Make the fallback codec correspond to whatever name happens
- # to be returned by sys.getdefaultencoding().
+ # to be returned by sys.getfilesystemencoding().
try:
encodings[default_encoding] = codecs.lookup(default_fallback)
except LookupError:
encodings[default_encoding] = encodings[default_fallback]
+ if filesystem_encoding in missing_encodings and \
+ filesystem_encoding not in encodings:
+ # Make the fallback codec correspond to whatever name happens
+ # to be returned by sys.getdefaultencoding().
+
+ try:
+ encodings[filesystem_encoding] = codecs.lookup(default_fallback)
+ except LookupError:
+ encodings[filesystem_encoding] = encodings[default_fallback]
+
def search_function(name):
name = name.lower()
name = name.replace('-', '_')
@@ -355,7 +367,8 @@ def _ensure_default_encoding():
codecs.register(search_function)
- del codec_name, default_encoding, default_fallback, missing_encodings, \
+ del codec_name, default_encoding, default_fallback, \
+ filesystem_encoding, missing_encodings, \
required_encodings, search_function
# Do this ASAP since writemsg() might not work without it.