diff options
author | Zac Medico <zmedico@gentoo.org> | 2011-07-10 16:26:24 -0700 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2011-07-10 16:55:05 -0700 |
commit | 8cc8d12a674ab6271183e5c35202263a36497279 (patch) | |
tree | 22365e2c613d04151a2d2da5ff3e25e37f84c554 /pym/_emerge/EbuildFetcher.py | |
parent | 906b62b24d8a845356d59abc5acd39db2174ce0f (diff) | |
download | portage-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/_emerge/EbuildFetcher.py')
-rw-r--r-- | pym/_emerge/EbuildFetcher.py | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/pym/_emerge/EbuildFetcher.py b/pym/_emerge/EbuildFetcher.py index 215024165..51d2f5a10 100644 --- a/pym/_emerge/EbuildFetcher.py +++ b/pym/_emerge/EbuildFetcher.py @@ -1,10 +1,11 @@ -# Copyright 1999-2010 Gentoo Foundation +# Copyright 1999-2011 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 import traceback from _emerge.SpawnProcess import SpawnProcess import copy +import io import signal import sys import portage @@ -12,7 +13,6 @@ from portage import os from portage import _encodings from portage import _unicode_encode from portage import _unicode_decode -import codecs from portage.elog.messages import eerror from portage.package.ebuild.fetch import fetch from portage.util._pty import _create_pty_or_pipe @@ -160,12 +160,13 @@ class EbuildFetcher(SpawnProcess): # fetch code will be skipped, so we need to generate equivalent # output here. if self.logfile is not None: - f = codecs.open(_unicode_encode(self.logfile, + f = io.open(_unicode_encode(self.logfile, encoding=_encodings['fs'], errors='strict'), - mode='a', encoding=_encodings['content'], errors='replace') + mode='a', encoding=_encodings['content'], + errors='backslashreplace') for filename in uri_map: - f.write((' * %s size ;-) ...' % \ - filename).ljust(73) + '[ ok ]\n') + f.write(_unicode_decode((' * %s size ;-) ...' % \ + filename).ljust(73) + '[ ok ]\n')) f.close() return True |