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/portage/update.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/portage/update.py')
-rw-r--r-- | pym/portage/update.py | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/pym/portage/update.py b/pym/portage/update.py index 4e5e78e5b..52ab50645 100644 --- a/pym/portage/update.py +++ b/pym/portage/update.py @@ -1,8 +1,8 @@ # Copyright 1999-2011 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 -import codecs import errno +import io import re import stat import sys @@ -13,9 +13,9 @@ from portage import _unicode_decode from portage import _unicode_encode import portage portage.proxy.lazyimport.lazyimport(globals(), - 'portage.dep:Atom,dep_getkey,get_operator,isjustname,isvalidatom,' + \ + 'portage.dep:Atom,dep_getkey,isvalidatom,' + \ 'remove_slot', - 'portage.util:ConfigProtect,grabfile,new_protect_filename,' + \ + 'portage.util:ConfigProtect,new_protect_filename,' + \ 'normalize_path,write_atomic,writemsg', 'portage.util.listdir:_ignorecvs_dirs', 'portage.versions:ververify' @@ -86,7 +86,7 @@ def fixdbentries(update_iter, dbdir): mydata = {} for myfile in [f for f in os.listdir(dbdir) if f not in ignored_dbentries]: file_path = os.path.join(dbdir, myfile) - mydata[myfile] = codecs.open(_unicode_encode(file_path, + mydata[myfile] = io.open(_unicode_encode(file_path, encoding=_encodings['fs'], errors='strict'), mode='r', encoding=_encodings['repo.content'], errors='replace').read() @@ -132,7 +132,7 @@ def grab_updates(updpath, prev_mtimes=None): if update_data or \ file_path not in prev_mtimes or \ long(prev_mtimes[file_path]) != mystat[stat.ST_MTIME]: - content = codecs.open(_unicode_encode(file_path, + content = io.open(_unicode_encode(file_path, encoding=_encodings['fs'], errors='strict'), mode='r', encoding=_encodings['repo.content'], errors='replace' ).read() @@ -253,7 +253,7 @@ def update_config_files(config_root, protect, protect_mask, update_iter, match_c myxfiles = recursivefiles for x in myxfiles: try: - file_contents[x] = codecs.open( + file_contents[x] = io.open( _unicode_encode(os.path.join(abs_user_config, x), encoding=_encodings['fs'], errors='strict'), mode='r', encoding=_encodings['content'], |