summaryrefslogtreecommitdiffstats
path: root/pym/portage/elog/messages.py
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2011-07-10 16:26:24 -0700
committerZac Medico <zmedico@gentoo.org>2011-07-10 16:55:05 -0700
commit8cc8d12a674ab6271183e5c35202263a36497279 (patch)
tree22365e2c613d04151a2d2da5ff3e25e37f84c554 /pym/portage/elog/messages.py
parent906b62b24d8a845356d59abc5acd39db2174ce0f (diff)
downloadportage-8cc8d12a674ab6271183e5c35202263a36497279.tar.gz
portage-8cc8d12a674ab6271183e5c35202263a36497279.tar.bz2
portage-8cc8d12a674ab6271183e5c35202263a36497279.zip
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.
Diffstat (limited to 'pym/portage/elog/messages.py')
-rw-r--r--pym/portage/elog/messages.py7
1 files changed, 3 insertions, 4 deletions
diff --git a/pym/portage/elog/messages.py b/pym/portage/elog/messages.py
index a8a3e9a5f..6c1580a37 100644
--- a/pym/portage/elog/messages.py
+++ b/pym/portage/elog/messages.py
@@ -1,5 +1,5 @@
# elog/messages.py - elog core functions
-# Copyright 2006-2009 Gentoo Foundation
+# Copyright 2006-2011 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
import portage
@@ -15,7 +15,7 @@ from portage import _encodings
from portage import _unicode_encode
from portage import _unicode_decode
-import codecs
+import io
import sys
def collect_ebuild_messages(path):
@@ -43,7 +43,7 @@ def collect_ebuild_messages(path):
logentries[msgfunction] = []
lastmsgtype = None
msgcontent = []
- for l in codecs.open(_unicode_encode(filename,
+ for l in io.open(_unicode_encode(filename,
encoding=_encodings['fs'], errors='strict'),
mode='r', encoding=_encodings['repo.content'], errors='replace'):
if not l:
@@ -167,7 +167,6 @@ def _make_msgfunction(level, color):
_elog_base(level, msg, phase=phase, key=key, color=color, out=out)
return _elog
-import sys
for f in _functions:
setattr(sys.modules[__name__], f, _make_msgfunction(_functions[f][0], _functions[f][1]))
del f, _functions