From: Zac Medico Date: Mon, 10 Aug 2009 08:15:05 +0000 (-0000) Subject: Open new items in text mode (unicode), and safely handle unicode in news item X-Git-Tag: v2.2_rc38 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=8e625c41a5417f697d67d8fe1c70b6b05435ab42;p=portage.git Open new items in text mode (unicode), and safely handle unicode in news item names. svn path=/main/trunk/; revision=13975 --- 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):