diff options
author | Zac Medico <zmedico@gentoo.org> | 2009-08-10 08:15:05 +0000 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2009-08-10 08:15:05 +0000 |
commit | 8e625c41a5417f697d67d8fe1c70b6b05435ab42 (patch) | |
tree | 77d3e955c52fcfce3fd438699dd16c3926d289d0 | |
parent | ae551558b72bd77f27f0e2cf7d40e9c885a0a9b9 (diff) | |
download | portage-8e625c41a5417f697d67d8fe1c70b6b05435ab42.tar.gz portage-8e625c41a5417f697d67d8fe1c70b6b05435ab42.tar.bz2 portage-8e625c41a5417f697d67d8fe1c70b6b05435ab42.zip |
Open new items in text mode (unicode), and safely handle unicode in news itemv2.2_rc38
names.
svn path=/main/trunk/; revision=13975
-rw-r--r-- | pym/portage/news.py | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/pym/portage/news.py b/pym/portage/news.py index 750df3dd6..c6bd9eafa 100644 --- a/pym/portage/news.py +++ b/pym/portage/news.py @@ -7,6 +7,7 @@ __all__ = ["NewsManager", "NewsItem", "DisplayRestriction", "DisplayProfileRestriction", "DisplayKeywordRestriction", "DisplayInstalledRestriction"] +import codecs import logging import os import re @@ -116,6 +117,8 @@ class NewsManager(object): itemid + "." + self.language_id + ".txt") if not os.path.isfile(filename): continue + if not isinstance(itemid, unicode): + itemid = unicode(itemid, encoding='utf_8', errors='replace') item = NewsItem(filename, itemid) if not item.isValid(): continue @@ -224,7 +227,8 @@ class NewsItem(object): return self._valid def parse(self): - lines = open(self.path).readlines() + lines = codecs.open(self.path, mode='r', + encoding='utf_8', errors='replace').readlines() self.restrictions = [] invalids = [] for i, line in enumerate(lines): |