From 8cc8d12a674ab6271183e5c35202263a36497279 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Sun, 10 Jul 2011 16:26:24 -0700 Subject: Migrate from codecs.open() to io.open(). The io.open() function is the same as the built-in open() function in python3, and its implementation is optimized in python-2.7 and later. In addition to the possible performance improvement, this also allows us to avoid any future compatibility issues with codecs.open() that may arise if it is delegated to the built-in open() function as discussed in PEP 400. The main caveat involved with io.open() is that TextIOWrapper.write() raises TypeError if given raw bytes, unlike the streams returned from codecs.open(). This is mainly an issue for python2 since literal strings are raw bytes. We handle this by wrapping TextIOWrapper.write() arguments with our _unicode_decode() function. Also, the atomic_ofstream class overrides the write() method in python2 so that it performs automatic coercion to unicode when necessary. --- pym/portage/news.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'pym/portage/news.py') diff --git a/pym/portage/news.py b/pym/portage/news.py index f500aa3b8..866e5b025 100644 --- a/pym/portage/news.py +++ b/pym/portage/news.py @@ -1,12 +1,12 @@ # portage: news management code -# Copyright 2006-2010 Gentoo Foundation +# Copyright 2006-2011 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 __all__ = ["NewsManager", "NewsItem", "DisplayRestriction", "DisplayProfileRestriction", "DisplayKeywordRestriction", "DisplayInstalledRestriction"] -import codecs +import io import logging import os as _os import re @@ -250,7 +250,7 @@ class NewsItem(object): return self._valid def parse(self): - lines = codecs.open(_unicode_encode(self.path, + lines = io.open(_unicode_encode(self.path, encoding=_encodings['fs'], errors='strict'), mode='r', encoding=_encodings['content'], errors='replace' ).readlines() -- cgit v1.2.3-1-g7c22