summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2009-08-17 23:17:30 +0000
committerZac Medico <zmedico@gentoo.org>2009-08-17 23:17:30 +0000
commitb0d24f3025e239b8f9826c9fda0e4d0f7163387d (patch)
treec44023c21f4500b61f89404dc9eb923cdddc3457
parentd92e72f25bd2a3fbf60724439d34d1c91fcc6c7d (diff)
downloadportage-b0d24f3025e239b8f9826c9fda0e4d0f7163387d.tar.gz
portage-b0d24f3025e239b8f9826c9fda0e4d0f7163387d.tar.bz2
portage-b0d24f3025e239b8f9826c9fda0e4d0f7163387d.zip
Use portage.os, _content_encoding, and _fs_encoding where appropriate.
svn path=/main/trunk/; revision=14080
-rw-r--r--pym/portage/locks.py5
-rw-r--r--pym/portage/news.py28
2 files changed, 26 insertions, 7 deletions
diff --git a/pym/portage/locks.py b/pym/portage/locks.py
index c41b4aae7..adf82af81 100644
--- a/pym/portage/locks.py
+++ b/pym/portage/locks.py
@@ -7,7 +7,10 @@ __all__ = ["lockdir", "unlockdir", "lockfile", "unlockfile", \
"hardlock_name", "hardlink_is_mine", "hardlink_lockfile", \
"unhardlink_lockfile", "hardlock_cleanup"]
-import errno, os, stat, time
+import errno
+import stat
+import time
+from portage import os
from portage.exception import DirectoryNotFound, FileNotFound, \
InvalidData, TryAgain, OperationNotPermitted, PermissionDenied
from portage.data import portage_gid
diff --git a/pym/portage/news.py b/pym/portage/news.py
index 36d4603f7..9251f030e 100644
--- a/pym/portage/news.py
+++ b/pym/portage/news.py
@@ -9,8 +9,13 @@ __all__ = ["NewsManager", "NewsItem", "DisplayRestriction",
import codecs
import logging
-import os
+import os as _os
import re
+from portage import os
+from portage import _content_encoding
+from portage import _fs_encoding
+from portage import _unicode_decode
+from portage import _unicode_encode
from portage.util import apply_secpass_permissions, ensure_dirs, \
grabfile, normalize_path, write_atomic, writemsg_level
from portage.data import portage_gid
@@ -94,7 +99,8 @@ class NewsManager(object):
news_dir = self._news_dir(repoid)
try:
- news = os.listdir(news_dir)
+ news = _os.listdir(_unicode_encode(news_dir,
+ encoding=_fs_encoding, errors='strict'))
except OSError:
return
@@ -112,14 +118,23 @@ class NewsManager(object):
updates = []
for itemid in news:
+ try:
+ itemid = _unicode_decode(itemid,
+ encoding=_fs_encoding, errors='strict')
+ except UnicodeDecodeError:
+ itemid = _unicode_decode(itemid,
+ encoding=_fs_encoding, errors='replace')
+ writemsg_level(
+ "!!! Invalid encoding in news item name: '%s'\n" % \
+ itemid, level=logging.ERROR, noiselevel=-1)
+ continue
+
if itemid in skip:
continue
filename = os.path.join(news_dir, itemid,
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
@@ -228,8 +243,9 @@ class NewsItem(object):
return self._valid
def parse(self):
- lines = codecs.open(self.path, mode='r',
- encoding='utf_8', errors='replace').readlines()
+ lines = codecs.open(_unicode_encode(self.path,
+ encoding=_fs_encoding, errors='strict'),
+ mode='r', encoding=_content_encoding, errors='replace').readlines()
self.restrictions = []
invalids = []
for i, line in enumerate(lines):